@fast-china/eslint-config 1.1.0 → 2.0.0
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/README.md +106 -80
- package/README.zh.md +107 -81
- package/dist/index.d.ts +110 -236
- package/dist/index.js +241 -218
- package/dist/index.js.map +1 -1
- package/dist/rules/index.d.ts +41 -36
- package/dist/rules/index.js +62 -48
- package/dist/rules/index.js.map +1 -1
- package/docs/engineering-audit.zh.md +73 -82
- package/docs/rules-risk.md +33 -44
- package/docs/rules-risk.zh.md +34 -45
- package/package.json +5 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and releases should follow [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## Unreleased
|
|
8
|
+
|
|
9
|
+
## 2.0.0 - 2026-07-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Published the ESM-only `fastConfig(options, ...overrides)` factory for Vue 3, Vite, TypeScript, JavaScript, Node.js, JSON dialects, Markdown, RegExp, import rules, Prettier conflict handling, and project overrides.
|
|
14
|
+
- Added environment-aware globals, `.gitignore` support, global ignore patterns, language switches, and file-scoped trailing overrides.
|
|
15
|
+
- Added optional type-aware TypeScript and Vue linting through typescript-eslint Project Service.
|
|
16
|
+
- Added opt-in `lodash` and `lodash-unified` static import policies without requiring an additional ESLint plugin.
|
|
17
|
+
- Added opt-in, semantics-aware `package.json` and `tsconfig*.json` sorting that preserves conditional export order.
|
|
18
|
+
- Added schema-generated `RuleOptions`, factory-level typed rules, and `defineRules()` for exact rule-name and rule-option completion.
|
|
19
|
+
- Published fully commented raw rule records through `@fast-china/eslint-config/rules`.
|
|
20
|
+
- Added bilingual usage and risk documentation, contribution guidance, and an engineering quality audit.
|
|
21
|
+
- Added deterministic type-generation checks, consumer type tests, runtime integration tests, multi-version Node.js CI, and publish-archive inspection.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Raised the minimum supported Node.js version to 22.13.0 so the package, local development workflow, and pnpm 11 CI use one consistent runtime baseline.
|
package/README.md
CHANGED
|
@@ -10,16 +10,18 @@ A practical, typed ESLint Flat Config for Vue 3, Vite, TypeScript, and JavaScrip
|
|
|
10
10
|
## Highlights
|
|
11
11
|
|
|
12
12
|
- Built for ESLint 10 and the native Flat Config format.
|
|
13
|
-
- Vue 3 + TypeScript + Vite defaults, with
|
|
13
|
+
- Vue 3 + TypeScript + Vite defaults, with type-aware linting and language integrations controlled explicitly.
|
|
14
14
|
- First-class JavaScript, TypeScript, Vue SFC, JSON, JSONC, JSON5, Markdown, RegExp, and import rules.
|
|
15
|
-
-
|
|
15
|
+
- One focused `fastConfig()` factory with a compact public API and no project-file reads at module import time.
|
|
16
16
|
- Schema-generated rule types provide exact rule-name and rule-option completion.
|
|
17
17
|
- Plugins and parsers are regular package dependencies, so consumers do not need to assemble the plugin graph.
|
|
18
18
|
- Prettier stays a formatter: the default only disables conflicting ESLint rules and does not run Prettier inside ESLint.
|
|
19
|
+
- Manifest sorting is explicit opt-in, preventing an unexpected large first-fix diff.
|
|
20
|
+
- An opt-in Lodash policy keeps projects on either `lodash` or `lodash-unified` without mixing package entry points.
|
|
19
21
|
|
|
20
22
|
## Requirements
|
|
21
23
|
|
|
22
|
-
- Node.js `^
|
|
24
|
+
- Node.js `^22.13.0` or `^24.0.0`
|
|
23
25
|
- ESLint `^10.0.0`
|
|
24
26
|
- TypeScript `>=5.3.0 <6.1.0`
|
|
25
27
|
|
|
@@ -38,83 +40,115 @@ Equivalent npm, Yarn, and Bun commands work as well.
|
|
|
38
40
|
Create `eslint.config.mjs`:
|
|
39
41
|
|
|
40
42
|
```js
|
|
41
|
-
import { defineConfig } from "eslint/config";
|
|
42
|
-
|
|
43
43
|
import fastChina from "@fast-china/eslint-config";
|
|
44
44
|
|
|
45
|
-
export default
|
|
45
|
+
export default fastChina();
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
The default enables Vue 3, TypeScript, JavaScript, JSON dialects, Markdown, import ordering, RegExp checks, `.gitignore`, browser globals, and Node globals for common config, script, test, and CLI files.
|
|
49
49
|
|
|
50
50
|
## Other project types
|
|
51
51
|
|
|
52
|
-
Use `
|
|
52
|
+
Use the default `fastConfig()` factory to keep only what a project needs.
|
|
53
53
|
|
|
54
54
|
### Node.js + TypeScript
|
|
55
55
|
|
|
56
56
|
```js
|
|
57
|
-
import
|
|
58
|
-
|
|
59
|
-
import { createConfig } from "@fast-china/eslint-config";
|
|
57
|
+
import fastChina from "@fast-china/eslint-config";
|
|
60
58
|
|
|
61
|
-
export default
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
);
|
|
59
|
+
export default fastChina({
|
|
60
|
+
environment: "node",
|
|
61
|
+
vue: false,
|
|
62
|
+
});
|
|
67
63
|
```
|
|
68
64
|
|
|
69
65
|
### JavaScript only
|
|
70
66
|
|
|
71
67
|
```js
|
|
72
|
-
import
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
typescript: false,
|
|
82
|
-
vue: false,
|
|
83
|
-
})
|
|
84
|
-
);
|
|
68
|
+
import fastChina from "@fast-china/eslint-config";
|
|
69
|
+
|
|
70
|
+
export default fastChina({
|
|
71
|
+
environment: "node",
|
|
72
|
+
json: false,
|
|
73
|
+
markdown: false,
|
|
74
|
+
typescript: false,
|
|
75
|
+
vue: false,
|
|
76
|
+
});
|
|
85
77
|
```
|
|
86
78
|
|
|
87
79
|
### Type-aware TypeScript rules
|
|
88
80
|
|
|
89
81
|
```js
|
|
90
|
-
import
|
|
91
|
-
|
|
92
|
-
import { createConfig } from "@fast-china/eslint-config";
|
|
82
|
+
import fastChina from "@fast-china/eslint-config";
|
|
93
83
|
|
|
94
|
-
export default
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
);
|
|
84
|
+
export default fastChina({
|
|
85
|
+
typescript: {
|
|
86
|
+
tsconfigRootDir: import.meta.dirname,
|
|
87
|
+
typeChecked: true,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
100
90
|
```
|
|
101
91
|
|
|
102
|
-
Type-aware linting uses the typescript-eslint
|
|
92
|
+
Type-aware linting uses the typescript-eslint Project Service. Project files must belong to a `tsconfig.json`. Most projects can omit `tsconfigRootDir`; complex monorepos should pass the directory containing the ESLint config explicitly.
|
|
103
93
|
|
|
104
94
|
## Options
|
|
105
95
|
|
|
106
|
-
| Option
|
|
107
|
-
|
|
|
108
|
-
| `environment`
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
96
|
+
| Option | Default | Purpose |
|
|
97
|
+
| ----------------- | ----------- | ------------------------------------------------------------------- |
|
|
98
|
+
| `environment` | `"browser"` | Use `"browser"`, `"node"`, or `"universal"` globals. |
|
|
99
|
+
| `globals` | none | Add globals supplied by a host platform or test runner. |
|
|
100
|
+
| `gitignore` | `true` | Read ignore patterns from the project `.gitignore`. |
|
|
101
|
+
| `ignores` | `[]` | Append project-specific global ignore patterns. |
|
|
102
|
+
| `imports` | `true` | Enable import-x correctness and ordering rules. |
|
|
103
|
+
| `javascript` | `true` | Process JavaScript and JSX files. |
|
|
104
|
+
| `json` | `true` | Enable recommended JSON, JSONC, and JSON5 rules. |
|
|
105
|
+
| `lodash` | `false` | Select `"lodash"` or `"lodash-unified"` for static imports. |
|
|
106
|
+
| `markdown` | `true` | Enable the official Markdown language rules. |
|
|
107
|
+
| `prettier` | `true` | Disable ESLint rules that conflict with Prettier. |
|
|
108
|
+
| `regexp` | `true` | Enable recommended RegExp rules. |
|
|
109
|
+
| `rules` | none | Add exactly typed project rules to every enabled code file. |
|
|
110
|
+
| `sortPackageJson` | `false` | Sort safe package.json keys without entering conditional `exports`. |
|
|
111
|
+
| `sortTsconfig` | `false` | Sort `tsconfig*.json` by TypeScript documentation topics. |
|
|
112
|
+
| `typescript` | `true` | Disable it or pass `{ typeChecked: true, tsconfigRootDir }`. |
|
|
113
|
+
| `vue` | `true` | Enable Vue 3 single-file components. |
|
|
114
|
+
|
|
115
|
+
## Lodash import policy
|
|
116
|
+
|
|
117
|
+
The default, `lodash: false`, leaves the dependency choice to the project. Select one policy when every static import should use the same package:
|
|
118
|
+
|
|
119
|
+
- `lodash: "lodash-unified"` rejects static imports and re-exports from `lodash`, `lodash-es`, and their subpaths.
|
|
120
|
+
- `lodash: "lodash"` rejects static imports and re-exports from `lodash-es`, `lodash-unified`, and their subpaths. The `lodash` root and `lodash/*` method imports remain valid.
|
|
121
|
+
|
|
122
|
+
Choose `lodash-unified`:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm add lodash-unified
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import fastChina from "@fast-china/eslint-config";
|
|
130
|
+
import { cloneDeep, debounce } from "lodash-unified";
|
|
131
|
+
|
|
132
|
+
export default fastChina({ lodash: "lodash-unified" });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Choose standard `lodash`:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
pnpm add lodash
|
|
139
|
+
pnpm add -D @types/lodash
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
import fastChina from "@fast-china/eslint-config";
|
|
144
|
+
import debounce from "lodash/debounce";
|
|
145
|
+
|
|
146
|
+
export default fastChina({ lodash: "lodash" });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This feature uses ESLint core `no-restricted-imports`, adds no plugin, and does not install Lodash for the project. It checks static `import`/`export` only, not dynamic `import()` or CommonJS `require()`. Setting `imports: false` disables import-x but leaves an explicitly selected Lodash policy active.
|
|
150
|
+
|
|
151
|
+
If a later `rules` record or file-scoped override sets `no-restricted-imports`, ESLint replaces this complete policy instead of merging its options. Projects that need additional package restrictions can import raw `preferLodashRules` or `preferLodashUnifiedRules` from `@fast-china/eslint-config/rules` and maintain one combined rule.
|
|
118
152
|
|
|
119
153
|
## Exact rule types and completion
|
|
120
154
|
|
|
@@ -122,9 +156,7 @@ The package generates `RuleOptions` from the JSON Schemas published by ESLint co
|
|
|
122
156
|
|
|
123
157
|
```js
|
|
124
158
|
// @ts-check
|
|
125
|
-
import {
|
|
126
|
-
|
|
127
|
-
import { createConfig, defineRules } from "@fast-china/eslint-config";
|
|
159
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
128
160
|
|
|
129
161
|
const projectRules = defineRules({
|
|
130
162
|
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
@@ -132,13 +164,14 @@ const projectRules = defineRules({
|
|
|
132
164
|
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
133
165
|
});
|
|
134
166
|
|
|
135
|
-
export default
|
|
136
|
-
|
|
167
|
+
export default fastChina(
|
|
168
|
+
{ rules: projectRules },
|
|
137
169
|
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
170
|
+
files: ["**/*.generated.ts"],
|
|
171
|
+
name: "project/generated",
|
|
172
|
+
rules: defineRules({ "@typescript-eslint/no-unused-vars": "off" }),
|
|
173
|
+
}
|
|
174
|
+
);
|
|
142
175
|
```
|
|
143
176
|
|
|
144
177
|
TypeScript configuration and tooling code can use the generated interface directly:
|
|
@@ -155,31 +188,32 @@ The generated set covers ESLint core and plugins bundled by this package. Rules
|
|
|
155
188
|
|
|
156
189
|
## Rule risk and maintenance
|
|
157
190
|
|
|
158
|
-
The default includes a small set of high-impact rules. They can
|
|
191
|
+
The default includes a small set of high-impact rules. They can block particular patterns or require a review of import side effects, type-only imports, and public component events. Manifest sorting is also high-impact but is disabled by default. Source comments mark these decisions as `[高影响]`, `[可自动修复]`, or `[安全关注]`.
|
|
159
192
|
|
|
160
193
|
See the [default-rule and risk guide](./docs/rules-risk.md) for inherited presets, the high-impact inventory, scoped override examples, and the maintenance contract. Run a read-only lint before `eslint --fix`, apply fixes in an isolated commit, and review imports, `package.json`, component events, and build output.
|
|
161
194
|
|
|
162
195
|
## Project overrides
|
|
163
196
|
|
|
164
|
-
|
|
197
|
+
Put common overrides in `rules`, and pass file-scoped overrides as later arguments. Later configurations take precedence:
|
|
165
198
|
|
|
166
199
|
```js
|
|
167
|
-
import {
|
|
200
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
168
201
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
export default defineConfig([
|
|
172
|
-
...createConfig({ vue: 3 }),
|
|
202
|
+
export default fastChina(
|
|
173
203
|
{
|
|
174
|
-
name: "project/overrides",
|
|
175
204
|
rules: {
|
|
176
|
-
"no-console": "
|
|
205
|
+
"no-console": "warn",
|
|
177
206
|
},
|
|
178
207
|
},
|
|
179
|
-
|
|
208
|
+
{
|
|
209
|
+
files: ["**/{scripts,tests}/**/*.{js,ts}"],
|
|
210
|
+
name: "project/node-files",
|
|
211
|
+
rules: defineRules({ "no-console": "off" }),
|
|
212
|
+
}
|
|
213
|
+
);
|
|
180
214
|
```
|
|
181
215
|
|
|
182
|
-
|
|
216
|
+
The root entry exports only `fastConfig`, `defaultConfigOptions`, `defineRules`, and their related types. Advanced consumers can import the fully commented raw rule records from `@fast-china/eslint-config/rules`.
|
|
183
217
|
|
|
184
218
|
## Prettier
|
|
185
219
|
|
|
@@ -198,21 +232,13 @@ Set `prettier: false` if another formatter or stylistic rule set should remain f
|
|
|
198
232
|
pnpm install
|
|
199
233
|
pnpm typegen
|
|
200
234
|
pnpm check
|
|
235
|
+
pnpm pack --dry-run
|
|
201
236
|
```
|
|
202
237
|
|
|
203
238
|
Run `pnpm typegen` after upgrading ESLint or a plugin and commit `src/typegen.d.ts`; never edit the generated file manually. `pnpm check` verifies that generated types are current, builds the package, type-checks source, lints all supported file types, checks formatting, and runs both runtime and consumer type tests against the built package.
|
|
204
239
|
|
|
205
240
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) for the contribution workflow, the [default-rule and risk guide](./docs/rules-risk.md) for rule maintenance, and [the engineering audit](./docs/engineering-audit.zh.md) for the current quality baseline.
|
|
206
241
|
|
|
207
|
-
## Migration from 1.0.48 and earlier
|
|
208
|
-
|
|
209
|
-
- Existing `export default [...fastChina]` usage still works.
|
|
210
|
-
- The package is ESM-only and no longer exposes a misleading CommonJS condition.
|
|
211
|
-
- Vue 3 is the explicit default; use `createConfig({ vue: 2 })` for Vue 2.
|
|
212
|
-
- `lodash` and `lodash-es` are no longer banned by default. The organization-specific rule records remain available from the rules subpath.
|
|
213
|
-
- Prettier no longer runs inside ESLint. Run the Prettier CLI or editor integration separately.
|
|
214
|
-
- ESLint 10 now determines the Node.js minimum shown above.
|
|
215
|
-
|
|
216
242
|
## License
|
|
217
243
|
|
|
218
244
|
[Apache-2.0](./LICENSE)
|
package/README.zh.md
CHANGED
|
@@ -9,17 +9,19 @@
|
|
|
9
9
|
|
|
10
10
|
## 特性
|
|
11
11
|
|
|
12
|
-
- 基于 ESLint 10
|
|
13
|
-
- 默认针对 Vue 3 + TypeScript + Vite
|
|
12
|
+
- 基于 ESLint 10,仅提供原生 Flat Config。
|
|
13
|
+
- 默认针对 Vue 3 + TypeScript + Vite,可显式开启类型感知规则或关闭不需要的语言能力。
|
|
14
14
|
- 完整覆盖 JavaScript、TypeScript、Vue SFC、JSON、JSONC、JSON5、Markdown、正则表达式与导入规则。
|
|
15
|
-
-
|
|
15
|
+
- 默认导出单一 `fastConfig()` 工厂,公共 API 清晰,并且不会在导入模块时读取项目文件。
|
|
16
16
|
- 根据 ESLint 与内置插件的规则 schema 生成精确类型,提供规则名和规则选项自动补全。
|
|
17
17
|
- 插件与解析器均由本包直接声明依赖,使用者不需要手工拼装插件依赖树。
|
|
18
18
|
- Prettier 只负责格式化:默认配置仅关闭冲突规则,不在 ESLint 内重复运行 Prettier。
|
|
19
|
+
- `package.json` 与 `tsconfig.json` 排序为显式 opt-in,避免安装后首次修复产生非预期大 diff。
|
|
20
|
+
- 可选统一使用 `lodash` 或 `lodash-unified`,避免同一项目混用多个 Lodash 入口。
|
|
19
21
|
|
|
20
22
|
## 环境要求
|
|
21
23
|
|
|
22
|
-
- Node.js `^
|
|
24
|
+
- Node.js `^22.13.0` 或 `^24.0.0`
|
|
23
25
|
- ESLint `^10.0.0`
|
|
24
26
|
- TypeScript `>=5.3.0 <6.1.0`
|
|
25
27
|
|
|
@@ -38,83 +40,115 @@ pnpm add -D eslint typescript @fast-china/eslint-config
|
|
|
38
40
|
创建 `eslint.config.mjs`:
|
|
39
41
|
|
|
40
42
|
```js
|
|
41
|
-
import { defineConfig } from "eslint/config";
|
|
42
|
-
|
|
43
43
|
import fastChina from "@fast-china/eslint-config";
|
|
44
44
|
|
|
45
|
-
export default
|
|
45
|
+
export default fastChina();
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
默认配置会启用 Vue 3、TypeScript、JavaScript、JSON 各方言、Markdown、导入排序、正则检查、`.gitignore` 与浏览器全局变量;常见配置文件、脚本、测试和 CLI 文件会额外获得 Node.js 全局变量。
|
|
49
49
|
|
|
50
50
|
## 适配其他项目
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
通过默认导出的 `fastConfig()` 只保留项目真正需要的能力。
|
|
53
53
|
|
|
54
54
|
### Node.js + TypeScript
|
|
55
55
|
|
|
56
56
|
```js
|
|
57
|
-
import
|
|
58
|
-
|
|
59
|
-
import { createConfig } from "@fast-china/eslint-config";
|
|
57
|
+
import fastChina from "@fast-china/eslint-config";
|
|
60
58
|
|
|
61
|
-
export default
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
);
|
|
59
|
+
export default fastChina({
|
|
60
|
+
environment: "node",
|
|
61
|
+
vue: false,
|
|
62
|
+
});
|
|
67
63
|
```
|
|
68
64
|
|
|
69
65
|
### 纯 JavaScript
|
|
70
66
|
|
|
71
67
|
```js
|
|
72
|
-
import
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
typescript: false,
|
|
82
|
-
vue: false,
|
|
83
|
-
})
|
|
84
|
-
);
|
|
68
|
+
import fastChina from "@fast-china/eslint-config";
|
|
69
|
+
|
|
70
|
+
export default fastChina({
|
|
71
|
+
environment: "node",
|
|
72
|
+
json: false,
|
|
73
|
+
markdown: false,
|
|
74
|
+
typescript: false,
|
|
75
|
+
vue: false,
|
|
76
|
+
});
|
|
85
77
|
```
|
|
86
78
|
|
|
87
79
|
### 启用 TypeScript 类型感知规则
|
|
88
80
|
|
|
89
81
|
```js
|
|
90
|
-
import
|
|
91
|
-
|
|
92
|
-
import { createConfig } from "@fast-china/eslint-config";
|
|
82
|
+
import fastChina from "@fast-china/eslint-config";
|
|
93
83
|
|
|
94
|
-
export default
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
);
|
|
84
|
+
export default fastChina({
|
|
85
|
+
typescript: {
|
|
86
|
+
tsconfigRootDir: import.meta.dirname,
|
|
87
|
+
typeChecked: true,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
100
90
|
```
|
|
101
91
|
|
|
102
|
-
类型感知模式使用 typescript-eslint
|
|
92
|
+
类型感知模式使用 typescript-eslint Project Service,被检查的文件必须属于某个 `tsconfig.json`。普通项目通常可省略 `tsconfigRootDir`;复杂 monorepo 建议显式传入配置文件所在目录。
|
|
103
93
|
|
|
104
94
|
## 配置选项
|
|
105
95
|
|
|
106
|
-
| 选项
|
|
107
|
-
|
|
|
108
|
-
| `environment`
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
| `
|
|
114
|
-
| `
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
96
|
+
| 选项 | 默认值 | 作用 |
|
|
97
|
+
| ----------------- | ----------- | -------------------------------------------------------------- |
|
|
98
|
+
| `environment` | `"browser"` | 可选 `"browser"`、`"node"` 或 `"universal"` 全局变量。 |
|
|
99
|
+
| `globals` | 无 | 增加项目宿主、测试运行器等提供的全局变量。 |
|
|
100
|
+
| `gitignore` | `true` | 读取项目根目录的 `.gitignore`。 |
|
|
101
|
+
| `ignores` | `[]` | 追加项目自己的全局忽略模式。 |
|
|
102
|
+
| `imports` | `true` | 启用 import-x 正确性与排序规则。 |
|
|
103
|
+
| `javascript` | `true` | 处理 JavaScript 与 JSX。 |
|
|
104
|
+
| `json` | `true` | 启用 JSON、JSONC 与 JSON5 推荐规则。 |
|
|
105
|
+
| `lodash` | `false` | 可选 `"lodash"` 或 `"lodash-unified"`,统一静态导入来源。 |
|
|
106
|
+
| `markdown` | `true` | 启用官方 Markdown 语言规则。 |
|
|
107
|
+
| `prettier` | `true` | 关闭与 Prettier 冲突的 ESLint 规则。 |
|
|
108
|
+
| `regexp` | `true` | 启用推荐的正则表达式规则。 |
|
|
109
|
+
| `rules` | 无 | 对所有已启用代码文件追加具有精确类型的项目规则。 |
|
|
110
|
+
| `sortPackageJson` | `false` | 按安全白名单排序 `package.json`,不会进入 `exports` 条件对象。 |
|
|
111
|
+
| `sortTsconfig` | `false` | 按 TypeScript 文档主题排序 `tsconfig*.json`。 |
|
|
112
|
+
| `typescript` | `true` | 可关闭,或传入 `{ typeChecked: true, tsconfigRootDir }`。 |
|
|
113
|
+
| `vue` | `true` | 启用 Vue 3 单文件组件支持。 |
|
|
114
|
+
|
|
115
|
+
## Lodash 导入策略
|
|
116
|
+
|
|
117
|
+
默认值 `lodash: false` 不限制项目选择。需要统一依赖入口时,可选择以下任一策略:
|
|
118
|
+
|
|
119
|
+
- `lodash: "lodash-unified"`:禁止从 `lodash`、`lodash-es` 及其子路径静态导入或重新导出。
|
|
120
|
+
- `lodash: "lodash"`:禁止从 `lodash-es`、`lodash-unified` 及其子路径静态导入或重新导出;允许 `lodash` 根入口和 `lodash/*` 按方法导入。
|
|
121
|
+
|
|
122
|
+
选择 `lodash-unified`:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm add lodash-unified
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import fastChina from "@fast-china/eslint-config";
|
|
130
|
+
import { cloneDeep, debounce } from "lodash-unified";
|
|
131
|
+
|
|
132
|
+
export default fastChina({ lodash: "lodash-unified" });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
选择标准 `lodash`:
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
pnpm add lodash
|
|
139
|
+
pnpm add -D @types/lodash
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
import fastChina from "@fast-china/eslint-config";
|
|
144
|
+
import debounce from "lodash/debounce";
|
|
145
|
+
|
|
146
|
+
export default fastChina({ lodash: "lodash" });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
该能力使用 ESLint 核心 `no-restricted-imports`,不需要额外插件,也不会替项目安装 Lodash。它只检查静态 `import`/`export`,不检查动态 `import()` 或 CommonJS `require()`。`imports: false` 只关闭 import-x,不会关闭已经显式选择的 Lodash 策略。
|
|
150
|
+
|
|
151
|
+
如果后续 `rules` 或文件级覆写再次设置 `no-restricted-imports`,ESLint 会用后面的完整规则替换这套策略,而不是合并选项。需要组合更多包限制时,可从 `@fast-china/eslint-config/rules` 导入原始 `preferLodashRules` 或 `preferLodashUnifiedRules`,统一维护一份完整规则。
|
|
118
152
|
|
|
119
153
|
## 精确规则类型与自动补全
|
|
120
154
|
|
|
@@ -122,9 +156,7 @@ export default defineConfig(
|
|
|
122
156
|
|
|
123
157
|
```js
|
|
124
158
|
// @ts-check
|
|
125
|
-
import {
|
|
126
|
-
|
|
127
|
-
import { createConfig, defineRules } from "@fast-china/eslint-config";
|
|
159
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
128
160
|
|
|
129
161
|
const projectRules = defineRules({
|
|
130
162
|
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
@@ -132,13 +164,14 @@ const projectRules = defineRules({
|
|
|
132
164
|
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
133
165
|
});
|
|
134
166
|
|
|
135
|
-
export default
|
|
136
|
-
|
|
167
|
+
export default fastChina(
|
|
168
|
+
{ rules: projectRules },
|
|
137
169
|
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
170
|
+
files: ["**/*.generated.ts"],
|
|
171
|
+
name: "project/generated",
|
|
172
|
+
rules: defineRules({ "@typescript-eslint/no-unused-vars": "off" }),
|
|
173
|
+
}
|
|
174
|
+
);
|
|
142
175
|
```
|
|
143
176
|
|
|
144
177
|
在 TypeScript 配置或工具代码中,也可以直接使用:
|
|
@@ -155,31 +188,32 @@ const rules = {
|
|
|
155
188
|
|
|
156
189
|
## 规则风险与维护
|
|
157
190
|
|
|
158
|
-
|
|
191
|
+
默认配置包含少量高影响规则:它们可能阻断特定写法,或要求复核 import 副作用、类型导入和组件公共事件。清单排序同样属于高影响能力,但默认关闭。源码使用 `[高影响]`、`[可自动修复]` 与 `[安全关注]` 标记这类规则。
|
|
159
192
|
|
|
160
193
|
完整的默认预置来源、高影响规则清单、关闭示例和维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md)。运行 `eslint --fix` 前建议先只检查,在独立提交中应用修复,并审查 import、`package.json`、组件事件和构建产物。
|
|
161
194
|
|
|
162
195
|
## 覆盖项目规则
|
|
163
196
|
|
|
164
|
-
|
|
197
|
+
最常用的全局覆盖可以直接放入 `rules`;按文件覆盖作为后续参数传入,后面的配置优先级更高:
|
|
165
198
|
|
|
166
199
|
```js
|
|
167
|
-
import {
|
|
200
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
168
201
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
export default defineConfig([
|
|
172
|
-
...createConfig({ vue: 3 }),
|
|
202
|
+
export default fastChina(
|
|
173
203
|
{
|
|
174
|
-
name: "project/overrides",
|
|
175
204
|
rules: {
|
|
176
|
-
"no-console": "
|
|
205
|
+
"no-console": "warn",
|
|
177
206
|
},
|
|
178
207
|
},
|
|
179
|
-
|
|
208
|
+
{
|
|
209
|
+
files: ["**/{scripts,tests}/**/*.{js,ts}"],
|
|
210
|
+
name: "project/node-files",
|
|
211
|
+
rules: defineRules({ "no-console": "off" }),
|
|
212
|
+
}
|
|
213
|
+
);
|
|
180
214
|
```
|
|
181
215
|
|
|
182
|
-
|
|
216
|
+
根入口只公开 `fastConfig`、`defaultConfigOptions`、`defineRules` 及相关类型。高级使用者可以从 `@fast-china/eslint-config/rules` 导入有完整注释的原始规则记录。
|
|
183
217
|
|
|
184
218
|
## Prettier
|
|
185
219
|
|
|
@@ -198,21 +232,13 @@ pnpm exec prettier --check .
|
|
|
198
232
|
pnpm install
|
|
199
233
|
pnpm typegen
|
|
200
234
|
pnpm check
|
|
235
|
+
pnpm pack --dry-run
|
|
201
236
|
```
|
|
202
237
|
|
|
203
238
|
升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`;不要手工编辑生成文件。`pnpm check` 会验证生成类型没有漂移,然后依次构建、类型检查、检查所有支持的文件类型、验证格式,并针对构建后的真实包运行运行时和消费者类型测试。
|
|
204
239
|
|
|
205
240
|
贡献流程见 [CONTRIBUTING.md](./CONTRIBUTING.md),规则维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md),本次工程审查和质量基线见 [工程质量审查报告](./docs/engineering-audit.zh.md)。
|
|
206
241
|
|
|
207
|
-
## 从 1.0.48 及更早版本迁移
|
|
208
|
-
|
|
209
|
-
- 现有 `export default [...fastChina]` 用法继续有效。
|
|
210
|
-
- 包现在明确为 ESM-only,不再暴露指向 ESM 文件的伪 CommonJS 条件。
|
|
211
|
-
- Vue 3 成为明确默认值;Vue 2 请使用 `createConfig({ vue: 2 })`。
|
|
212
|
-
- 默认不再强制项目改用 `lodash-unified`,组织定制规则仍保留在 rules 子路径中供显式使用。
|
|
213
|
-
- Prettier 不再运行于 ESLint 内部,请改用 Prettier CLI 或编辑器集成。
|
|
214
|
-
- Node.js 最低版本调整为 ESLint 10 的实际要求。
|
|
215
|
-
|
|
216
242
|
## 开源协议
|
|
217
243
|
|
|
218
244
|
[Apache-2.0](./LICENSE)
|