@fast-china/eslint-config 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +66 -142
- package/README.zh.md +64 -142
- package/dist/configs/environment.mjs +2 -0
- package/dist/configs/environment.mjs.map +1 -1
- package/dist/configs/ignores.mjs +0 -1
- package/dist/configs/ignores.mjs.map +1 -1
- package/dist/configs/import.mjs +4 -1
- package/dist/configs/import.mjs.map +1 -1
- package/dist/configs/index.d.mts +2 -2
- package/dist/configs/index.mjs +2 -2
- package/dist/configs/javascript.mjs +3 -1
- package/dist/configs/javascript.mjs.map +1 -1
- package/dist/configs/json.mjs +3 -1
- package/dist/configs/json.mjs.map +1 -1
- package/dist/configs/markdown.d.mts +2 -1
- package/dist/configs/markdown.mjs +4 -2
- package/dist/configs/markdown.mjs.map +1 -1
- package/dist/configs/prettier.mjs +1 -1
- package/dist/configs/prettier.mjs.map +1 -1
- package/dist/configs/sort-package.d.mts +1 -1
- package/dist/configs/sort-package.mjs +1 -1
- package/dist/configs/sort-package.mjs.map +1 -1
- package/dist/configs/sort-tsconfig.d.mts +2 -2
- package/dist/configs/sort-tsconfig.mjs +2 -2
- package/dist/configs/sort-tsconfig.mjs.map +1 -1
- package/dist/configs/typescript.d.mts +11 -7
- package/dist/configs/typescript.mjs +25 -22
- package/dist/configs/typescript.mjs.map +1 -1
- package/dist/configs/uniapp.mjs +19 -13
- package/dist/configs/uniapp.mjs.map +1 -1
- package/dist/configs/vue.d.mts +18 -3
- package/dist/configs/vue.mjs +59 -9
- package/dist/configs/vue.mjs.map +1 -1
- package/dist/constants/index.d.mts +4 -0
- package/dist/constants/index.mjs +5 -1
- package/dist/constants/index.mjs.map +1 -1
- package/dist/index.d.mts +37 -58
- package/dist/index.mjs +43 -47
- package/dist/index.mjs.map +1 -1
- package/dist/rules/angular.d.mts +28 -0
- package/dist/rules/angular.mjs +28 -0
- package/dist/rules/angular.mjs.map +1 -1
- package/dist/rules/common.d.mts +16 -6
- package/dist/rules/common.mjs +16 -13
- package/dist/rules/common.mjs.map +1 -1
- package/dist/rules/import.d.mts +9 -0
- package/dist/rules/import.mjs +24 -0
- package/dist/rules/import.mjs.map +1 -1
- package/dist/rules/index.d.mts +2 -2
- package/dist/rules/index.mjs +2 -2
- package/dist/rules/javascript.d.mts +18 -0
- package/dist/rules/javascript.mjs +18 -0
- package/dist/rules/javascript.mjs.map +1 -1
- package/dist/rules/lodash.d.mts +2 -0
- package/dist/rules/lodash.mjs +6 -2
- package/dist/rules/lodash.mjs.map +1 -1
- package/dist/rules/react.d.mts +13 -0
- package/dist/rules/react.mjs +13 -0
- package/dist/rules/react.mjs.map +1 -1
- package/dist/rules/regexp.d.mts +25 -0
- package/dist/rules/regexp.mjs +25 -0
- package/dist/rules/regexp.mjs.map +1 -1
- package/dist/rules/sort-package.d.mts +3 -1
- package/dist/rules/sort-package.mjs +3 -1
- package/dist/rules/sort-package.mjs.map +1 -1
- package/dist/rules/sort-tsconfig.d.mts +3 -1
- package/dist/rules/sort-tsconfig.mjs +3 -1
- package/dist/rules/sort-tsconfig.mjs.map +1 -1
- package/dist/rules/typescript.d.mts +81 -13
- package/dist/rules/typescript.mjs +83 -15
- package/dist/rules/typescript.mjs.map +1 -1
- package/dist/rules/vue.d.mts +65 -10
- package/dist/rules/vue.mjs +41 -14
- package/dist/rules/vue.mjs.map +1 -1
- package/docs/engineering-audit.zh.md +45 -49
- package/docs/rules/angular.zh.md +721 -0
- package/docs/rules/core.zh.md +3031 -0
- package/docs/rules/index.zh.md +38 -0
- package/docs/rules/json.zh.md +784 -0
- package/docs/rules/markdown.zh.md +449 -0
- package/docs/rules/react.zh.md +2091 -0
- package/docs/rules/typescript.zh.md +2051 -0
- package/docs/rules/vue.zh.md +3016 -0
- package/docs/rules-risk.md +85 -91
- package/docs/rules-risk.zh.md +76 -82
- package/package.json +4 -2
package/docs/rules-risk.md
CHANGED
|
@@ -1,119 +1,113 @@
|
|
|
1
1
|
# Default Rules and Risk Guide
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This guide describes the current configuration model, major rules, and auto-fix risks. Source comments explain current intent; historical differences belong in `CHANGELOG.md`.
|
|
4
|
+
|
|
5
|
+
## Policy
|
|
6
|
+
|
|
7
|
+
Rules are selected in this order:
|
|
8
|
+
|
|
9
|
+
1. Follow common JavaScript, TypeScript, and Vue conventions while keeping code concise and readable.
|
|
10
|
+
2. Detect real bugs and type-safety problems.
|
|
11
|
+
3. Preserve cross-project consistency.
|
|
12
|
+
4. Apply Fast project style preferences last.
|
|
13
|
+
|
|
14
|
+
Rules that only satisfy ESLint by changing valid semantics, adding boilerplate, or forcing uncommon forms do not belong in the defaults.
|
|
4
15
|
|
|
5
16
|
## Configuration model
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
Vue 3 and UniApp are separate named complete configurations from the root entry:
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
- `vueConfig` handles plain Vue projects only.
|
|
21
|
+
- `uniAppConfig` adds `.nvue`, UniApp globals, manifest behavior, and the `unpackage` ignore.
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
- `.gitignore`
|
|
13
|
-
- JavaScript and type-aware TypeScript
|
|
14
|
-
- Vue 3, `.nvue`, UniApp globals, and manifest handling
|
|
15
|
-
- Import, RegExp, JSON, JSONC, and JSON5
|
|
16
|
-
- `package.json` and `tsconfig*.json` sorting
|
|
17
|
-
- Prettier conflict handling
|
|
18
|
-
- Node.js tooling globals and trailing rule overrides
|
|
23
|
+
The root entry has no default export. It exposes `vueConfig`, `uniAppConfig`, `createVueProjectConfigs()`, `createUniAppProjectConfigs()`, `createBaseConfigs()`, `defineRules()`, and their types.
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
SDKs, Node.js, and other framework-neutral projects use `createBaseConfigs()`. React, Angular, Markdown, and Lodash compose explicitly from `./configs`; manifest sorting is part of every complete configuration.
|
|
21
26
|
|
|
22
27
|
## Preset sources
|
|
23
28
|
|
|
24
|
-
| Domain | Preset or implementation
|
|
25
|
-
| ---------- |
|
|
26
|
-
| JavaScript | `@eslint/js` recommended plus local rules
|
|
27
|
-
| TypeScript | typescript-eslint
|
|
28
|
-
| Vue | `eslint-plugin-vue` `flat/recommended` plus type-aware TypeScript
|
|
29
|
-
| React | `@eslint-react` recommended/type-checked plus React Hooks Flat Recommended
|
|
30
|
-
| Angular | Angular ESLint TypeScript, template, and accessibility recommended presets
|
|
31
|
-
| JSON | `eslint-plugin-jsonc` recommended presets for three dialects
|
|
32
|
-
| Import | `eslint-plugin-import-x` recommended plus a
|
|
33
|
-
| RegExp | Explicit correctness, safety, and super-linear backtracking rules
|
|
34
|
-
| Prettier | `eslint-config-prettier` conflict disabling
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- `camelcase: ["error", { properties: "never" }]`
|
|
41
|
-
- `no-empty`
|
|
42
|
-
- `no-
|
|
43
|
-
- `no-debugger
|
|
44
|
-
- `
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
47
|
-
- `
|
|
48
|
-
-
|
|
49
|
-
- `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
- `explicit-
|
|
58
|
-
- `no-
|
|
59
|
-
-
|
|
60
|
-
- `no-
|
|
61
|
-
- `
|
|
62
|
-
- `no-
|
|
63
|
-
- `
|
|
64
|
-
-
|
|
65
|
-
- `
|
|
66
|
-
- `no-
|
|
67
|
-
-
|
|
68
|
-
- `
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
- `
|
|
74
|
-
- `no-
|
|
75
|
-
- `no-v-text-v-html-on-component`
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
|
|
79
|
-
## Type-aware requirements
|
|
80
|
-
|
|
81
|
-
TypeScript, Vue, and React TSX always require type information. Linted files must belong to a discoverable `tsconfig.json`, or Project Service reports a configuration error.
|
|
82
|
-
|
|
83
|
-
The `typeChecked` and `tsconfigRootDir` wrapper options no longer exist. Complex monorepos can override `languageOptions.parserOptions` in trailing Flat Config, but should not disable type checking to hide project-boundary problems.
|
|
29
|
+
| Domain | Preset or implementation |
|
|
30
|
+
| ---------- | -------------------------------------------------------------------------- |
|
|
31
|
+
| JavaScript | `@eslint/js` recommended plus local high-confidence rules |
|
|
32
|
+
| TypeScript | typescript-eslint `recommendedTypeChecked` plus Project Service |
|
|
33
|
+
| Vue | `eslint-plugin-vue` `flat/recommended` plus type-aware TypeScript |
|
|
34
|
+
| React | `@eslint-react` recommended/type-checked plus React Hooks Flat Recommended |
|
|
35
|
+
| Angular | Angular ESLint TypeScript, template, and accessibility recommended presets |
|
|
36
|
+
| JSON | `eslint-plugin-jsonc` recommended presets for three dialects |
|
|
37
|
+
| Import | `eslint-plugin-import-x` recommended plus a general ordering warning |
|
|
38
|
+
| RegExp | Explicit correctness, safety, and super-linear backtracking rules |
|
|
39
|
+
| Prettier | `eslint-config-prettier` conflict disabling |
|
|
40
|
+
|
|
41
|
+
The complete `strictTypeChecked`, `stylisticTypeChecked`, and mechanical `all` presets are not enabled. Extra rules are limited to low-false-positive checks that directly improve correctness or readability.
|
|
42
|
+
|
|
43
|
+
## JavaScript and Import
|
|
44
|
+
|
|
45
|
+
- `camelcase: ["error", { properties: "never" }]` applies to variables and types while external protocol properties retain their original names.
|
|
46
|
+
- `no-empty` permits a completely empty `catch` and reports other empty blocks.
|
|
47
|
+
- `no-void` is an error; `void` is not used to hide a Promise or express an ignored return value.
|
|
48
|
+
- Real-risk rules such as `no-eval`, `no-implied-eval`, `no-new-func`, `no-promise-executor-return`, and `no-debugger` are errors.
|
|
49
|
+
- `curly` requires consistent braces only for multiline branches and does not force braces on every single-line branch.
|
|
50
|
+
- `import-x/first` and `import-x/no-duplicates` are errors.
|
|
51
|
+
- `import-x/order` is an error and fixes declaration order; common framework, tool, and `@/**` path groups extend the general groups.
|
|
52
|
+
- `pathGroupsExcludedImportTypes: ["type"]` keeps type imports in the final type group.
|
|
53
|
+
- Non-style side-effect imports participate in ordering. `style-imports-last` requires a final contiguous stylesheet group without sorting within it, preserving CSS cascade order.
|
|
54
|
+
- `sort-imports` is an error and only normalizes members inside one import declaration; `prefer-object-has-own` is not enabled.
|
|
55
|
+
|
|
56
|
+
## TypeScript
|
|
57
|
+
|
|
58
|
+
TypeScript always uses Project Service and `recommendedTypeChecked`. Linted files must belong to a discoverable `tsconfig.json`.
|
|
59
|
+
|
|
60
|
+
- `.ts`, `.mts`, and `.cts` files are SDK-like module boundaries: `explicit-module-boundary-types` is an error, so exported functions and public boundaries of exported classes require explicit types.
|
|
61
|
+
- `.tsx` files are UI component files: type-aware correctness rules remain enabled, but module-boundary annotations are not required for inferable JSX return types.
|
|
62
|
+
- `explicit-function-return-type` is disabled, leaving internal functions, local handlers, and callbacks to TypeScript inference.
|
|
63
|
+
- `no-inferrable-types` preserves explicit parameter and property types and only removes annotations without contract value, such as obvious local-variable types.
|
|
64
|
+
- Vue/NVue SFCs and standalone TSX components disable module-boundary and function-return requirements to preserve common concise component forms.
|
|
65
|
+
- `no-floating-promises` is disabled because waiting, returning, or handling a Promise depends on business semantics.
|
|
66
|
+
- `require-await` is an error; an `async` function without `await` changes return and exception semantics and should lose `async`.
|
|
67
|
+
- `no-misused-promises`, `await-thenable`, unsafe-type rules, exhaustive switches, getter/setter compatibility, and other high-confidence checks are errors.
|
|
68
|
+
- `return-await` requires `await` only when needed for correct error handling.
|
|
69
|
+
- Standard non-null assertions are permitted, while contradictory optional-chain or nullish-coalescing combinations remain errors.
|
|
70
|
+
- `no-explicit-any` and `no-deprecated` warn.
|
|
71
|
+
- `no-unnecessary-condition`, `unified-signatures`, and syntax-only preferences are disabled to preserve runtime guards and public overloads.
|
|
72
|
+
- Template strings allow numbers and booleans; dynamic property deletion and static utility classes are not forcibly rewritten.
|
|
73
|
+
- `prefer-nullish-coalescing` does not force primitive values from `||` to `??`; `prefer-optional-chain` applies only when the type explicitly contains null or undefined.
|
|
74
|
+
|
|
75
|
+
## Vue
|
|
76
|
+
|
|
77
|
+
- The official `flat/recommended` preset is the general Vue baseline.
|
|
78
|
+
- `no-v-html` warns so XSS risk is visible while sanitized content remains possible.
|
|
79
|
+
- `require-explicit-emits`, `no-dupe-keys`, `no-mutating-props`, `no-setup-props-reactivity-loss`, `no-ref-object-reactivity-loss`, and `no-reserved-component-names` are errors for Vue SFC and Vue JSX/TSX component scripts.
|
|
80
|
+
- `attribute-hyphenation`, `no-v-text-v-html-on-component`, and `attributes-order` remain limited to `.vue/.nvue` templates; `attributes-order` sorts definition, list-rendering, conditional, render-modifier, unique, global, ordinary, event, and content attributes.
|
|
81
|
+
- JSX attributes retain JavaScript camelCase conventions and do not inherit the template kebab-case rule.
|
|
82
|
+
- Setup props/ref reactivity loss and invalid custom-event names remain errors.
|
|
84
83
|
|
|
85
84
|
## UniApp boundary
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
Only the UniApp entry declares `uni`, `uniCloud`, page APIs, and conditional-platform objects such as `wx`, `plus`, `my`, and `tt`. The plain Vue entry neither receives these globals nor ignores `unpackage`.
|
|
88
87
|
|
|
89
|
-
ESLint does not execute conditional compilation
|
|
88
|
+
ESLint does not execute conditional compilation. It can avoid `no-undef` inside platform branches but cannot prove that an object occurs under the correct `#ifdef`.
|
|
90
89
|
|
|
91
|
-
##
|
|
90
|
+
## Manifest sorting and auto-fix
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
`package.json` and `tsconfig*.json` sorting is enabled by default in `createBaseConfigs()`, `vueConfig`, and `uniAppConfig`. The individual factories remain available for custom composition.
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
- Separate TypeScript `import type` declarations.
|
|
97
|
-
- Vue attribute naming and ordering.
|
|
98
|
-
- `package.json` and `tsconfig*.json` key order.
|
|
94
|
+
Review these fixes carefully:
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
- Import groups, path groups, type-import placement, and non-style side-effect import order.
|
|
97
|
+
- Stylesheet imports are only checked for final placement and are not moved or reordered automatically.
|
|
98
|
+
- Separate TypeScript `import type` and `export type` declarations.
|
|
99
|
+
- Default manifest key ordering.
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
Check before fixing:
|
|
103
102
|
|
|
104
103
|
```sh
|
|
105
104
|
pnpm exec eslint .
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Then apply fixes after reviewing the scope:
|
|
109
|
-
|
|
110
|
-
```sh
|
|
111
105
|
pnpm exec eslint . --fix
|
|
112
106
|
```
|
|
113
107
|
|
|
114
108
|
## Maintenance policy
|
|
115
109
|
|
|
116
|
-
1.
|
|
117
|
-
2.
|
|
118
|
-
3.
|
|
119
|
-
4.
|
|
110
|
+
1. Inspect effective rules after recommended preset upgrades so upstream changes do not silently alter severity.
|
|
111
|
+
2. Every new rule must explain the real problem it catches, its false-positive boundary, and whether it auto-fixes.
|
|
112
|
+
3. Frameworks add parsers, file scopes, and framework semantics without creating another language strictness tier.
|
|
113
|
+
4. Public entries, parser scopes, or auto-fix changes require matching type, runtime, and package tests.
|
package/docs/rules-risk.zh.md
CHANGED
|
@@ -1,119 +1,113 @@
|
|
|
1
1
|
# 默认规则与风险指南
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本文说明当前配置模型、主要规则和自动修复风险。源码注释只解释现行意图;历史差异记录在 `CHANGELOG.md`。
|
|
4
|
+
|
|
5
|
+
## 规则原则
|
|
6
|
+
|
|
7
|
+
规则按以下顺序取舍:
|
|
8
|
+
|
|
9
|
+
1. 符合 JavaScript、TypeScript 与 Vue 社区的通用标准写法,并以简洁、可读为前提。
|
|
10
|
+
2. 发现真实 Bug 和类型安全问题。
|
|
11
|
+
3. 保持跨项目代码一致性。
|
|
12
|
+
4. 最后才采用 Fast 系列项目的风格偏好。
|
|
13
|
+
|
|
14
|
+
纯粹为了 ESLint 而改变正常语义、增加样板代码或强制冷门写法的规则,不进入默认配置。
|
|
4
15
|
|
|
5
16
|
## 配置模型
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
Vue 3 和 UniApp 是根入口的两个独立具名完整配置:
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
- `vueConfig` 仅处理普通 Vue 项目。
|
|
21
|
+
- `uniAppConfig` 在 Vue 能力之外增加 `.nvue`、UniApp globals、清单适配和 `unpackage` 忽略。
|
|
10
22
|
|
|
11
|
-
|
|
12
|
-
- `.gitignore`
|
|
13
|
-
- JavaScript、类型感知 TypeScript
|
|
14
|
-
- Vue 3、`.nvue`、UniApp globals 与清单适配
|
|
15
|
-
- Import、RegExp、JSON/JSONC/JSON5
|
|
16
|
-
- `package.json` 和 `tsconfig*.json` 排序
|
|
17
|
-
- Prettier 冲突关闭层
|
|
18
|
-
- Node.js 工程文件 globals 与末尾规则覆写
|
|
23
|
+
根入口不提供默认导出,公开 `vueConfig`、`uniAppConfig`、`createVueProjectConfigs()`、`createUniAppProjectConfigs()`、`createBaseConfigs()`、`defineRules()` 及相关类型。
|
|
19
24
|
|
|
20
|
-
`
|
|
25
|
+
SDK、Node.js 和其他无框架项目使用 `createBaseConfigs()`。React、Angular、Markdown 和 Lodash 从 `./configs` 显式组合;清单排序属于所有完整配置的基础能力。
|
|
21
26
|
|
|
22
27
|
## 预置来源
|
|
23
28
|
|
|
24
29
|
| 领域 | 预置或实现 |
|
|
25
30
|
| ---------- | ----------------------------------------------------------------------- |
|
|
26
|
-
| JavaScript | `@eslint/js` recommended +
|
|
27
|
-
| TypeScript | typescript-eslint
|
|
31
|
+
| JavaScript | `@eslint/js` recommended + 本地高置信度规则 |
|
|
32
|
+
| TypeScript | typescript-eslint `recommendedTypeChecked` + Project Service |
|
|
28
33
|
| Vue | `eslint-plugin-vue` `flat/recommended` + 类型感知 TypeScript |
|
|
29
34
|
| React | `@eslint-react` recommended/type-checked + React Hooks Flat Recommended |
|
|
30
35
|
| Angular | Angular ESLint TypeScript、模板及无障碍 recommended |
|
|
31
36
|
| JSON | `eslint-plugin-jsonc` 三种方言 recommended |
|
|
32
|
-
| Import | `eslint-plugin-import-x` recommended +
|
|
37
|
+
| Import | `eslint-plugin-import-x` recommended + 通用顺序警告 |
|
|
33
38
|
| RegExp | 显式正确性、安全和超线性回溯规则 |
|
|
34
39
|
| Prettier | `eslint-config-prettier` 冲突关闭层 |
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- `camelcase: ["error", { properties: "never" }]`:变量和类型使用 camelCase
|
|
41
|
-
- `no-empty`
|
|
42
|
-
- `no-
|
|
43
|
-
- `no-debugger
|
|
44
|
-
- `
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
47
|
-
- `
|
|
48
|
-
- `
|
|
49
|
-
- `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
- `explicit-
|
|
58
|
-
- `no-
|
|
59
|
-
-
|
|
60
|
-
- `no-
|
|
61
|
-
- `
|
|
62
|
-
- `no-
|
|
63
|
-
- `
|
|
64
|
-
-
|
|
65
|
-
- `
|
|
66
|
-
- `no-
|
|
67
|
-
-
|
|
68
|
-
- `
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
- `
|
|
74
|
-
- `no-
|
|
75
|
-
- `no-v-text-v-html-on-component`
|
|
76
|
-
-
|
|
77
|
-
-
|
|
78
|
-
|
|
79
|
-
## 类型感知要求
|
|
80
|
-
|
|
81
|
-
TypeScript、Vue 和 React TSX 始终依赖类型信息。被检查文件必须属于可发现的 `tsconfig.json`,否则 Project Service 会报告配置错误。
|
|
82
|
-
|
|
83
|
-
本包不再提供 `typeChecked` 或 `tsconfigRootDir` 包装选项。复杂 monorepo 可以通过后置 Flat Config 直接覆盖 `languageOptions.parserOptions`,但不应通过关闭类型检查绕过项目边界问题。
|
|
41
|
+
没有启用完整 `strictTypeChecked`、`stylisticTypeChecked` 或机械式 `all` 预置。额外规则只选择误报低、能直接改善正确性或可读性的部分。
|
|
42
|
+
|
|
43
|
+
## JavaScript 与 Import
|
|
44
|
+
|
|
45
|
+
- `camelcase: ["error", { properties: "never" }]`:变量和类型使用 camelCase,外部协议属性可以保留原名。
|
|
46
|
+
- `no-empty` 允许完全空的 `catch`;其他空块仍报错。
|
|
47
|
+
- `no-void` 为错误,不使用 `void` 隐藏 Promise 或表达“忽略返回值”。
|
|
48
|
+
- `no-eval`、`no-implied-eval`、`no-new-func`、`no-promise-executor-return`、`no-debugger` 等真实风险规则为错误。
|
|
49
|
+
- `curly` 只要求多行条件分支使用一致花括号;不会强制所有单行分支加括号。
|
|
50
|
+
- `import-x/first` 和 `import-x/no-duplicates` 为错误。
|
|
51
|
+
- `import-x/order` 为错误,支持修复声明顺序;在通用分组之上保留常用框架、工具和 `@/**` pathGroups。
|
|
52
|
+
- `pathGroupsExcludedImportTypes: ["type"]` 保证类型导入统一留在最后的 type 总分组。
|
|
53
|
+
- 非样式副作用导入参与顺序检查;样式导入由 `style-imports-last` 强制形成最后一个连续分组,但组内不排序,避免改变 CSS 层叠顺序。
|
|
54
|
+
- `sort-imports` 为错误,只统一同一 import 声明内的成员顺序;`prefer-object-has-own` 不启用。
|
|
55
|
+
|
|
56
|
+
## TypeScript
|
|
57
|
+
|
|
58
|
+
TypeScript 始终启用 Project Service 和 `recommendedTypeChecked`。被检查文件必须属于可发现的 `tsconfig.json`。
|
|
59
|
+
|
|
60
|
+
- `.ts`、`.mts`、`.cts` 视为 SDK 式模块封装:`explicit-module-boundary-types` 为错误,导出函数及导出类的公共边界必须显式声明类型。
|
|
61
|
+
- `.tsx` 视为 UI 组件文件:保留类型感知正确性规则,但关闭模块边界类型强制,不要求补写可推断的 JSX 返回类型。
|
|
62
|
+
- `explicit-function-return-type` 关闭,内部函数、局部处理函数和回调使用 TypeScript 推断。
|
|
63
|
+
- `no-inferrable-types` 保留参数和属性上的显式类型,只清理局部变量等没有契约价值的冗余标注。
|
|
64
|
+
- Vue/NVue SFC 与独立 TSX 组件关闭模块边界和函数返回类型要求,保留常见组件写法。
|
|
65
|
+
- `no-floating-promises` 关闭;是否等待、返回或处理 Promise 由业务语义决定。
|
|
66
|
+
- `require-await` 为错误;没有 `await` 的 `async` 会改变返回值和异常语义,应删除 `async`。
|
|
67
|
+
- `no-misused-promises`、`await-thenable`、unsafe 类型规则、穷尽 switch、getter/setter 类型一致性等高置信度检查为错误。
|
|
68
|
+
- `return-await` 只在错误处理正确性需要时要求 `await`。
|
|
69
|
+
- 标准非空断言允许使用;可选链后非空断言、空值合并前非空断言等矛盾组合仍报错。
|
|
70
|
+
- `no-explicit-any` 和 `no-deprecated` 为警告。
|
|
71
|
+
- `no-unnecessary-condition`、`unified-signatures` 及纯语法偏好关闭,避免删除运行时防御或改写公共重载。
|
|
72
|
+
- 模板字符串允许 number 和 boolean;动态字段删除和纯静态工具类不强制改写。
|
|
73
|
+
- `prefer-nullish-coalescing` 不强制原始类型从 `||` 改为 `??`;`prefer-optional-chain` 只在类型明确包含 null/undefined 时要求改写。
|
|
74
|
+
|
|
75
|
+
## Vue
|
|
76
|
+
|
|
77
|
+
- 使用官方 `flat/recommended` 作为通用 Vue 基线。
|
|
78
|
+
- `no-v-html` 为警告,提醒审查 XSS 风险但允许已净化内容。
|
|
79
|
+
- `require-explicit-emits`、`no-dupe-keys`、`no-mutating-props`、`no-setup-props-reactivity-loss`、`no-ref-object-reactivity-loss` 和 `no-reserved-component-names` 为错误,并应用于 Vue SFC 与 Vue JSX/TSX 的组件脚本。
|
|
80
|
+
- `attribute-hyphenation`、`no-v-text-v-html-on-component` 和 `attributes-order` 仅应用于 `.vue/.nvue` 模板;`attributes-order` 按定义、循环、条件、渲染修饰、唯一属性、全局属性、普通属性、事件和内容排序。
|
|
81
|
+
- JSX 属性继续使用 JavaScript 的 camelCase 约定,不受模板 kebab-case 规则影响。
|
|
82
|
+
- setup props/ref 响应性丢失和自定义事件命名错误仍为错误。
|
|
84
83
|
|
|
85
84
|
## UniApp 边界
|
|
86
85
|
|
|
87
|
-
|
|
86
|
+
只有 UniApp 入口声明 `uni`、`uniCloud`、页面 API 及 `wx`、`plus`、`my`、`tt` 等条件编译平台对象。普通 Vue 入口不会获得这些 globals,也不会忽略 `unpackage`。
|
|
88
87
|
|
|
89
|
-
ESLint
|
|
88
|
+
ESLint 不执行条件编译,所以能避免平台分支中的 `no-undef`,但不能验证对象是否出现在正确的 `#ifdef` 分支。
|
|
90
89
|
|
|
91
|
-
##
|
|
90
|
+
## 清单排序与自动修复
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
`package.json` 和 `tsconfig*.json` 排序属于 `createBaseConfigs()`、`vueConfig` 和 `uniAppConfig` 的默认配置。独立片段工厂仍可用于自定义组合。
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
- TypeScript 独立 `import type` 声明。
|
|
97
|
-
- Vue 属性命名与排序。
|
|
98
|
-
- `package.json` 和 `tsconfig*.json` 字段顺序。
|
|
94
|
+
重点审查以下自动修复:
|
|
99
95
|
|
|
100
|
-
|
|
96
|
+
- Import 分组、pathGroups、类型导入位置与非样式副作用导入顺序。
|
|
97
|
+
- 样式导入只检查是否位于最后,不自动移动或重排。
|
|
98
|
+
- TypeScript 独立 `import type` / `export type`。
|
|
99
|
+
- 默认启用的清单字段排序。
|
|
101
100
|
|
|
102
|
-
|
|
101
|
+
先检查,再修复:
|
|
103
102
|
|
|
104
103
|
```sh
|
|
105
104
|
pnpm exec eslint .
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
确认问题范围后再运行:
|
|
109
|
-
|
|
110
|
-
```sh
|
|
111
105
|
pnpm exec eslint . --fix
|
|
112
106
|
```
|
|
113
107
|
|
|
114
108
|
## 维护约定
|
|
115
109
|
|
|
116
|
-
1.
|
|
117
|
-
2.
|
|
118
|
-
3.
|
|
119
|
-
4.
|
|
110
|
+
1. 升级 recommended 预置后检查最终生效配置,避免上游变化静默改变严重级别。
|
|
111
|
+
2. 新规则必须说明它解决的真实问题、误报边界和是否自动修复。
|
|
112
|
+
3. 框架只增加解析器、文件范围和框架语义,不建立第二套语言严格度。
|
|
113
|
+
4. 公共入口、解析器范围或自动修复行为变化时同步更新类型、运行时和发布测试。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fast-china/eslint-config",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "Practical, typed ESLint Flat Config for Vue 3, UniApp, React, Angular, Vite, TypeScript, JavaScript, and Node.js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -72,6 +72,8 @@
|
|
|
72
72
|
"dev": "eslint-config-inspector --config src/eslint-inspector.config.ts",
|
|
73
73
|
"build": "pnpm run typegen:check && tsdown",
|
|
74
74
|
"build:inspector": "eslint-config-inspector build --config src/eslint-inspector.config.ts",
|
|
75
|
+
"docs:rules": "tsx scripts/rules-docs.ts",
|
|
76
|
+
"docs:rules:check": "tsx scripts/rules-docs.ts --check",
|
|
75
77
|
"typegen": "tsx scripts/typegen.ts",
|
|
76
78
|
"typegen:check": "tsx scripts/typegen.ts --check",
|
|
77
79
|
"typecheck": "tsc --noEmit",
|
|
@@ -83,7 +85,7 @@
|
|
|
83
85
|
"test:types": "tsc --noEmit --project tests/tsconfig.json",
|
|
84
86
|
"test:runtime": "node --test tests/config.test.mjs",
|
|
85
87
|
"test:package": "node --test tests/package.test.mjs",
|
|
86
|
-
"check": "pnpm run typecheck && pnpm run test && pnpm run lint && pnpm run format:check",
|
|
88
|
+
"check": "pnpm run typecheck && pnpm run docs:rules:check && pnpm run test && pnpm run lint && pnpm run format:check",
|
|
87
89
|
"prepack": "pnpm run check"
|
|
88
90
|
},
|
|
89
91
|
"peerDependencies": {
|