# oasis-lint **Repository Path**: worldzb/oasis-lint ## Basic Information - **Project Name**: oasis-lint - **Description**: 前端lint 开发预设,包含 eslint, stylelint,commitlit,prettier 等 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-09-04 - **Last Updated**: 2025-11-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @worldzb/lint-config > oasis lint 配置预设 #### tips 1. `eslint 8 及一下 版本对应 v0.2` [老版本文档](./README-old.md) 2. `eslint 9 及以上版本对应 v1.0 以上版本` ## 使用 ### 安装 ```bash pnpm i eslint pnpm add -D eslint @worldzb/eslint-config-basic ``` ### 单独使用 ```bash pnpm i -D @worldzb/eslint-config-basic # JavaScript only pnpm i -D @worldzb/eslint-config-ts # JavaScript and TypeScript and Nestjs pnpm i -D @worldzb/eslint-config-vue # JavaScript, TypeScript and Vue pnpm i -D @worldzb/eslint-config-react # JavaScript, TypeScript and React ``` ### 配置 `eslint.config.js` `注意!eslint 9 不再支持 .eslintrc.js 以及 package.json 配置 eslint` ` ```js import vueLint from '@worldzb/eslint-config-vue' export default [ ...vueLint, { ignores: ['src/router/elegant/**.*'], }, ] ``` > 不需要配置.eslintignore 文件,因为已经在预设中配置好了 ### 在 package.json 添加脚本 示例: ```json { "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix" } } ``` ## stylelint 使用 ### 安装 ```bash pnpm i -D @worldzb/stylelint-config-scss ``` ### 配置 stylelint ```js module.exports = { defaultSeverity: 'error', extends: '@worldzb/stylelint-config-scss', } ``` ## commitlint 使用 ### 安装 ```bash pnpm i -D @worldzb/commitlint-config ``` 创建好 husky git 钩子,以及 lint staged 之后,添加如下配置 ### 配置 stylelint ```js module.exports = { extends: ['@worldzb/commitlint-config'], } ``` ## prettier 使用 ```bash pnpm i -D @worldzb/prettier-config ``` ### 配置 prettierrc.cjs ```js const config = require('@worldzb/prettier-config') module.exports = config ``` ## 配置 VS Code 自动修复 Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and create `.vscode/settings.json` ```json { "prettier.enable": false, "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": true } } ``` ## Lint Staged If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`: ```json { "simple-git-hooks": { "pre-commit": "pnpm lint-staged" }, "lint-staged": { "*": "eslint --fix" } } ``` and then ```bash npm i -D lint-staged simple-git-hooks ``` ## 常用配置 1.npmrc ```ini registry=https://registry.npmmirror.com/ auto-install-peers=true @worldzb:registry=https://registry.npmjs.org/ ``` 2.package.json ```json { "scripts": { "lint": "eslint --ext .ts,.js,.vue src --fix && stylelint \"src/**/*.(vue|scss|css|less)\" --fix" }, "lint-staged": { "*.vue": ["prettier --write", "stylelint --fix", "eslint --fix"], "*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix"], "*.{less,scss,css}": ["prettier --write", "stylelint --fix"] } } ```