@fast-china/eslint-config 1.0.47 → 1.1.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/README.md +175 -66
- package/README.zh.md +175 -66
- package/dist/{typegen.d.ts → define-rules-CSwQ8C1q.d.ts} +5577 -2499
- package/dist/index.d.ts +110 -5
- package/dist/index.js +380 -571
- package/dist/index.js.map +1 -1
- package/dist/rules/index.d.ts +229 -0
- package/dist/rules/index.js +123 -233
- package/dist/rules/index.js.map +1 -1
- package/docs/engineering-audit.zh.md +105 -0
- package/docs/rules-risk.md +110 -0
- package/docs/rules-risk.zh.md +114 -0
- package/package.json +60 -46
package/README.md
CHANGED
|
@@ -1,109 +1,218 @@
|
|
|
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 Vue 2 and type-aware linting available explicitly.
|
|
14
|
+
- First-class JavaScript, TypeScript, Vue SFC, JSON, JSONC, JSON5, Markdown, RegExp, and import rules.
|
|
15
|
+
- A zero-configuration default array plus a small `createConfig()` factory for other project types.
|
|
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.
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Node.js `^20.19.0`, `^22.13.0`, or `>=24`
|
|
23
|
+
- ESLint `^10.0.0`
|
|
24
|
+
- TypeScript `>=5.3.0 <6.1.0`
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
npm install @fast-china/eslint-config --save-dev
|
|
26
|
+
These versions follow the runtime requirements of ESLint 10 and the included language plugins.
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
yarn add @fast-china/eslint-config --dev
|
|
28
|
+
## Installation
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
pnpm
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add -D eslint typescript @fast-china/eslint-config
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
Equivalent npm, Yarn, and Bun commands work as well.
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
## Quick start: Vue 3 + Vite
|
|
37
|
+
|
|
38
|
+
Create `eslint.config.mjs`:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { defineConfig } from "eslint/config";
|
|
38
42
|
|
|
39
|
-
```typescript
|
|
40
43
|
import fastChina from "@fast-china/eslint-config";
|
|
41
44
|
|
|
42
|
-
export default [...fastChina];
|
|
45
|
+
export default defineConfig([...fastChina]);
|
|
43
46
|
```
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
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 `createConfig()` to keep only what a project needs.
|
|
53
|
+
|
|
54
|
+
### Node.js + TypeScript
|
|
55
|
+
|
|
56
|
+
```js
|
|
47
57
|
import { defineConfig } from "eslint/config";
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
60
|
+
|
|
61
|
+
export default defineConfig(
|
|
62
|
+
createConfig({
|
|
63
|
+
environment: "node",
|
|
64
|
+
vue: false,
|
|
65
|
+
})
|
|
66
|
+
);
|
|
50
67
|
```
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
import fastChina from "@fast-china/eslint-config";
|
|
54
|
-
import tseslint from "typescript-eslint";
|
|
69
|
+
### JavaScript only
|
|
55
70
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
```
|
|
71
|
+
```js
|
|
72
|
+
import { defineConfig } from "eslint/config";
|
|
60
73
|
|
|
61
|
-
|
|
74
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
75
|
+
|
|
76
|
+
export default defineConfig(
|
|
77
|
+
createConfig({
|
|
78
|
+
environment: "node",
|
|
79
|
+
json: false,
|
|
80
|
+
markdown: false,
|
|
81
|
+
typescript: false,
|
|
82
|
+
vue: false,
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
```
|
|
62
86
|
|
|
63
|
-
|
|
87
|
+
### Type-aware TypeScript rules
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
```js
|
|
90
|
+
import { defineConfig } from "eslint/config";
|
|
66
91
|
|
|
67
|
-
|
|
92
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
68
93
|
|
|
94
|
+
export default defineConfig(
|
|
95
|
+
createConfig({
|
|
96
|
+
typescript: { typeChecked: true },
|
|
97
|
+
vue: { typeChecked: true, version: 3 },
|
|
98
|
+
})
|
|
99
|
+
);
|
|
69
100
|
```
|
|
70
|
-
Apache Open Source License
|
|
71
101
|
|
|
72
|
-
|
|
102
|
+
Type-aware linting uses the typescript-eslint project service. Project files must belong to a `tsconfig.json`.
|
|
73
103
|
|
|
74
|
-
|
|
75
|
-
This Agreement grants any individual or organization that obtains a copy of this software and its related documentation (hereinafter referred to as the "Software").
|
|
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.
|
|
104
|
+
## Options
|
|
80
105
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
106
|
+
| Option | Default | Purpose |
|
|
107
|
+
| ------------- | ----------- | ----------------------------------------------------------- |
|
|
108
|
+
| `environment` | `"browser"` | Use `"browser"`, `"node"`, or `"universal"` globals. |
|
|
109
|
+
| `gitignore` | `true` | Read ignore patterns from the project `.gitignore`. |
|
|
110
|
+
| `ignores` | `[]` | Add project-specific global ignore patterns. |
|
|
111
|
+
| `imports` | `true` | Enable import-x correctness and ordering rules. |
|
|
112
|
+
| `json` | `true` | Enable JSON/JSONC/JSON5 rules and package/tsconfig sorting. |
|
|
113
|
+
| `markdown` | `true` | Enable the official Markdown language rules. |
|
|
114
|
+
| `prettier` | `true` | Disable ESLint rules that conflict with Prettier. |
|
|
115
|
+
| `regexp` | `true` | Enable recommended RegExp rules. |
|
|
116
|
+
| `typescript` | `true` | Disable it or pass `{ typeChecked: true }`. |
|
|
117
|
+
| `vue` | `3` | Disable it, use `2`/`3`, or pass Vue options. |
|
|
85
118
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
The
|
|
89
|
-
|
|
119
|
+
## Exact rule types and completion
|
|
120
|
+
|
|
121
|
+
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.
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
// @ts-check
|
|
125
|
+
import { defineConfig } from "eslint/config";
|
|
126
|
+
|
|
127
|
+
import { createConfig, defineRules } from "@fast-china/eslint-config";
|
|
90
128
|
|
|
91
|
-
|
|
129
|
+
const projectRules = defineRules({
|
|
130
|
+
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
131
|
+
"import-x/order": ["error", { "newlines-between": "always" }],
|
|
132
|
+
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
133
|
+
});
|
|
92
134
|
|
|
135
|
+
export default defineConfig([
|
|
136
|
+
...createConfig(),
|
|
137
|
+
{
|
|
138
|
+
name: "project/rules",
|
|
139
|
+
rules: projectRules,
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
93
142
|
```
|
|
94
|
-
|
|
143
|
+
|
|
144
|
+
TypeScript configuration and tooling code can use the generated interface directly:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import type { RuleOptions } from "@fast-china/eslint-config";
|
|
148
|
+
|
|
149
|
+
const rules = {
|
|
150
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
151
|
+
} satisfies RuleOptions;
|
|
95
152
|
```
|
|
96
153
|
|
|
97
|
-
|
|
154
|
+
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.
|
|
155
|
+
|
|
156
|
+
## Rule risk and maintenance
|
|
157
|
+
|
|
158
|
+
The default includes a small set of high-impact rules. They can create a large first-run sorting diff, block legacy patterns, or require a review of import side effects, type-only imports, and public component events. Source comments mark these decisions as `[高影响]`, `[可自动修复]`, or `[安全关注]`.
|
|
159
|
+
|
|
160
|
+
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.
|
|
98
161
|
|
|
99
|
-
|
|
162
|
+
## Project overrides
|
|
100
163
|
|
|
101
|
-
|
|
102
|
-
<img src="https://contrib.rocks/image?repo=China-xiaoFang/Fast.ESLint.Config" />
|
|
103
|
-
</a>
|
|
164
|
+
Append project rules after the shared config so they take precedence:
|
|
104
165
|
|
|
105
|
-
|
|
166
|
+
```js
|
|
167
|
+
import { defineConfig } from "eslint/config";
|
|
106
168
|
|
|
169
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
170
|
+
|
|
171
|
+
export default defineConfig([
|
|
172
|
+
...createConfig({ vue: 3 }),
|
|
173
|
+
{
|
|
174
|
+
name: "project/overrides",
|
|
175
|
+
rules: {
|
|
176
|
+
"no-console": "off",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
107
180
|
```
|
|
108
|
-
|
|
181
|
+
|
|
182
|
+
Reusable named exports include `PresetJavascriptConfigs`, `PresetTypeScriptConfigs`, `PresetBasicConfigs`, `PresetJsonConfigs`, `PresetVueConfigs`, individual config groups, constants, and raw rule records from `@fast-china/eslint-config/rules`.
|
|
183
|
+
|
|
184
|
+
## Prettier
|
|
185
|
+
|
|
186
|
+
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:
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
pnpm add -D prettier
|
|
190
|
+
pnpm exec prettier --check .
|
|
109
191
|
```
|
|
192
|
+
|
|
193
|
+
Set `prettier: false` if another formatter or stylistic rule set should remain fully in control.
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
pnpm install
|
|
199
|
+
pnpm typegen
|
|
200
|
+
pnpm check
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
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
|
+
|
|
205
|
+
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
|
+
|
|
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
|
+
## License
|
|
217
|
+
|
|
218
|
+
[Apache-2.0](./LICENSE)
|
package/README.zh.md
CHANGED
|
@@ -1,109 +1,218 @@
|
|
|
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
|
+
## 特性
|
|
19
11
|
|
|
20
|
-
|
|
12
|
+
- 基于 ESLint 10 与原生 Flat Config,不再兼容旧式 `.eslintrc`。
|
|
13
|
+
- 默认针对 Vue 3 + TypeScript + Vite,同时可显式选择 Vue 2 或类型感知规则。
|
|
14
|
+
- 完整覆盖 JavaScript、TypeScript、Vue SFC、JSON、JSONC、JSON5、Markdown、正则表达式与导入规则。
|
|
15
|
+
- 保留零配置的默认数组,并提供轻量的 `createConfig()` 工厂适配其他类型项目。
|
|
16
|
+
- 根据 ESLint 与内置插件的规则 schema 生成精确类型,提供规则名和规则选项自动补全。
|
|
17
|
+
- 插件与解析器均由本包直接声明依赖,使用者不需要手工拼装插件依赖树。
|
|
18
|
+
- Prettier 只负责格式化:默认配置仅关闭冲突规则,不在 ESLint 内重复运行 Prettier。
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
# 选择一个你喜欢的包管理器
|
|
20
|
+
## 环境要求
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
- Node.js `^20.19.0`、`^22.13.0` 或 `>=24`
|
|
23
|
+
- ESLint `^10.0.0`
|
|
24
|
+
- TypeScript `>=5.3.0 <6.1.0`
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
这些版本范围与 ESLint 10 及内置语言插件的运行要求保持一致。
|
|
27
|
+
|
|
28
|
+
## 安装
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
pnpm
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add -D eslint typescript @fast-china/eslint-config
|
|
33
32
|
```
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
也可以使用 npm、Yarn 或 Bun 的等价命令。
|
|
35
|
+
|
|
36
|
+
## 快速开始:Vue 3 + Vite
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
创建 `eslint.config.mjs`:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { defineConfig } from "eslint/config";
|
|
38
42
|
|
|
39
|
-
```typescript
|
|
40
43
|
import fastChina from "@fast-china/eslint-config";
|
|
41
44
|
|
|
42
|
-
export default [...fastChina];
|
|
45
|
+
export default defineConfig([...fastChina]);
|
|
43
46
|
```
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
默认配置会启用 Vue 3、TypeScript、JavaScript、JSON 各方言、Markdown、导入排序、正则检查、`.gitignore` 与浏览器全局变量;常见配置文件、脚本、测试和 CLI 文件会额外获得 Node.js 全局变量。
|
|
49
|
+
|
|
50
|
+
## 适配其他项目
|
|
51
|
+
|
|
52
|
+
通过 `createConfig()` 只保留项目真正需要的能力。
|
|
53
|
+
|
|
54
|
+
### Node.js + TypeScript
|
|
55
|
+
|
|
56
|
+
```js
|
|
47
57
|
import { defineConfig } from "eslint/config";
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
60
|
+
|
|
61
|
+
export default defineConfig(
|
|
62
|
+
createConfig({
|
|
63
|
+
environment: "node",
|
|
64
|
+
vue: false,
|
|
65
|
+
})
|
|
66
|
+
);
|
|
50
67
|
```
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
import fastChina from "@fast-china/eslint-config";
|
|
54
|
-
import tseslint from "typescript-eslint";
|
|
69
|
+
### 纯 JavaScript
|
|
55
70
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
```
|
|
71
|
+
```js
|
|
72
|
+
import { defineConfig } from "eslint/config";
|
|
60
73
|
|
|
61
|
-
|
|
74
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
75
|
+
|
|
76
|
+
export default defineConfig(
|
|
77
|
+
createConfig({
|
|
78
|
+
environment: "node",
|
|
79
|
+
json: false,
|
|
80
|
+
markdown: false,
|
|
81
|
+
typescript: false,
|
|
82
|
+
vue: false,
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
```
|
|
62
86
|
|
|
63
|
-
|
|
87
|
+
### 启用 TypeScript 类型感知规则
|
|
64
88
|
|
|
65
|
-
|
|
89
|
+
```js
|
|
90
|
+
import { defineConfig } from "eslint/config";
|
|
66
91
|
|
|
67
|
-
|
|
92
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
68
93
|
|
|
94
|
+
export default defineConfig(
|
|
95
|
+
createConfig({
|
|
96
|
+
typescript: { typeChecked: true },
|
|
97
|
+
vue: { typeChecked: true, version: 3 },
|
|
98
|
+
})
|
|
99
|
+
);
|
|
69
100
|
```
|
|
70
|
-
Apache开源许可证
|
|
71
101
|
|
|
72
|
-
|
|
102
|
+
类型感知模式使用 typescript-eslint project service,被检查的文件必须属于某个 `tsconfig.json`。
|
|
73
103
|
|
|
74
|
-
|
|
75
|
-
本协议授予任何获得本软件及其相关文档(以下简称“软件”)副本的个人或组织。
|
|
76
|
-
在遵守本协议条款的前提下,享有使用、复制、修改、合并、发布、分发、再许可、销售软件副本的权利:
|
|
77
|
-
1.所有软件副本或主要部分必须保留本版权声明及本许可协议。
|
|
78
|
-
2.软件的使用、复制、修改或分发不得违反适用法律或侵犯他人合法权益。
|
|
79
|
-
3.修改或衍生作品须明确标注原作者及原软件出处。
|
|
104
|
+
## 配置选项
|
|
80
105
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
106
|
+
| 选项 | 默认值 | 作用 |
|
|
107
|
+
| ------------- | ----------- | ------------------------------------------------------ |
|
|
108
|
+
| `environment` | `"browser"` | 可选 `"browser"`、`"node"` 或 `"universal"` 全局变量。 |
|
|
109
|
+
| `gitignore` | `true` | 读取项目根目录的 `.gitignore`。 |
|
|
110
|
+
| `ignores` | `[]` | 增加项目自己的全局忽略模式。 |
|
|
111
|
+
| `imports` | `true` | 启用 import-x 正确性与排序规则。 |
|
|
112
|
+
| `json` | `true` | 启用 JSON/JSONC/JSON5 及 package/tsconfig 排序。 |
|
|
113
|
+
| `markdown` | `true` | 启用官方 Markdown 语言规则。 |
|
|
114
|
+
| `prettier` | `true` | 关闭与 Prettier 冲突的 ESLint 规则。 |
|
|
115
|
+
| `regexp` | `true` | 启用推荐的正则表达式规则。 |
|
|
116
|
+
| `typescript` | `true` | 可关闭,或传入 `{ typeChecked: true }`。 |
|
|
117
|
+
| `vue` | `3` | 可关闭、传入 `2`/`3`,或传入 Vue 选项对象。 |
|
|
85
118
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
119
|
+
## 精确规则类型与自动补全
|
|
120
|
+
|
|
121
|
+
本包根据 ESLint 核心规则和所有随包插件公开的 JSON Schema 生成 `RuleOptions`,并提供不会改变运行时对象的 `defineRules()`。在输入规则名、严重级别或选项时,TypeScript 与支持类型分析的编辑器会给出补全;拼错规则名或填写无效选项时会立即报错。
|
|
90
122
|
|
|
91
|
-
|
|
123
|
+
```js
|
|
124
|
+
// @ts-check
|
|
125
|
+
import { defineConfig } from "eslint/config";
|
|
126
|
+
|
|
127
|
+
import { createConfig, defineRules } from "@fast-china/eslint-config";
|
|
92
128
|
|
|
129
|
+
const projectRules = defineRules({
|
|
130
|
+
"@typescript-eslint/no-unused-vars": ["error", { args: "after-used" }],
|
|
131
|
+
"import-x/order": ["error", { "newlines-between": "always" }],
|
|
132
|
+
"vue/attributes-order": ["error", { order: ["DEFINITION", "EVENTS", "CONTENT"] }],
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export default defineConfig([
|
|
136
|
+
...createConfig(),
|
|
137
|
+
{
|
|
138
|
+
name: "project/rules",
|
|
139
|
+
rules: projectRules,
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
93
142
|
```
|
|
94
|
-
|
|
143
|
+
|
|
144
|
+
在 TypeScript 配置或工具代码中,也可以直接使用:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import type { RuleOptions } from "@fast-china/eslint-config";
|
|
148
|
+
|
|
149
|
+
const rules = {
|
|
150
|
+
"no-console": ["warn", { allow: ["warn", "error"] }],
|
|
151
|
+
} satisfies RuleOptions;
|
|
95
152
|
```
|
|
96
153
|
|
|
97
|
-
|
|
154
|
+
精确类型覆盖 ESLint 核心规则和本包附带的插件规则;项目自行安装的额外插件不在该类型集合内。类型精度取决于对应规则公开的 schema。
|
|
155
|
+
|
|
156
|
+
## 规则风险与维护
|
|
157
|
+
|
|
158
|
+
默认配置包含少量高影响规则:它们可能在首次启用时产生大面积排序差异、阻断旧项目写法,或要求复核 import 副作用、类型导入和组件公共事件。源码使用 `[高影响]`、`[可自动修复]` 与 `[安全关注]` 标记这类规则。
|
|
159
|
+
|
|
160
|
+
完整的默认预置来源、高影响规则清单、关闭示例和维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md)。运行 `eslint --fix` 前建议先只检查,在独立提交中应用修复,并审查 import、`package.json`、组件事件和构建产物。
|
|
161
|
+
|
|
162
|
+
## 覆盖项目规则
|
|
163
|
+
|
|
164
|
+
将项目规则放在共享配置之后即可覆盖:
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
import { defineConfig } from "eslint/config";
|
|
168
|
+
|
|
169
|
+
import { createConfig } from "@fast-china/eslint-config";
|
|
170
|
+
|
|
171
|
+
export default defineConfig([
|
|
172
|
+
...createConfig({ vue: 3 }),
|
|
173
|
+
{
|
|
174
|
+
name: "project/overrides",
|
|
175
|
+
rules: {
|
|
176
|
+
"no-console": "off",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
180
|
+
```
|
|
98
181
|
|
|
99
|
-
|
|
182
|
+
可复用导出包括 `PresetJavascriptConfigs`、`PresetTypeScriptConfigs`、`PresetBasicConfigs`、`PresetJsonConfigs`、`PresetVueConfigs`、各独立配置组和常量;原始规则记录可从 `@fast-china/eslint-config/rules` 导入。
|
|
100
183
|
|
|
101
|
-
|
|
102
|
-
<img src="https://contrib.rocks/image?repo=China-xiaoFang/Fast.ESLint.Config" />
|
|
103
|
-
</a>
|
|
184
|
+
## Prettier
|
|
104
185
|
|
|
105
|
-
|
|
186
|
+
Prettier 不再是 peer dependency,也不会作为 ESLint 规则运行。项目需要格式化时单独安装并执行:
|
|
106
187
|
|
|
188
|
+
```sh
|
|
189
|
+
pnpm add -D prettier
|
|
190
|
+
pnpm exec prettier --check .
|
|
107
191
|
```
|
|
108
|
-
|
|
192
|
+
|
|
193
|
+
如果使用其他格式化工具,或希望保留完整的样式类 ESLint 规则,请设置 `prettier: false`。
|
|
194
|
+
|
|
195
|
+
## 开发与贡献
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
pnpm install
|
|
199
|
+
pnpm typegen
|
|
200
|
+
pnpm check
|
|
109
201
|
```
|
|
202
|
+
|
|
203
|
+
升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`;不要手工编辑生成文件。`pnpm check` 会验证生成类型没有漂移,然后依次构建、类型检查、检查所有支持的文件类型、验证格式,并针对构建后的真实包运行运行时和消费者类型测试。
|
|
204
|
+
|
|
205
|
+
贡献流程见 [CONTRIBUTING.md](./CONTRIBUTING.md),规则维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md),本次工程审查和质量基线见 [工程质量审查报告](./docs/engineering-audit.zh.md)。
|
|
206
|
+
|
|
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
|
+
## 开源协议
|
|
217
|
+
|
|
218
|
+
[Apache-2.0](./LICENSE)
|