-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support eslint@9 and add nuxt/nestjs configs
BREAKING CHANGE: drop support eslint < 9
- Loading branch information
1 parent
e35ebdd
commit 76bce2f
Showing
28 changed files
with
811 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,67 @@ | ||
# @buka/eslint-config | ||
|
||
| config | Description | | ||
| :--------------------------------------------- | :---------- | | ||
| @buka/eslint-config/autofix | | ||
| @buka/eslint-cofnig/recommended | | ||
| @buka/eslint-config/typescript/autofix | | ||
| @buka/eslint-config/typescript/recommended | | ||
| @buka/eslint-config/typescript/esm-recommended | | ||
|
||
## Usage | ||
|
||
```bash | ||
npm install @buka/eslint-config | ||
[Buka]: https://github.com/buka-lnc | ||
|
||
[Buka][Buka] 基准 Eslint 规则,需要`eslint > 9`。 | ||
|
||
`@buka/eslint-config` 提供四种适用于不同场景的 eslint 规则: | ||
|
||
- 适用于 `.js` 文件的通用的 eslint 规则。 | ||
- 适用于 `.ts` 文件的通用的 eslint 规则。 | ||
- 适用于 [nuxt](https://nuxt.com/) 的 eslint 规则。 | ||
- 适用于 [nestjs](https://nestjs.com/) 的 eslint 规则。 | ||
|
||
> 部分场景除`recommended`之外,还提供了其他选项。 | ||
> 但并不建议使用其他选项,除非你清楚的知道自己想要做什么。 | ||
## js | ||
|
||
```javascript | ||
// eslint.config.mjs | ||
import buka from "@buka/eslint-config"; | ||
|
||
export default [...buka.js.recommend]; | ||
``` | ||
|
||
| config | Description | | ||
| :-------------------- | :-------------------------------------------------------------------------------------------- | | ||
| `buka.js.autofix` | 仅包含 eslint 支持 autofix 的规则 | | ||
| `buka.js.recommended` | 包含 @eslint/js 的 recommended 规则 和 buka.js.autofix 规则。并增加 [Buka][Buka] 推荐的规则。 | | ||
|
||
## typescript | ||
|
||
```javascript | ||
// eslint.config.mjs | ||
import buka from "@buka/eslint-config"; | ||
|
||
export default [...buka.typescript.recommend]; | ||
``` | ||
|
||
Add to eslint config: | ||
|
||
```json | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint/eslint-plugin"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"@buka/eslint-config/typescript/recommended" | ||
] | ||
} | ||
| config | Description | | ||
| :---------------------------- | :------------------------------------------------------------------------------------------------------------ | | ||
| `buka.typescript.autofix` | 仅包含 eslint 和 @typescript-eslint 支持 autofix 的规则 | | ||
| `buka.typescript.recommended` | 包含 @typescript-eslint 的 recommended 规则 和 buka.typescript.autofix 规则。并增加 [Buka][Buka] 推荐的规则。 | | ||
|
||
## nuxt | ||
|
||
此规则需要配合[`nuxt@3`](https://nuxt.com/) 和 `@nuxt/eslint` 使用。 | ||
|
||
```javascript | ||
// eslint.config.mjs | ||
import buka from "@buka/eslint-config"; | ||
import withNuxt from "./.nuxt/eslint.config.mjs"; | ||
|
||
export default withNuxt(...buka.nuxt.recommended); | ||
``` | ||
|
||
| config | Description | | ||
| :---------------------- | :----------------------------- | | ||
| `buka.nuxt.recommended` | 增加 [Buka][Buka] 推荐的规则。 | | ||
|
||
## nestjs | ||
|
||
此规则需要配合 [Nestjs](https://nestjs.com/) 使用。 | ||
|
||
| config | Description | | ||
| :------------------------ | :------------------------------------------------------------------ | | ||
| `buka.nestjs.recommended` | 在 `buka.typescript.recommended` 规则上,增加了 NestJS 需要的配置。 | |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import nuxt from './nuxt'; | ||
import js from './js' | ||
import typescript from './typescript' | ||
import nestjs from './nestjs' | ||
|
||
export { nuxt, js, typescript, nestjs } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports.js = require('./js') | ||
module.exports.typescript = require('./typescript') | ||
module.exports.nuxt = require('./nuxt') | ||
module.exports.nestjs = require('./nestjs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ResolvableFlatConfig } from 'eslint-flat-config-utils' | ||
declare const _default: ResolvableFlatConfig[] | ||
export default _default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const stylistic = require('@stylistic/eslint-plugin') | ||
|
||
|
||
module.exports = [ | ||
{ | ||
files: ['**/*.js'], | ||
|
||
plugins: { | ||
'@stylistic': stylistic | ||
}, | ||
|
||
rules: { | ||
"no-div-regex": "error", | ||
"no-else-return": "error", | ||
"no-implicit-coercion": ["error", { "boolean": false }], | ||
"no-lonely-if": "error", | ||
"no-unneeded-ternary": "error", | ||
"no-useless-computed-key": "error", | ||
"no-var": "error", | ||
"no-unused-vars": "error", | ||
"prefer-const": "error", | ||
"prefer-template": "error", | ||
"prefer-object-spread": "error", | ||
"curly": ["error", "multi-line", "consistent"], | ||
"yoda": ["error", "never"], | ||
|
||
|
||
"@stylistic/no-confusing-arrow": "error", | ||
"@stylistic/no-floating-decimal": "error", | ||
"@stylistic/no-multiple-empty-lines": [ | ||
"error", | ||
{ | ||
"max": 2 | ||
} | ||
], | ||
"@stylistic/no-multi-spaces": "error", | ||
"@stylistic/no-tabs": "error", | ||
"@stylistic/no-trailing-spaces": "error", | ||
"@stylistic/no-whitespace-before-property": "error", | ||
"@stylistic/nonblock-statement-body-position": "error", | ||
|
||
"@stylistic/line-comment-position": ["error", "above"], | ||
// 会导致vscode的vim插件的gcc指令无法解除注释 | ||
// "multiline-comment-style": ["error", "starred-block"], | ||
// typescript 的特殊注释需要三个反斜杠 | ||
"@stylistic/spaced-comment": ["error", "always", { "markers": ['/'] }], | ||
|
||
"@stylistic/array-bracket-spacing": ["error", "never"], | ||
"@stylistic/array-element-newline": ["error", "consistent"], | ||
|
||
"@stylistic/arrow-parens": ["error", "always"], | ||
"@stylistic/arrow-spacing": ["error", { "before": true, "after": true }], | ||
"arrow-body-style": ["error", "as-needed"], | ||
|
||
"@stylistic/comma-dangle": ["error", "always-multiline"], | ||
"@stylistic/comma-spacing": ["error", { "before": false, "after": true }], | ||
"@stylistic/comma-style": ["error", "last"], | ||
|
||
"@stylistic/func-call-spacing": ["error", "never"], | ||
"@stylistic/function-call-argument-newline": ["error", "consistent"], | ||
|
||
"@stylistic/key-spacing": [ | ||
"error", | ||
{ | ||
"afterColon": true, | ||
"beforeColon": false, | ||
"mode": "strict" | ||
} | ||
], | ||
"@stylistic/keyword-spacing": [ | ||
"error", | ||
{ | ||
"before": true, | ||
"after": true | ||
} | ||
], | ||
|
||
"@stylistic/object-curly-spacing": ["error", "always"], | ||
"@stylistic/object-curly-newline": [ | ||
"error", | ||
{ | ||
"multiline": true, | ||
"consistent": true | ||
} | ||
], | ||
|
||
"@stylistic/space-before-blocks": ["error", "always"], | ||
"@stylistic/space-before-function-paren": [ | ||
"error", | ||
{ | ||
"anonymous": "always", | ||
"named": "never", | ||
"asyncArrow": "always" | ||
} | ||
], | ||
|
||
"@stylistic/space-in-parens": ["error", "never"], | ||
"@stylistic/space-infix-ops": "error", | ||
"@stylistic/space-unary-ops": "error", | ||
|
||
"@stylistic/switch-colon-spacing": ["error", { "after": true, "before": false }], | ||
"@stylistic/rest-spread-spacing": ["error", "never"], | ||
"@stylistic/template-curly-spacing": ["error", "never"], | ||
"@stylistic/computed-property-spacing": ["error", "never"], | ||
"@stylistic/block-spacing": ["error", "always"], | ||
"@stylistic/implicit-arrow-linebreak": "error", | ||
|
||
"@stylistic/indent": [ | ||
"error", | ||
2, | ||
{ | ||
"MemberExpression": 1, | ||
"ignoredNodes": [ | ||
"FunctionExpression > .params[decorators.length > 0]", | ||
"FunctionExpression > .params > :matches(Decorator, :not(:first-child))", | ||
"ClassBody.body > PropertyDefinition[decorators.length > 0] > .key" | ||
] | ||
} | ||
], | ||
"@stylistic/one-var-declaration-per-line": ["error", "initializations"], | ||
"@stylistic/padded-blocks": ["error", "never"], | ||
"@stylistic/jsx-quotes": ["error", "prefer-double"], | ||
"@stylistic/new-parens": "error", | ||
"@stylistic/brace-style": ["error", "1tbs"], | ||
"@stylistic/eol-last": ["error", "always"], | ||
"@stylistic/quote-props": ["error", "as-needed"], | ||
"@stylistic/semi": ["error", "never"], | ||
"@stylistic/quotes": ["error", "single", { "avoidEscape": true }], | ||
"@stylistic/linebreak-style": ["error", "unix"], | ||
"@stylistic/lines-between-class-members": [ | ||
"error", | ||
"always", | ||
{ | ||
"exceptAfterSingleLine": true | ||
} | ||
], | ||
"@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 2 }] | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import autofix from './autofix'; | ||
import recommended from './recommended'; | ||
|
||
export { autofix, recommended }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const autofix = require('./autofix') | ||
const recommended = require('./recommended') | ||
|
||
|
||
module.exports.autofix = autofix | ||
module.exports.recommended = recommended |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ResolvableFlatConfig } from 'eslint-flat-config-utils' | ||
declare const _default: ResolvableFlatConfig[] | ||
export default _default |
Oops, something went wrong.