@fast-china/eslint-config 1.0.48 → 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 +196 -61
- package/README.zh.md +196 -61
- package/dist/{typegen.d.ts → define-rules-CSwQ8C1q.d.ts} +5577 -2499
- package/dist/index.d.ts +126 -147
- package/dist/index.js +407 -575
- package/dist/index.js.map +1 -1
- package/dist/rules/index.d.ts +211 -24
- package/dist/rules/index.js +171 -267
- package/dist/rules/index.js.map +1 -1
- package/docs/engineering-audit.zh.md +96 -0
- package/docs/rules-risk.md +99 -0
- package/docs/rules-risk.zh.md +103 -0
- package/package.json +61 -46
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
|
@@ -1,109 +1,244 @@
|
|
|
1
|
-
[
|
|
1
|
+
[中文](./README.zh.md) | **English**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @fast-china/eslint-config
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
<code>Fast</code> platform An rule library built based on <code>ESLint</code>.
|
|
7
|
-
</p>
|
|
5
|
+
A practical, typed ESLint Flat Config for Vue 3, Vite, TypeScript, and JavaScript projects.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<img src="https://img.shields.io/npm/v/@fast-china/eslint-config?color=orange&label=" alt="version" />
|
|
12
|
-
</a>
|
|
13
|
-
<a href="https://gitee.com/FastDotnet/Fast.ESLint.Config/blob/master/LICENSE">
|
|
14
|
-
<img src="https://img.shields.io/npm/l/@fast-china/eslint-config" alt="license" />
|
|
15
|
-
</a>
|
|
16
|
-
</p>
|
|
7
|
+
[](https://www.npmjs.com/package/@fast-china/eslint-config)
|
|
8
|
+
[](./LICENSE)
|
|
17
9
|
|
|
18
|
-
##
|
|
10
|
+
## Highlights
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
- Built for ESLint 10 and the native Flat Config format.
|
|
13
|
+
- Vue 3 + TypeScript + Vite defaults, with type-aware linting and language integrations controlled explicitly.
|
|
14
|
+
- First-class JavaScript, TypeScript, Vue SFC, JSON, JSONC, JSON5, Markdown, RegExp, and import rules.
|
|
15
|
+
- One focused `fastConfig()` factory with a compact public API and no project-file reads at module import time.
|
|
16
|
+
- Schema-generated rule types provide exact rule-name and rule-option completion.
|
|
17
|
+
- Plugins and parsers are regular package dependencies, so consumers do not need to assemble the plugin graph.
|
|
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.
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
- Node.js `^22.13.0` or `^24.0.0`
|
|
25
|
+
- ESLint `^10.0.0`
|
|
26
|
+
- TypeScript `>=5.3.0 <6.1.0`
|
|
27
|
+
|
|
28
|
+
These versions follow the runtime requirements of ESLint 10 and the included language plugins.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
21
31
|
|
|
22
32
|
```sh
|
|
23
|
-
|
|
33
|
+
pnpm add -D eslint typescript @fast-china/eslint-config
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Equivalent npm, Yarn, and Bun commands work as well.
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
npm install @fast-china/eslint-config --save-dev
|
|
38
|
+
## Quick start: Vue 3 + Vite
|
|
27
39
|
|
|
28
|
-
|
|
29
|
-
yarn add @fast-china/eslint-config --dev
|
|
40
|
+
Create `eslint.config.mjs`:
|
|
30
41
|
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
```js
|
|
43
|
+
import fastChina from "@fast-china/eslint-config";
|
|
44
|
+
|
|
45
|
+
export default fastChina();
|
|
33
46
|
```
|
|
34
47
|
|
|
35
|
-
|
|
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
|
+
|
|
50
|
+
## Other project types
|
|
51
|
+
|
|
52
|
+
Use the default `fastConfig()` factory to keep only what a project needs.
|
|
36
53
|
|
|
37
|
-
|
|
54
|
+
### Node.js + TypeScript
|
|
38
55
|
|
|
39
|
-
```
|
|
56
|
+
```js
|
|
40
57
|
import fastChina from "@fast-china/eslint-config";
|
|
41
58
|
|
|
42
|
-
export default
|
|
59
|
+
export default fastChina({
|
|
60
|
+
environment: "node",
|
|
61
|
+
vue: false,
|
|
62
|
+
});
|
|
43
63
|
```
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
### JavaScript only
|
|
66
|
+
|
|
67
|
+
```js
|
|
46
68
|
import fastChina from "@fast-china/eslint-config";
|
|
47
|
-
import { defineConfig } from "eslint/config";
|
|
48
69
|
|
|
49
|
-
export default
|
|
70
|
+
export default fastChina({
|
|
71
|
+
environment: "node",
|
|
72
|
+
json: false,
|
|
73
|
+
markdown: false,
|
|
74
|
+
typescript: false,
|
|
75
|
+
vue: false,
|
|
76
|
+
});
|
|
50
77
|
```
|
|
51
78
|
|
|
52
|
-
|
|
79
|
+
### Type-aware TypeScript rules
|
|
80
|
+
|
|
81
|
+
```js
|
|
53
82
|
import fastChina from "@fast-china/eslint-config";
|
|
54
|
-
import tseslint from "typescript-eslint";
|
|
55
83
|
|
|
56
|
-
export default
|
|
57
|
-
|
|
84
|
+
export default fastChina({
|
|
85
|
+
typescript: {
|
|
86
|
+
tsconfigRootDir: import.meta.dirname,
|
|
87
|
+
typeChecked: true,
|
|
88
|
+
},
|
|
58
89
|
});
|
|
59
90
|
```
|
|
60
91
|
|
|
61
|
-
|
|
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.
|
|
93
|
+
|
|
94
|
+
## Options
|
|
95
|
+
|
|
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
|
|
62
116
|
|
|
63
|
-
|
|
117
|
+
The default, `lodash: false`, leaves the dependency choice to the project. Select one policy when every static import should use the same package:
|
|
64
118
|
|
|
65
|
-
|
|
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.
|
|
66
121
|
|
|
67
|
-
|
|
122
|
+
Choose `lodash-unified`:
|
|
68
123
|
|
|
124
|
+
```sh
|
|
125
|
+
pnpm add lodash-unified
|
|
69
126
|
```
|
|
70
|
-
Apache Open Source License
|
|
71
127
|
|
|
72
|
-
|
|
128
|
+
```js
|
|
129
|
+
import fastChina from "@fast-china/eslint-config";
|
|
130
|
+
import { cloneDeep, debounce } from "lodash-unified";
|
|
73
131
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Subject to the terms of this Agreement, you have the right to use, copy, modify, merge, publish, distribute, sublicense, and sell copies of the Software:
|
|
77
|
-
1.All copies or major parts of the Software must retain this Copyright Notice and this License Agreement.
|
|
78
|
-
2.The use, copying, modification, or distribution of the Software shall not violate applicable laws or infringe upon the legitimate rights and interests of others.
|
|
79
|
-
3.Modified or derivative works must clearly indicate the original author and the source of the original Software.
|
|
132
|
+
export default fastChina({ lodash: "lodash-unified" });
|
|
133
|
+
```
|
|
80
134
|
|
|
81
|
-
|
|
82
|
-
- This Software is provided "as is" without any express or implied warranty of any kind, including but not limited to the warranty of merchantability, fitness for purpose, and non-infringement.
|
|
83
|
-
- In no event shall the author or copyright holder be liable for any direct or indirect loss caused by the use or inability to use this Software.
|
|
84
|
-
- Including but not limited to data loss, business interruption, etc.
|
|
135
|
+
Choose standard `lodash`:
|
|
85
136
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
137
|
+
```sh
|
|
138
|
+
pnpm add lodash
|
|
139
|
+
pnpm add -D @types/lodash
|
|
89
140
|
```
|
|
90
141
|
|
|
91
|
-
|
|
142
|
+
```js
|
|
143
|
+
import fastChina from "@fast-china/eslint-config";
|
|
144
|
+
import debounce from "lodash/debounce";
|
|
92
145
|
|
|
146
|
+
export default fastChina({ lodash: "lodash" });
|
|
93
147
|
```
|
|
94
|
-
|
|
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.
|
|
152
|
+
|
|
153
|
+
## Exact rule types and completion
|
|
154
|
+
|
|
155
|
+
The package generates `RuleOptions` from the JSON Schemas published by ESLint core and every bundled plugin. The identity helper `defineRules()` adds editor completion for rule names, severities, and options while rejecting misspelled rules and invalid options at type-checking time.
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// @ts-check
|
|
159
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
160
|
+
|
|
161
|
+
const projectRules = defineRules({
|
|
162
|
+
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
163
|
+
"import-x/order": ["error", { "newlines-between": "always" }],
|
|
164
|
+
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export default fastChina(
|
|
168
|
+
{ rules: projectRules },
|
|
169
|
+
{
|
|
170
|
+
files: ["**/*.generated.ts"],
|
|
171
|
+
name: "project/generated",
|
|
172
|
+
rules: defineRules({ "@typescript-eslint/no-unused-vars": "off" }),
|
|
173
|
+
}
|
|
174
|
+
);
|
|
95
175
|
```
|
|
96
176
|
|
|
97
|
-
|
|
177
|
+
TypeScript configuration and tooling code can use the generated interface directly:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import type { RuleOptions } from "@fast-china/eslint-config";
|
|
181
|
+
|
|
182
|
+
const rules = {
|
|
183
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
184
|
+
} satisfies RuleOptions;
|
|
185
|
+
```
|
|
98
186
|
|
|
99
|
-
|
|
187
|
+
The generated set covers ESLint core and plugins bundled by this package. Rules from additional project-installed plugins are outside this type set, and precision ultimately depends on the schema published by each rule.
|
|
100
188
|
|
|
101
|
-
|
|
102
|
-
<img src="https://contrib.rocks/image?repo=China-xiaoFang/Fast.ESLint.Config" />
|
|
103
|
-
</a>
|
|
189
|
+
## Rule risk and maintenance
|
|
104
190
|
|
|
105
|
-
|
|
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 `[安全关注]`.
|
|
106
192
|
|
|
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.
|
|
194
|
+
|
|
195
|
+
## Project overrides
|
|
196
|
+
|
|
197
|
+
Put common overrides in `rules`, and pass file-scoped overrides as later arguments. Later configurations take precedence:
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
201
|
+
|
|
202
|
+
export default fastChina(
|
|
203
|
+
{
|
|
204
|
+
rules: {
|
|
205
|
+
"no-console": "warn",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
files: ["**/{scripts,tests}/**/*.{js,ts}"],
|
|
210
|
+
name: "project/node-files",
|
|
211
|
+
rules: defineRules({ "no-console": "off" }),
|
|
212
|
+
}
|
|
213
|
+
);
|
|
107
214
|
```
|
|
108
|
-
|
|
215
|
+
|
|
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`.
|
|
217
|
+
|
|
218
|
+
## Prettier
|
|
219
|
+
|
|
220
|
+
Prettier is intentionally not a peer dependency and is not executed as an ESLint rule. Install and run it separately if the project uses it:
|
|
221
|
+
|
|
222
|
+
```sh
|
|
223
|
+
pnpm add -D prettier
|
|
224
|
+
pnpm exec prettier --check .
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Set `prettier: false` if another formatter or stylistic rule set should remain fully in control.
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
pnpm install
|
|
233
|
+
pnpm typegen
|
|
234
|
+
pnpm check
|
|
235
|
+
pnpm pack --dry-run
|
|
109
236
|
```
|
|
237
|
+
|
|
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.
|
|
239
|
+
|
|
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.
|
|
241
|
+
|
|
242
|
+
## License
|
|
243
|
+
|
|
244
|
+
[Apache-2.0](./LICENSE)
|
package/README.zh.md
CHANGED
|
@@ -1,109 +1,244 @@
|
|
|
1
|
-
|
|
1
|
+
**中文** | [English](./README.md)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @fast-china/eslint-config
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
<code>Fast</code> 平台下基于 <code>ESLint</code> 构建的规则库。
|
|
7
|
-
</p>
|
|
5
|
+
面向 Vue 3、Vite、TypeScript 与 JavaScript 项目的实用型 ESLint Flat Config 规则库。
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<img src="https://img.shields.io/npm/v/@fast-china/eslint-config?color=orange&label=" alt="version" />
|
|
12
|
-
</a>
|
|
13
|
-
<a href="https://gitee.com/FastDotnet/Fast.ESLint.Config/blob/master/LICENSE">
|
|
14
|
-
<img src="https://img.shields.io/npm/l/@fast-china/eslint-config" alt="license" />
|
|
15
|
-
</a>
|
|
16
|
-
</p>
|
|
7
|
+
[](https://www.npmjs.com/package/@fast-china/eslint-config)
|
|
8
|
+
[](./LICENSE)
|
|
17
9
|
|
|
18
|
-
##
|
|
10
|
+
## 特性
|
|
11
|
+
|
|
12
|
+
- 基于 ESLint 10,仅提供原生 Flat Config。
|
|
13
|
+
- 默认针对 Vue 3 + TypeScript + Vite,可显式开启类型感知规则或关闭不需要的语言能力。
|
|
14
|
+
- 完整覆盖 JavaScript、TypeScript、Vue SFC、JSON、JSONC、JSON5、Markdown、正则表达式与导入规则。
|
|
15
|
+
- 默认导出单一 `fastConfig()` 工厂,公共 API 清晰,并且不会在导入模块时读取项目文件。
|
|
16
|
+
- 根据 ESLint 与内置插件的规则 schema 生成精确类型,提供规则名和规则选项自动补全。
|
|
17
|
+
- 插件与解析器均由本包直接声明依赖,使用者不需要手工拼装插件依赖树。
|
|
18
|
+
- Prettier 只负责格式化:默认配置仅关闭冲突规则,不在 ESLint 内重复运行 Prettier。
|
|
19
|
+
- `package.json` 与 `tsconfig.json` 排序为显式 opt-in,避免安装后首次修复产生非预期大 diff。
|
|
20
|
+
- 可选统一使用 `lodash` 或 `lodash-unified`,避免同一项目混用多个 Lodash 入口。
|
|
21
|
+
|
|
22
|
+
## 环境要求
|
|
23
|
+
|
|
24
|
+
- Node.js `^22.13.0` 或 `^24.0.0`
|
|
25
|
+
- ESLint `^10.0.0`
|
|
26
|
+
- TypeScript `>=5.3.0 <6.1.0`
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
这些版本范围与 ESLint 10 及内置语言插件的运行要求保持一致。
|
|
29
|
+
|
|
30
|
+
## 安装
|
|
21
31
|
|
|
22
32
|
```sh
|
|
23
|
-
|
|
33
|
+
pnpm add -D eslint typescript @fast-china/eslint-config
|
|
34
|
+
```
|
|
24
35
|
|
|
25
|
-
|
|
26
|
-
npm install @fast-china/eslint-config --save-dev
|
|
36
|
+
也可以使用 npm、Yarn 或 Bun 的等价命令。
|
|
27
37
|
|
|
28
|
-
|
|
29
|
-
yarn add @fast-china/eslint-config --dev
|
|
38
|
+
## 快速开始:Vue 3 + Vite
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
创建 `eslint.config.mjs`:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import fastChina from "@fast-china/eslint-config";
|
|
44
|
+
|
|
45
|
+
export default fastChina();
|
|
33
46
|
```
|
|
34
47
|
|
|
35
|
-
|
|
48
|
+
默认配置会启用 Vue 3、TypeScript、JavaScript、JSON 各方言、Markdown、导入排序、正则检查、`.gitignore` 与浏览器全局变量;常见配置文件、脚本、测试和 CLI 文件会额外获得 Node.js 全局变量。
|
|
49
|
+
|
|
50
|
+
## 适配其他项目
|
|
36
51
|
|
|
37
|
-
|
|
52
|
+
通过默认导出的 `fastConfig()` 只保留项目真正需要的能力。
|
|
38
53
|
|
|
39
|
-
|
|
54
|
+
### Node.js + TypeScript
|
|
55
|
+
|
|
56
|
+
```js
|
|
40
57
|
import fastChina from "@fast-china/eslint-config";
|
|
41
58
|
|
|
42
|
-
export default
|
|
59
|
+
export default fastChina({
|
|
60
|
+
environment: "node",
|
|
61
|
+
vue: false,
|
|
62
|
+
});
|
|
43
63
|
```
|
|
44
64
|
|
|
45
|
-
|
|
65
|
+
### 纯 JavaScript
|
|
66
|
+
|
|
67
|
+
```js
|
|
46
68
|
import fastChina from "@fast-china/eslint-config";
|
|
47
|
-
import { defineConfig } from "eslint/config";
|
|
48
69
|
|
|
49
|
-
export default
|
|
70
|
+
export default fastChina({
|
|
71
|
+
environment: "node",
|
|
72
|
+
json: false,
|
|
73
|
+
markdown: false,
|
|
74
|
+
typescript: false,
|
|
75
|
+
vue: false,
|
|
76
|
+
});
|
|
50
77
|
```
|
|
51
78
|
|
|
52
|
-
|
|
79
|
+
### 启用 TypeScript 类型感知规则
|
|
80
|
+
|
|
81
|
+
```js
|
|
53
82
|
import fastChina from "@fast-china/eslint-config";
|
|
54
|
-
import tseslint from "typescript-eslint";
|
|
55
83
|
|
|
56
|
-
export default
|
|
57
|
-
|
|
84
|
+
export default fastChina({
|
|
85
|
+
typescript: {
|
|
86
|
+
tsconfigRootDir: import.meta.dirname,
|
|
87
|
+
typeChecked: true,
|
|
88
|
+
},
|
|
58
89
|
});
|
|
59
90
|
```
|
|
60
91
|
|
|
61
|
-
|
|
92
|
+
类型感知模式使用 typescript-eslint Project Service,被检查的文件必须属于某个 `tsconfig.json`。普通项目通常可省略 `tsconfigRootDir`;复杂 monorepo 建议显式传入配置文件所在目录。
|
|
93
|
+
|
|
94
|
+
## 配置选项
|
|
95
|
+
|
|
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 单文件组件支持。 |
|
|
62
114
|
|
|
63
|
-
|
|
115
|
+
## Lodash 导入策略
|
|
64
116
|
|
|
65
|
-
|
|
117
|
+
默认值 `lodash: false` 不限制项目选择。需要统一依赖入口时,可选择以下任一策略:
|
|
66
118
|
|
|
67
|
-
|
|
119
|
+
- `lodash: "lodash-unified"`:禁止从 `lodash`、`lodash-es` 及其子路径静态导入或重新导出。
|
|
120
|
+
- `lodash: "lodash"`:禁止从 `lodash-es`、`lodash-unified` 及其子路径静态导入或重新导出;允许 `lodash` 根入口和 `lodash/*` 按方法导入。
|
|
68
121
|
|
|
122
|
+
选择 `lodash-unified`:
|
|
123
|
+
|
|
124
|
+
```sh
|
|
125
|
+
pnpm add lodash-unified
|
|
69
126
|
```
|
|
70
|
-
Apache开源许可证
|
|
71
127
|
|
|
72
|
-
|
|
128
|
+
```js
|
|
129
|
+
import fastChina from "@fast-china/eslint-config";
|
|
130
|
+
import { cloneDeep, debounce } from "lodash-unified";
|
|
73
131
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
在遵守本协议条款的前提下,享有使用、复制、修改、合并、发布、分发、再许可、销售软件副本的权利:
|
|
77
|
-
1.所有软件副本或主要部分必须保留本版权声明及本许可协议。
|
|
78
|
-
2.软件的使用、复制、修改或分发不得违反适用法律或侵犯他人合法权益。
|
|
79
|
-
3.修改或衍生作品须明确标注原作者及原软件出处。
|
|
132
|
+
export default fastChina({ lodash: "lodash-unified" });
|
|
133
|
+
```
|
|
80
134
|
|
|
81
|
-
|
|
82
|
-
- 本软件按“原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、适用性和非侵权的保证。
|
|
83
|
-
- 在任何情况下,作者或版权持有人均不对因使用或无法使用本软件导致的任何直接或间接损失的责任。
|
|
84
|
-
- 包括但不限于数据丢失、业务中断等情况。
|
|
135
|
+
选择标准 `lodash`:
|
|
85
136
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
137
|
+
```sh
|
|
138
|
+
pnpm add lodash
|
|
139
|
+
pnpm add -D @types/lodash
|
|
89
140
|
```
|
|
90
141
|
|
|
91
|
-
|
|
142
|
+
```js
|
|
143
|
+
import fastChina from "@fast-china/eslint-config";
|
|
144
|
+
import debounce from "lodash/debounce";
|
|
92
145
|
|
|
146
|
+
export default fastChina({ lodash: "lodash" });
|
|
93
147
|
```
|
|
94
|
-
|
|
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`,统一维护一份完整规则。
|
|
152
|
+
|
|
153
|
+
## 精确规则类型与自动补全
|
|
154
|
+
|
|
155
|
+
本包根据 ESLint 核心规则和所有随包插件公开的 JSON Schema 生成 `RuleOptions`,并提供不会改变运行时对象的 `defineRules()`。在输入规则名、严重级别或选项时,TypeScript 与支持类型分析的编辑器会给出补全;拼错规则名或填写无效选项时会立即报错。
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
// @ts-check
|
|
159
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
160
|
+
|
|
161
|
+
const projectRules = defineRules({
|
|
162
|
+
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
163
|
+
"import-x/order": ["error", { "newlines-between": "always" }],
|
|
164
|
+
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
export default fastChina(
|
|
168
|
+
{ rules: projectRules },
|
|
169
|
+
{
|
|
170
|
+
files: ["**/*.generated.ts"],
|
|
171
|
+
name: "project/generated",
|
|
172
|
+
rules: defineRules({ "@typescript-eslint/no-unused-vars": "off" }),
|
|
173
|
+
}
|
|
174
|
+
);
|
|
95
175
|
```
|
|
96
176
|
|
|
97
|
-
|
|
177
|
+
在 TypeScript 配置或工具代码中,也可以直接使用:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import type { RuleOptions } from "@fast-china/eslint-config";
|
|
181
|
+
|
|
182
|
+
const rules = {
|
|
183
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
184
|
+
} satisfies RuleOptions;
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
精确类型覆盖 ESLint 核心规则和本包附带的插件规则;项目自行安装的额外插件不在该类型集合内。类型精度取决于对应规则公开的 schema。
|
|
188
|
+
|
|
189
|
+
## 规则风险与维护
|
|
190
|
+
|
|
191
|
+
默认配置包含少量高影响规则:它们可能阻断特定写法,或要求复核 import 副作用、类型导入和组件公共事件。清单排序同样属于高影响能力,但默认关闭。源码使用 `[高影响]`、`[可自动修复]` 与 `[安全关注]` 标记这类规则。
|
|
192
|
+
|
|
193
|
+
完整的默认预置来源、高影响规则清单、关闭示例和维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md)。运行 `eslint --fix` 前建议先只检查,在独立提交中应用修复,并审查 import、`package.json`、组件事件和构建产物。
|
|
194
|
+
|
|
195
|
+
## 覆盖项目规则
|
|
98
196
|
|
|
99
|
-
|
|
197
|
+
最常用的全局覆盖可以直接放入 `rules`;按文件覆盖作为后续参数传入,后面的配置优先级更高:
|
|
100
198
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
</a>
|
|
199
|
+
```js
|
|
200
|
+
import fastChina, { defineRules } from "@fast-china/eslint-config";
|
|
104
201
|
|
|
105
|
-
|
|
202
|
+
export default fastChina(
|
|
203
|
+
{
|
|
204
|
+
rules: {
|
|
205
|
+
"no-console": "warn",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
files: ["**/{scripts,tests}/**/*.{js,ts}"],
|
|
210
|
+
name: "project/node-files",
|
|
211
|
+
rules: defineRules({ "no-console": "off" }),
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
根入口只公开 `fastConfig`、`defaultConfigOptions`、`defineRules` 及相关类型。高级使用者可以从 `@fast-china/eslint-config/rules` 导入有完整注释的原始规则记录。
|
|
217
|
+
|
|
218
|
+
## Prettier
|
|
219
|
+
|
|
220
|
+
Prettier 不再是 peer dependency,也不会作为 ESLint 规则运行。项目需要格式化时单独安装并执行:
|
|
106
221
|
|
|
222
|
+
```sh
|
|
223
|
+
pnpm add -D prettier
|
|
224
|
+
pnpm exec prettier --check .
|
|
107
225
|
```
|
|
108
|
-
|
|
226
|
+
|
|
227
|
+
如果使用其他格式化工具,或希望保留完整的样式类 ESLint 规则,请设置 `prettier: false`。
|
|
228
|
+
|
|
229
|
+
## 开发与贡献
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
pnpm install
|
|
233
|
+
pnpm typegen
|
|
234
|
+
pnpm check
|
|
235
|
+
pnpm pack --dry-run
|
|
109
236
|
```
|
|
237
|
+
|
|
238
|
+
升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`;不要手工编辑生成文件。`pnpm check` 会验证生成类型没有漂移,然后依次构建、类型检查、检查所有支持的文件类型、验证格式,并针对构建后的真实包运行运行时和消费者类型测试。
|
|
239
|
+
|
|
240
|
+
贡献流程见 [CONTRIBUTING.md](./CONTRIBUTING.md),规则维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md),本次工程审查和质量基线见 [工程质量审查报告](./docs/engineering-audit.zh.md)。
|
|
241
|
+
|
|
242
|
+
## 开源协议
|
|
243
|
+
|
|
244
|
+
[Apache-2.0](./LICENSE)
|