@fast-china/eslint-config 2.1.7 → 2.1.9
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 +31 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +103 -144
- package/README.zh.md +101 -144
- 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 +61 -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 +2052 -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/README.zh.md
CHANGED
|
@@ -8,20 +8,19 @@
|
|
|
8
8
|
|
|
9
9
|
# @fast-china/eslint-config
|
|
10
10
|
|
|
11
|
-
面向 Vue 3、UniApp、React、Angular、
|
|
11
|
+
面向 Vue 3、UniApp、SDK、Node.js、React、Angular、TypeScript 与 JavaScript 项目的实用型 ESLint Flat Config。
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
规则取舍遵循:先尊重社区通用写法并保持代码简洁、易读,再依次考虑真实 Bug / 类型安全、代码一致性和 Fast 系列项目偏好。不会为了满足 ESLint 强制改写语义正常、普遍使用的代码。
|
|
14
14
|
|
|
15
15
|
## 特性
|
|
16
16
|
|
|
17
17
|
- 基于 ESLint 10,仅提供原生 Flat Config。
|
|
18
|
-
-
|
|
19
|
-
- TypeScript
|
|
20
|
-
- SDK
|
|
21
|
-
-
|
|
22
|
-
- React、Angular、Markdown 和 Lodash
|
|
23
|
-
- 根据规则 schema 生成精确 `RuleOptions
|
|
24
|
-
- 插件与解析器均由本包声明依赖,使用者不需要手工拼装依赖树。
|
|
18
|
+
- Vue 3 与 UniApp 使用两个独立完整配置;普通 Vue 项目不会获得 UniApp globals、`.nvue` 解析或清单适配。
|
|
19
|
+
- TypeScript 使用 `recommendedTypeChecked` 与 Project Service,不叠加完整 strict/stylistic 预置。
|
|
20
|
+
- `.ts`、`.mts`、`.cts` 导出边界按 SDK 公共 API 对待;`.tsx` 保留完整类型安全和常见组件返回类型推断。
|
|
21
|
+
- JavaScript、TypeScript、Import 与 RegExp 规则在 SDK 和应用项目之间保持一致。
|
|
22
|
+
- 默认统一排序 `package.json` 和 `tsconfig*.json`;React、Angular、Markdown 和 Lodash 通过 `./configs` 按需组合。
|
|
23
|
+
- 根据规则 schema 生成精确 `RuleOptions`,提供规则名和选项自动补全。
|
|
25
24
|
|
|
26
25
|
## 环境要求
|
|
27
26
|
|
|
@@ -29,64 +28,63 @@
|
|
|
29
28
|
- ESLint `^10.0.0`
|
|
30
29
|
- TypeScript `^6.0.0`
|
|
31
30
|
|
|
32
|
-
## 安装
|
|
33
|
-
|
|
34
31
|
```sh
|
|
35
32
|
pnpm add -D eslint typescript @fast-china/eslint-config
|
|
36
33
|
```
|
|
37
34
|
|
|
38
|
-
## Vue 3
|
|
39
|
-
|
|
40
|
-
创建 `eslint.config.mjs`:
|
|
35
|
+
## Vue 3
|
|
41
36
|
|
|
42
37
|
```js
|
|
43
|
-
import
|
|
38
|
+
import { vueConfig } from "@fast-china/eslint-config";
|
|
39
|
+
import { defineConfig } from "eslint/config";
|
|
44
40
|
|
|
45
|
-
export default
|
|
41
|
+
export default defineConfig([
|
|
42
|
+
...vueConfig,
|
|
43
|
+
{
|
|
44
|
+
name: "project/custom",
|
|
45
|
+
rules: {
|
|
46
|
+
"no-console": "warn",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
46
50
|
```
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- 浏览器运行环境和 Node.js 工程文件 globals。
|
|
51
|
-
- JavaScript、类型感知 TypeScript、Vue 3 与 `.nvue`。
|
|
52
|
-
- `uni`、`uniCloud`、页面 API 以及 `wx`、`plus`、`my`、`tt` 等条件编译平台 globals。
|
|
53
|
-
- JSON、JSONC、JSON5,以及允许注释的 `pages.json`、`manifest.json` 和 VS Code `settings.json`、`extensions.json`。
|
|
54
|
-
- Import、RegExp、`package.json`/`tsconfig*.json` 排序、`.gitignore` 和 Prettier 冲突关闭层。
|
|
52
|
+
该入口处理 JavaScript、类型感知 TypeScript、Vue SFC,以及 Vue 项目常用的独立 `.jsx`/`.tsx` 组件文件;Vue JSX/TSX 继续检查显式 emits、重复键、只读 props、响应性丢失和保留组件名,但不会套用模板专属的 kebab-case、模板属性排序或 `v-text`/`v-html` 规则。配置同时包含 JSON、Import、RegExp、`.gitignore` 和 Prettier 兼容规则,但不包含任何 UniApp 能力。
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
## `fastConfig()`
|
|
59
|
-
|
|
60
|
-
根工厂只保留 `environment`,默认值为 `"browser"`:
|
|
54
|
+
## UniApp
|
|
61
55
|
|
|
62
56
|
```js
|
|
63
|
-
import {
|
|
57
|
+
import { uniAppConfig } from "@fast-china/eslint-config";
|
|
58
|
+
import { defineConfig } from "eslint/config";
|
|
64
59
|
|
|
65
|
-
export default
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
export default defineConfig([
|
|
61
|
+
...uniAppConfig,
|
|
62
|
+
{
|
|
63
|
+
name: "project/custom",
|
|
64
|
+
ignores: ["src/generated/**"],
|
|
65
|
+
rules: {
|
|
66
|
+
"no-console": "warn",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
| 值 | 应用源码 globals |
|
|
73
|
-
| ------------- | ---------------- |
|
|
74
|
-
| `"browser"` | 浏览器 |
|
|
75
|
-
| `"node"` | Node.js |
|
|
76
|
-
| `"universal"` | 浏览器和 Node.js |
|
|
72
|
+
UniApp 入口在 Vue 完整能力之外增加 `.nvue`、`uni`、`uniCloud`、页面 API、条件编译平台 globals、`unpackage` 忽略,以及 `pages.json`、`manifest.json` 注释适配。
|
|
77
73
|
|
|
78
|
-
|
|
74
|
+
ESLint 不执行 `#ifdef`/`#endif`,因此只能识别平台对象,不能验证对象是否位于正确的平台分支。当前不处理需要专用解析器的 `.uvue` 与 `.uts`。
|
|
79
75
|
|
|
80
|
-
##
|
|
76
|
+
## 工厂与项目覆写
|
|
81
77
|
|
|
82
|
-
|
|
78
|
+
根入口只提供含义明确的具名配置与工厂。项目需要选择运行环境或追加覆写时使用对应工厂:
|
|
83
79
|
|
|
84
80
|
```js
|
|
85
|
-
import {
|
|
81
|
+
import { createVueProjectConfigs, defineRules } from "@fast-china/eslint-config";
|
|
82
|
+
import { defineConfig } from "eslint/config";
|
|
86
83
|
|
|
87
|
-
export default
|
|
88
|
-
{ environment: "
|
|
84
|
+
export default defineConfig([
|
|
85
|
+
...createVueProjectConfigs({ environment: "universal" }),
|
|
89
86
|
{
|
|
87
|
+
name: "project/custom",
|
|
90
88
|
ignores: ["public/vendor/**"],
|
|
91
89
|
languageOptions: {
|
|
92
90
|
globals: {
|
|
@@ -97,152 +95,111 @@ export default fastConfig(
|
|
|
97
95
|
"no-console": "warn",
|
|
98
96
|
}),
|
|
99
97
|
},
|
|
100
|
-
|
|
101
|
-
files: ["**/*.generated.ts"],
|
|
102
|
-
rules: defineRules({
|
|
103
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
104
|
-
}),
|
|
105
|
-
}
|
|
106
|
-
);
|
|
98
|
+
]);
|
|
107
99
|
```
|
|
108
100
|
|
|
109
|
-
|
|
101
|
+
可用工厂:
|
|
110
102
|
|
|
111
|
-
|
|
103
|
+
- `createVueProjectConfigs(options, ...overrides)`
|
|
104
|
+
- `createUniAppProjectConfigs(options, ...overrides)`
|
|
105
|
+
- `createBaseConfigs(options)`:不绑定前端框架,适用于 Node.js、SDK 及其他显式组合场景
|
|
112
106
|
|
|
113
|
-
`
|
|
107
|
+
`environment` 可为 `"browser"`、`"node"` 或 `"universal"`,默认是 `"browser"`。配置文件、脚本、测试和 CLI 文件始终单独获得 Node.js globals。
|
|
114
108
|
|
|
115
|
-
|
|
116
|
-
parserOptions: {
|
|
117
|
-
projectService: true,
|
|
118
|
-
extraFileExtensions: [".vue", ".nvue"],
|
|
119
|
-
}
|
|
120
|
-
```
|
|
109
|
+
后置 Flat Config 拥有最高优先级。`defineRules()` 不修改传入对象,只提供精确规则类型检查。
|
|
121
110
|
|
|
122
|
-
|
|
111
|
+
## TypeScript 策略
|
|
123
112
|
|
|
124
|
-
|
|
113
|
+
类型感知文件必须属于 Project Service 可发现的 `tsconfig.json`。
|
|
125
114
|
|
|
126
|
-
|
|
115
|
+
- `explicit-module-boundary-types: "error"`:`.ts`、`.mts`、`.cts` 导出函数及导出类的公共边界必须显式声明参数和返回类型。
|
|
116
|
+
- `.tsx` 默认关闭模块边界类型强制:组件 Props 继续接受 TypeScript 检查,但不要求补写可稳定推断的 JSX 返回类型。
|
|
117
|
+
- `explicit-function-return-type: "off"`:内部函数、局部处理函数和内联回调使用 TypeScript 推断。
|
|
118
|
+
- `no-inferrable-types` 不删除参数和属性上的显式类型。
|
|
119
|
+
- Vue/NVue SFC 与独立 TSX 组件不强制模块边界和函数返回类型,以保留常见简洁写法。
|
|
120
|
+
- `no-floating-promises` 关闭;是否等待 Promise 由业务顺序和异常语义决定。
|
|
121
|
+
- `no-void: "error"`:不使用 `void promise` 或其他 `void` 表达式规避检查。
|
|
122
|
+
- `require-await: "error"`:没有真实 `await` 的函数应删除 `async`,避免改变返回值和异常语义。
|
|
123
|
+
- `no-misused-promises`、`await-thenable`、unsafe 类型规则及精选的高置信度类型规则保持为错误。
|
|
124
|
+
- 标准非空断言可用;矛盾、重复或无效的断言仍由专项规则检查。
|
|
125
|
+
- 数字和布尔值可直接用于模板字符串;运行时防御性条件不会因类型看似多余而报错。
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
## JavaScript、Import 与 Vue 策略
|
|
129
128
|
|
|
130
|
-
|
|
129
|
+
- `no-empty` 允许完全空的 `catch`,其他空代码块仍报错。
|
|
130
|
+
- `camelcase: ["error", { properties: "never" }]`:变量和类型使用 camelCase,外部协议对象属性保持原名。
|
|
131
|
+
- `no-eval`、`no-implied-eval`、`no-new-func`、`no-debugger` 等真实风险规则为错误。
|
|
132
|
+
- `import-x/first`、`import-x/no-duplicates` 与 `import-x/order` 均为错误;声明顺序支持自动修复。
|
|
133
|
+
- 保留 UniApp、Vue、React、Angular、Vite、Element Plus、Fast 和 Lodash 等常用 pathGroups,`@/**` 归入 internal,类型导入不参与 pathGroups 匹配。
|
|
134
|
+
- `sort-imports` 只检查同一 import 声明 `{}` 内的成员顺序,不接管声明之间的排序。
|
|
135
|
+
- `import-x/style-imports-last` 要求样式文件形成最后一个连续分组,同时不改变样式组内部顺序。
|
|
136
|
+
- Vue SFC 使用官方 `flat/recommended`;显式 emits、重复键、只读 props、响应性丢失和保留组件名等脚本语义规则也应用于 Vue JSX/TSX。
|
|
137
|
+
- kebab-case 属性、模板属性顺序和组件上的 `v-text`/`v-html` 仅检查 `.vue/.nvue` 模板;JSX 属性继续遵循 JavaScript 的 camelCase 约定。`no-v-html` 保持警告。
|
|
131
138
|
|
|
132
|
-
## React
|
|
133
|
-
|
|
134
|
-
React 项目从不绑定框架的基础配置开始组合:
|
|
139
|
+
## React 与 Angular
|
|
135
140
|
|
|
136
141
|
```js
|
|
137
142
|
import { createBaseConfigs } from "@fast-china/eslint-config";
|
|
138
143
|
import { createReactConfigs } from "@fast-china/eslint-config/configs";
|
|
139
144
|
import { defineConfig } from "eslint/config";
|
|
140
145
|
|
|
141
|
-
export default defineConfig([
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
export default defineConfig([...createBaseConfigs(), ...createReactConfigs({ importSource: "preact", version: "detect" })]);
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Angular
|
|
153
|
-
|
|
154
|
-
```js
|
|
155
|
-
import { createBaseConfigs } from "@fast-china/eslint-config";
|
|
156
|
-
import { createAngularConfigs } from "@fast-china/eslint-config/configs";
|
|
157
|
-
import { defineConfig } from "eslint/config";
|
|
158
|
-
|
|
159
|
-
export default defineConfig([...createBaseConfigs(), ...createAngularConfigs()]);
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Angular 片段检查 TypeScript 源码、外部 HTML 模板和组件内联模板,默认启用官方模板无障碍规则。特殊项目仍可配置:
|
|
163
|
-
|
|
164
|
-
```js
|
|
165
|
-
createAngularConfigs({
|
|
166
|
-
inlineTemplates: false,
|
|
167
|
-
templateAccessibility: false,
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## Node.js / SDK
|
|
172
|
-
|
|
173
|
-
不需要 Vue、UniApp、React 或 Angular 的项目直接使用基础配置:
|
|
174
|
-
|
|
175
|
-
```js
|
|
176
|
-
import { createBaseConfigs } from "@fast-china/eslint-config";
|
|
177
|
-
|
|
178
|
-
export default createBaseConfigs({ environment: "node" });
|
|
146
|
+
export default defineConfig([
|
|
147
|
+
...createBaseConfigs(),
|
|
148
|
+
...createReactConfigs(),
|
|
149
|
+
{
|
|
150
|
+
name: "project/custom",
|
|
151
|
+
rules: { "no-console": "warn" },
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
179
154
|
```
|
|
180
155
|
|
|
181
|
-
`
|
|
156
|
+
Angular 同理组合 `createAngularConfigs()`。基础配置不会加载 Vue 或 UniApp。
|
|
182
157
|
|
|
183
|
-
##
|
|
158
|
+
## 可选能力与清单排序
|
|
184
159
|
|
|
185
|
-
Markdown
|
|
160
|
+
Markdown 和 Lodash 导入策略需要显式组合:
|
|
186
161
|
|
|
187
162
|
```js
|
|
188
163
|
import { createBaseConfigs } from "@fast-china/eslint-config";
|
|
189
164
|
import { createMarkdownConfigs } from "@fast-china/eslint-config/configs";
|
|
190
165
|
import { defineConfig } from "eslint/config";
|
|
191
166
|
|
|
192
|
-
export default defineConfig([
|
|
167
|
+
export default defineConfig([
|
|
168
|
+
...createBaseConfigs({ environment: "node" }),
|
|
169
|
+
...createMarkdownConfigs(),
|
|
170
|
+
{
|
|
171
|
+
name: "project/custom",
|
|
172
|
+
rules: { "no-console": "warn" },
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
193
175
|
```
|
|
194
176
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
```js
|
|
198
|
-
import { createLodashConfigs } from "@fast-china/eslint-config/configs";
|
|
199
|
-
|
|
200
|
-
createLodashConfigs("lodash");
|
|
201
|
-
createLodashConfigs("lodash-unified");
|
|
202
|
-
```
|
|
177
|
+
`createBaseConfigs()`、`vueConfig` 和 `uniAppConfig` 都默认启用 `package.json` 与 `tsconfig*.json` 排序。`package.json` 排序不会进入顺序具有运行时语义的条件 `exports` 对象。
|
|
203
178
|
|
|
204
179
|
## 公共入口
|
|
205
180
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
- 默认 Vue 3 + TypeScript + UniApp Flat Config。
|
|
209
|
-
- `fastConfig`、`createBaseConfigs`、`FastConfigOptions`。
|
|
210
|
-
- `defineRules`、`RuleOptions`。
|
|
211
|
-
|
|
212
|
-
高级组合通过职责明确的子路径提供:
|
|
213
|
-
|
|
214
|
-
- `@fast-china/eslint-config/configs`:框架和功能配置片段。
|
|
181
|
+
- `@fast-china/eslint-config`:具名导出两个完整配置、项目配置工厂、`defineRules`、`ProjectConfigOptions` 和 `RuleOptions`;不提供默认导出或旧入口别名。
|
|
182
|
+
- `@fast-china/eslint-config/configs`:框架和可选功能片段。
|
|
215
183
|
- `@fast-china/eslint-config/constants`:文件 glob 与 UniApp globals。
|
|
216
184
|
- `@fast-china/eslint-config/rules`:带类型的原始规则记录。
|
|
217
185
|
|
|
218
186
|
## Prettier
|
|
219
187
|
|
|
220
|
-
Prettier 不作为 ESLint 规则运行。默认配置只加载 `eslint-config-prettier`
|
|
221
|
-
|
|
222
|
-
```sh
|
|
223
|
-
pnpm add -D prettier
|
|
224
|
-
pnpm exec prettier --check .
|
|
225
|
-
```
|
|
188
|
+
Prettier 不作为 ESLint 规则运行。默认配置只加载 `eslint-config-prettier` 关闭冲突规则;项目需要自行安装并执行格式化。
|
|
226
189
|
|
|
227
190
|
## 文档
|
|
228
191
|
|
|
192
|
+
- [完整规则手册](./docs/rules/index.zh.md)
|
|
229
193
|
- [默认规则与风险指南](./docs/rules-risk.zh.md)
|
|
230
194
|
- [工程质量审查报告](./docs/engineering-audit.zh.md)
|
|
231
|
-
- [贡献指南](./CONTRIBUTING.md)
|
|
232
|
-
- [安全策略](./SECURITY.md)
|
|
233
195
|
- [更新日志](./CHANGELOG.md)
|
|
234
196
|
|
|
235
|
-
|
|
197
|
+
完整规则手册在每个分类中优先列出仓库显式配置的规则,再列第三方预置规则;全部规则均提供直接的错误与正确代码示例。
|
|
198
|
+
|
|
199
|
+
## 开发
|
|
236
200
|
|
|
237
201
|
```sh
|
|
238
202
|
pnpm install --frozen-lockfile
|
|
239
203
|
pnpm typegen
|
|
240
204
|
pnpm check
|
|
241
|
-
pnpm pack --dry-run
|
|
242
205
|
```
|
|
243
|
-
|
|
244
|
-
升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`。`pnpm check` 会验证类型、构建、运行时行为、发布包契约、ESLint 和格式。
|
|
245
|
-
|
|
246
|
-
## 开源协议
|
|
247
|
-
|
|
248
|
-
[Apache-2.0](./LICENSE)
|
|
@@ -46,7 +46,9 @@ const createNodeToolingConfigs = (nodeFiles = GLOBS_JAVASCRIPT) => {
|
|
|
46
46
|
name: "@fast-china/node-tooling",
|
|
47
47
|
files,
|
|
48
48
|
rules: {
|
|
49
|
+
/** Node.js 配置和脚本可能需要加载 CommonJS 包,只在工具文件范围关闭 ESM `import` 限制。 */
|
|
49
50
|
"@typescript-eslint/no-require-imports": "off",
|
|
51
|
+
/** 构建、测试和 CLI 脚本允许把执行进度与诊断信息输出到终端。 */
|
|
50
52
|
"no-console": "off"
|
|
51
53
|
}
|
|
52
54
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.mjs","names":[],"sources":["../../src/configs/environment.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport globals from \"globals\";\nimport { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_NODE_TOOLING } from \"../constants\";\nimport type { Linter } from \"eslint\";\n\n/**\n * 应用源码可声明的运行时环境。\n *\n * - `\"browser\"` 仅提供浏览器全局变量。\n * - `\"node\"` 仅提供 Node.js 全局变量。\n * - `\"universal\"` 同时提供浏览器与 Node.js 全局变量。\n */\nexport type RuntimeEnvironment = \"browser\" | \"node\" | \"universal\";\n\n/**\n * 运行时全局变量配置片段的选项。\n *\n * @remarks\n * 固定项目组合会根据自身处理的语言和框架传入 `files`、`nodeFiles`。该接口仍保持独立,\n * 以便低层组合明确控制环境片段的文件范围。\n *\n * 应用代码与 Node.js 工程文件使用两个独立 Flat Config 片段,避免浏览器源码无条件获得\n * `process`、`Buffer` 等 Node.js 全局变量,也避免配置文件误报这些合法全局变量未定义。\n */\nexport interface EnvironmentConfigOptions {\n\t/**\n\t * 应用代码实际运行的环境,决定 `files` 范围内注入哪组标准全局变量。\n\t *\n\t * `\"browser\"` 只注入浏览器全局变量,`\"node\"` 只注入 Node.js 全局变量,\n\t * `\"universal\"` 同时注入两组。该值不会影响 `nodeFiles` 对应的工程文件;后者始终\n\t * 使用 Node.js 全局变量。\n\t * @defaultValue `\"browser\"`\n\t */\n\tenvironment?: RuntimeEnvironment;\n\t/**\n\t * 需要获得所选运行时全局变量的应用代码 glob 列表。\n\t *\n\t * 项目组合会把自身负责的 JavaScript、TypeScript 和框架文件范围传入这里。数组会\n\t * 复制到生成配置中,不会在函数内部修改调用方传入的值。\n\t * @defaultValue {@link GLOBS_CODE}\n\t */\n\tfiles?: readonly string[];\n\t/**\n\t * 当前启用且允许作为 Node.js 工程文件执行的脚本扩展名 glob 列表。\n\t *\n\t * 每一项都会与内置的配置文件、脚本目录、测试文件和 CLI 文件模式组合为 ESLint\n\t * Flat Config 的 AND 文件条件,避免工程文件模式意外接管组合范围之外的扩展名。\n\t * @defaultValue {@link GLOBS_JAVASCRIPT}\n\t */\n\tnodeFiles?: readonly string[];\n\t/**\n\t * 追加到应用代码环境中的项目级全局变量及其读写权限。\n\t *\n\t * 该记录在标准环境全局变量之后合并,所以同名条目可以覆盖预置权限。它应用于完整\n\t * `files` 范围;其中属于 Node.js 工程文件的子集还会由后续片段追加标准 Node.js 全局\n\t * 变量。值格式遵循 ESLint `Linter.Globals`。\n\t * @defaultValue `{}`\n\t */\n\tglobals?: Linter.Globals;\n}\n\n/**\n * 创建运行时环境相关的 ESLint 配置。\n *\n * @remarks\n * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局\n * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量。\n * Node 工具文件的规则覆写由 {@link createNodeToolingConfigs} 在语言规则之后应用。\n *\n * @param options - 运行时环境、目标文件范围与项目级全局变量。\n * @returns 依次包含应用运行时环境和 Node.js 工程文件环境的 Flat Config 数组。\n */\nexport const createEnvironmentConfigs = ({\n\tenvironment = \"browser\",\n\tfiles = GLOBS_CODE,\n\tnodeFiles = GLOBS_JAVASCRIPT,\n\tglobals: projectGlobals = {},\n}: EnvironmentConfigOptions = {}): ReturnType<typeof defineConfig> => {\n\tconst runtimeGlobals = {\n\t\t...(environment !== \"node\" ? globals.browser : {}),\n\t\t...(environment !== \"browser\" ? globals.node : {}),\n\t\t...projectGlobals,\n\t};\n\tconst nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));\n\n\treturn defineConfig([\n\t\t{\n\t\t\tname: `@fast-china/globals/${environment}`,\n\t\t\tfiles: [...files],\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: runtimeGlobals,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/globals/node-tooling\",\n\t\t\tfiles: nodeToolingFiles,\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: globals.node,\n\t\t\t},\n\t\t},\n\t]);\n};\n\n/**\n * 创建 Node.js 配置、脚本、测试和 CLI 文件的末尾规则覆写。\n *\n * @remarks\n * 该片段必须放在 JavaScript 与 TypeScript 规则之后,确保工具文件可以输出日志并使用\n * CommonJS 兼容加载,而不会放宽浏览器业务源码。\n *\n * @param nodeFiles - 当前已启用的 JavaScript/TypeScript 文件 glob。\n * @returns Node 工具文件规则覆写数组。\n */\nexport const createNodeToolingConfigs = (nodeFiles: readonly string[] = GLOBS_JAVASCRIPT): ReturnType<typeof defineConfig> => {\n\tconst files = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));\n\n\treturn defineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/node-tooling\",\n\t\t\tfiles,\n\t\t\trules: {\n\t\t\t\t
|
|
1
|
+
{"version":3,"file":"environment.mjs","names":[],"sources":["../../src/configs/environment.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport globals from \"globals\";\nimport { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_NODE_TOOLING } from \"../constants\";\nimport type { Linter } from \"eslint\";\n\n/**\n * 应用源码可声明的运行时环境。\n *\n * - `\"browser\"` 仅提供浏览器全局变量。\n * - `\"node\"` 仅提供 Node.js 全局变量。\n * - `\"universal\"` 同时提供浏览器与 Node.js 全局变量。\n */\nexport type RuntimeEnvironment = \"browser\" | \"node\" | \"universal\";\n\n/**\n * 运行时全局变量配置片段的选项。\n *\n * @remarks\n * 固定项目组合会根据自身处理的语言和框架传入 `files`、`nodeFiles`。该接口仍保持独立,\n * 以便低层组合明确控制环境片段的文件范围。\n *\n * 应用代码与 Node.js 工程文件使用两个独立 Flat Config 片段,避免浏览器源码无条件获得\n * `process`、`Buffer` 等 Node.js 全局变量,也避免配置文件误报这些合法全局变量未定义。\n */\nexport interface EnvironmentConfigOptions {\n\t/**\n\t * 应用代码实际运行的环境,决定 `files` 范围内注入哪组标准全局变量。\n\t *\n\t * `\"browser\"` 只注入浏览器全局变量,`\"node\"` 只注入 Node.js 全局变量,\n\t * `\"universal\"` 同时注入两组。该值不会影响 `nodeFiles` 对应的工程文件;后者始终\n\t * 使用 Node.js 全局变量。\n\t * @defaultValue `\"browser\"`\n\t */\n\tenvironment?: RuntimeEnvironment;\n\t/**\n\t * 需要获得所选运行时全局变量的应用代码 glob 列表。\n\t *\n\t * 项目组合会把自身负责的 JavaScript、TypeScript 和框架文件范围传入这里。数组会\n\t * 复制到生成配置中,不会在函数内部修改调用方传入的值。\n\t * @defaultValue {@link GLOBS_CODE}\n\t */\n\tfiles?: readonly string[];\n\t/**\n\t * 当前启用且允许作为 Node.js 工程文件执行的脚本扩展名 glob 列表。\n\t *\n\t * 每一项都会与内置的配置文件、脚本目录、测试文件和 CLI 文件模式组合为 ESLint\n\t * Flat Config 的 AND 文件条件,避免工程文件模式意外接管组合范围之外的扩展名。\n\t * @defaultValue {@link GLOBS_JAVASCRIPT}\n\t */\n\tnodeFiles?: readonly string[];\n\t/**\n\t * 追加到应用代码环境中的项目级全局变量及其读写权限。\n\t *\n\t * 该记录在标准环境全局变量之后合并,所以同名条目可以覆盖预置权限。它应用于完整\n\t * `files` 范围;其中属于 Node.js 工程文件的子集还会由后续片段追加标准 Node.js 全局\n\t * 变量。值格式遵循 ESLint `Linter.Globals`。\n\t * @defaultValue `{}`\n\t */\n\tglobals?: Linter.Globals;\n}\n\n/**\n * 创建运行时环境相关的 ESLint 配置。\n *\n * @remarks\n * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局\n * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量。\n * Node 工具文件的规则覆写由 {@link createNodeToolingConfigs} 在语言规则之后应用。\n *\n * @param options - 运行时环境、目标文件范围与项目级全局变量。\n * @returns 依次包含应用运行时环境和 Node.js 工程文件环境的 Flat Config 数组。\n */\nexport const createEnvironmentConfigs = ({\n\tenvironment = \"browser\",\n\tfiles = GLOBS_CODE,\n\tnodeFiles = GLOBS_JAVASCRIPT,\n\tglobals: projectGlobals = {},\n}: EnvironmentConfigOptions = {}): ReturnType<typeof defineConfig> => {\n\tconst runtimeGlobals = {\n\t\t...(environment !== \"node\" ? globals.browser : {}),\n\t\t...(environment !== \"browser\" ? globals.node : {}),\n\t\t...projectGlobals,\n\t};\n\tconst nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));\n\n\treturn defineConfig([\n\t\t{\n\t\t\tname: `@fast-china/globals/${environment}`,\n\t\t\tfiles: [...files],\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: runtimeGlobals,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/globals/node-tooling\",\n\t\t\tfiles: nodeToolingFiles,\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: globals.node,\n\t\t\t},\n\t\t},\n\t]);\n};\n\n/**\n * 创建 Node.js 配置、脚本、测试和 CLI 文件的末尾规则覆写。\n *\n * @remarks\n * 该片段必须放在 JavaScript 与 TypeScript 规则之后,确保工具文件可以输出日志并使用\n * CommonJS 兼容加载,而不会放宽浏览器业务源码。\n *\n * @param nodeFiles - 当前已启用的 JavaScript/TypeScript 文件 glob。\n * @returns Node 工具文件规则覆写数组。\n */\nexport const createNodeToolingConfigs = (nodeFiles: readonly string[] = GLOBS_JAVASCRIPT): ReturnType<typeof defineConfig> => {\n\tconst files = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));\n\n\treturn defineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/node-tooling\",\n\t\t\tfiles,\n\t\t\trules: {\n\t\t\t\t/** Node.js 配置和脚本可能需要加载 CommonJS 包,只在工具文件范围关闭 ESM `import` 限制。 */\n\t\t\t\t\"@typescript-eslint/no-require-imports\": \"off\",\n\t\t\t\t/** 构建、测试和 CLI 脚本允许把执行进度与诊断信息输出到终端。 */\n\t\t\t\t\"no-console\": \"off\",\n\t\t\t},\n\t\t},\n\t]);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAwEA,MAAa,4BAA4B,EACxC,cAAc,WACd,QAAQ,YACR,YAAY,kBACZ,SAAS,iBAAiB,CAAC,MACE,CAAC,MAAuC;CACrE,MAAM,iBAAiB;EACtB,GAAI,gBAAgB,SAAS,QAAQ,UAAU,CAAC;EAChD,GAAI,gBAAgB,YAAY,QAAQ,OAAO,CAAC;EAChD,GAAG;CACJ;CACA,MAAM,mBAAmB,mBAAmB,SAAS,aAAa,UAAU,KAAK,aAAa,CAAC,UAAU,QAAQ,CAAC,CAAC;CAEnH,OAAO,aAAa,CACnB;EACC,MAAM,uBAAuB;EAC7B,OAAO,CAAC,GAAG,KAAK;EAChB,iBAAiB,EAChB,SAAS,eACV;CACD,GACA;EACC,MAAM;EACN,OAAO;EACP,iBAAiB,EAChB,SAAS,QAAQ,KAClB;CACD,CACD,CAAC;AACF;;;;;;;;;;;AAYA,MAAa,4BAA4B,YAA+B,qBAAsD;CAC7H,MAAM,QAAQ,mBAAmB,SAAS,aAAa,UAAU,KAAK,aAAa,CAAC,UAAU,QAAQ,CAAC,CAAC;CAExG,OAAO,aAAa,CACnB;EACC,MAAM;EACN;EACA,OAAO;;GAEN,yCAAyC;;GAEzC,cAAc;EACf;CACD,CACD,CAAC;AACF"}
|
package/dist/configs/ignores.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import eslintConfigFlatGitignore from "eslint-config-flat-gitignore";
|
|
|
12
12
|
const DEFAULT_IGNORE_PATTERNS = Object.freeze([
|
|
13
13
|
"**/{.pnpm-store,node_modules}/**",
|
|
14
14
|
"**/{dist,build,coverage,output,temp,tmp}/**",
|
|
15
|
-
"**/unpackage/**",
|
|
16
15
|
"**/{.cache,.nuxt,.output,.vercel,.nitro}/**",
|
|
17
16
|
"**/{.vitepress/cache,.vite-inspect}/**",
|
|
18
17
|
"**/__snapshots__/**",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ignores.mjs","names":[],"sources":["../../src/configs/ignores.ts"],"sourcesContent":["import { defineConfig, globalIgnores } from \"eslint/config\";\nimport eslintConfigFlatGitignore from \"eslint-config-flat-gitignore\";\nimport { GLOBS_LOCKFILES } from \"../constants\";\n\n/**\n * 默认忽略依赖、构建结果、缓存、生成文件和包管理器锁文件。\n *\n * @remarks\n * 不忽略 `src`、`public`、测试夹具或普通 Markdown 文档,避免共享配置静默漏检\n * 应由项目维护的文件。\n */\nexport const DEFAULT_IGNORE_PATTERNS = Object.freeze([\n\t\"**/{.pnpm-store,node_modules}/**\",\n\t\"**/{dist,build,coverage,output,temp,tmp}/**\",\n\t\"**/
|
|
1
|
+
{"version":3,"file":"ignores.mjs","names":[],"sources":["../../src/configs/ignores.ts"],"sourcesContent":["import { defineConfig, globalIgnores } from \"eslint/config\";\nimport eslintConfigFlatGitignore from \"eslint-config-flat-gitignore\";\nimport { GLOBS_LOCKFILES } from \"../constants\";\n\n/**\n * 默认忽略依赖、构建结果、缓存、生成文件和包管理器锁文件。\n *\n * @remarks\n * 不忽略 `src`、`public`、测试夹具或普通 Markdown 文档,避免共享配置静默漏检\n * 应由项目维护的文件。\n */\nexport const DEFAULT_IGNORE_PATTERNS = Object.freeze([\n\t\"**/{.pnpm-store,node_modules}/**\",\n\t\"**/{dist,build,coverage,output,temp,tmp}/**\",\n\t\"**/{.cache,.nuxt,.output,.vercel,.nitro}/**\",\n\t\"**/{.vitepress/cache,.vite-inspect}/**\",\n\t\"**/__snapshots__/**\",\n\t\"**/*.min.*\",\n\t\"**/auto-import?(s).d.ts\",\n\t\"**/components.d.ts\",\n\t...GLOBS_LOCKFILES,\n]);\n\n/**\n * 创建全局忽略配置,并在默认集合之后追加项目自定义模式。\n *\n * @param additionalPatterns - 追加到 {@link DEFAULT_IGNORE_PATTERNS} 之后的 ESLint 全局忽略模式。\n * @returns 包含单个命名全局忽略片段的 Flat Config 数组。\n */\nexport const createGlobalIgnores = (additionalPatterns: readonly string[] = []): ReturnType<typeof defineConfig> =>\n\tdefineConfig([globalIgnores([...DEFAULT_IGNORE_PATTERNS, ...additionalPatterns], \"@fast-china/ignores/global\")]);\n\n/**\n * 创建读取项目 `.gitignore` 的全局忽略配置。\n *\n * @remarks\n * `.gitignore` 的查找位置由 `eslint-config-flat-gitignore` 根据 ESLint 当前工作目录确定。\n * 未找到文件时不会抛错;该片段也不会替代 {@link createGlobalIgnores} 的内置模式。\n *\n * @returns 包含 `.gitignore` 转换结果的 Flat Config 数组。\n */\nexport const createGitignoreConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\t...eslintConfigFlatGitignore({ strict: false }),\n\t\t\tname: \"@fast-china/ignores/git\",\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,0BAA0B,OAAO,OAAO;CACpD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;AACJ,CAAC;;;;;;;AAQD,MAAa,uBAAuB,qBAAwC,CAAC,MAC5E,aAAa,CAAC,cAAc,CAAC,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,4BAA4B,CAAC,CAAC;;;;;;;;;;AAWhH,MAAa,+BACZ,aAAa,CACZ;CACC,GAAG,0BAA0B,EAAE,QAAQ,MAAM,CAAC;CAC9C,MAAM;AACP,CACD,CAAC"}
|
package/dist/configs/import.mjs
CHANGED
|
@@ -6,7 +6,9 @@ import eslintPluginImportX from "eslint-plugin-import-x";
|
|
|
6
6
|
//#region src/configs/import.ts
|
|
7
7
|
const importXRecommended = {
|
|
8
8
|
...eslintPluginImportX.flatConfigs.recommended,
|
|
9
|
-
plugins: {
|
|
9
|
+
plugins: {
|
|
10
|
+
/** import-x 当前发布类型仍基于旧版 RuleContext;运行时接口与 ESLint 10 Flat Config 兼容。 */
|
|
11
|
+
"import-x": styleAwareImportXPlugin }
|
|
10
12
|
};
|
|
11
13
|
/**
|
|
12
14
|
* 创建模块导入规则配置。
|
|
@@ -24,6 +26,7 @@ const createImportConfigs = (files = GLOBS_CODE) => defineConfig([{
|
|
|
24
26
|
extends: [importXRecommended],
|
|
25
27
|
rules: {
|
|
26
28
|
...importRules,
|
|
29
|
+
/** 样式导入必须形成最后一个连续分组;规则不提供修复,避免改变 CSS 层叠顺序。 */
|
|
27
30
|
"import-x/style-imports-last": "error"
|
|
28
31
|
}
|
|
29
32
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import.mjs","names":[],"sources":["../../src/configs/import.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginImportX from \"eslint-plugin-import-x\";\nimport { GLOBS_CODE } from \"../constants\";\nimport { styleAwareImportXPlugin } from \"../plugins/import\";\nimport { importRules } from \"../rules\";\nimport type { ESLint } from \"eslint\";\n\nconst importXRecommended = {\n\t...eslintPluginImportX.flatConfigs.recommended,\n\tplugins: {\n\t\t
|
|
1
|
+
{"version":3,"file":"import.mjs","names":[],"sources":["../../src/configs/import.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginImportX from \"eslint-plugin-import-x\";\nimport { GLOBS_CODE } from \"../constants\";\nimport { styleAwareImportXPlugin } from \"../plugins/import\";\nimport { importRules } from \"../rules\";\nimport type { ESLint } from \"eslint\";\n\nconst importXRecommended = {\n\t...eslintPluginImportX.flatConfigs.recommended,\n\tplugins: {\n\t\t/** import-x 当前发布类型仍基于旧版 RuleContext;运行时接口与 ESLint 10 Flat Config 兼容。 */\n\t\t\"import-x\": styleAwareImportXPlugin as unknown as ESLint.Plugin,\n\t},\n};\n\n/**\n * 创建模块导入规则配置。\n *\n * @remarks\n * 共享库不猜测项目的路径别名或解析器,因此只继承 import-x 的推荐能力,\n * 与 resolver 强耦合且容易误报的规则会在本地规则记录中显式关闭。\n *\n * @param files - 应用 import-x 推荐规则与本地覆盖规则的 ESLint glob 列表。\n * @returns 包含 import-x 插件预置和本地规则的 Flat Config 数组。\n */\nexport const createImportConfigs = (files: readonly string[] = GLOBS_CODE): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/import\",\n\t\t\tfiles: [...files],\n\t\t\textends: [importXRecommended],\n\t\t\trules: {\n\t\t\t\t...importRules,\n\t\t\t\t/** 样式导入必须形成最后一个连续分组;规则不提供修复,避免改变 CSS 层叠顺序。 */\n\t\t\t\t\"import-x/style-imports-last\": \"error\",\n\t\t\t},\n\t\t},\n\t]);\n"],"mappings":";;;;;;AAOA,MAAM,qBAAqB;CAC1B,GAAG,oBAAoB,YAAY;CACnC,SAAS;;AAER,YAAY,wBACb;AACD;;;;;;;;;;;AAYA,MAAa,uBAAuB,QAA2B,eAC9D,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,GAAG,KAAK;CAChB,SAAS,CAAC,kBAAkB;CAC5B,OAAO;EACN,GAAG;;EAEH,+BAA+B;CAChC;AACD,CACD,CAAC"}
|
package/dist/configs/index.d.mts
CHANGED
|
@@ -14,5 +14,5 @@ import { createPackageJsonSortConfigs } from "./sort-package.mjs";
|
|
|
14
14
|
import { createTsconfigSortConfigs } from "./sort-tsconfig.mjs";
|
|
15
15
|
import { createTypeScriptConfigs, createTypeScriptParserOptions, getTypeScriptPresetConfigs } from "./typescript.mjs";
|
|
16
16
|
import { createUniAppConfigs } from "./uniapp.mjs";
|
|
17
|
-
import { createVueConfigs } from "./vue.mjs";
|
|
18
|
-
export { AngularConfigOptions, DEFAULT_IGNORE_PATTERNS, EnvironmentConfigOptions, LodashPreference, ReactConfigOptions, RuntimeEnvironment, createAngularConfigs, createCommonConfigs, createEnvironmentConfigs, createGitignoreConfigs, createGlobalIgnores, createImportConfigs, createJavaScriptConfigs, createJsonConfigs, createLodashConfigs, createMarkdownConfigs, createNodeToolingConfigs, createPackageJsonSortConfigs, createPrettierConfigs, createReactConfigs, createRegexpConfigs, createTsconfigSortConfigs, createTypeScriptConfigs, createTypeScriptParserOptions, createUniAppConfigs, createVueConfigs, getTypeScriptPresetConfigs };
|
|
17
|
+
import { createVueConfigs, createVueJsxConfigs } from "./vue.mjs";
|
|
18
|
+
export { AngularConfigOptions, DEFAULT_IGNORE_PATTERNS, EnvironmentConfigOptions, LodashPreference, ReactConfigOptions, RuntimeEnvironment, createAngularConfigs, createCommonConfigs, createEnvironmentConfigs, createGitignoreConfigs, createGlobalIgnores, createImportConfigs, createJavaScriptConfigs, createJsonConfigs, createLodashConfigs, createMarkdownConfigs, createNodeToolingConfigs, createPackageJsonSortConfigs, createPrettierConfigs, createReactConfigs, createRegexpConfigs, createTsconfigSortConfigs, createTypeScriptConfigs, createTypeScriptParserOptions, createUniAppConfigs, createVueConfigs, createVueJsxConfigs, getTypeScriptPresetConfigs };
|
package/dist/configs/index.mjs
CHANGED
|
@@ -14,5 +14,5 @@ import { createPackageJsonSortConfigs } from "./sort-package.mjs";
|
|
|
14
14
|
import { createTsconfigSortConfigs } from "./sort-tsconfig.mjs";
|
|
15
15
|
import { createTypeScriptConfigs, createTypeScriptParserOptions, getTypeScriptPresetConfigs } from "./typescript.mjs";
|
|
16
16
|
import { createUniAppConfigs } from "./uniapp.mjs";
|
|
17
|
-
import { createVueConfigs } from "./vue.mjs";
|
|
18
|
-
export { DEFAULT_IGNORE_PATTERNS, createAngularConfigs, createCommonConfigs, createEnvironmentConfigs, createGitignoreConfigs, createGlobalIgnores, createImportConfigs, createJavaScriptConfigs, createJsonConfigs, createLodashConfigs, createMarkdownConfigs, createNodeToolingConfigs, createPackageJsonSortConfigs, createPrettierConfigs, createReactConfigs, createRegexpConfigs, createTsconfigSortConfigs, createTypeScriptConfigs, createTypeScriptParserOptions, createUniAppConfigs, createVueConfigs, getTypeScriptPresetConfigs };
|
|
17
|
+
import { createVueConfigs, createVueJsxConfigs } from "./vue.mjs";
|
|
18
|
+
export { DEFAULT_IGNORE_PATTERNS, createAngularConfigs, createCommonConfigs, createEnvironmentConfigs, createGitignoreConfigs, createGlobalIgnores, createImportConfigs, createJavaScriptConfigs, createJsonConfigs, createLodashConfigs, createMarkdownConfigs, createNodeToolingConfigs, createPackageJsonSortConfigs, createPrettierConfigs, createReactConfigs, createRegexpConfigs, createTsconfigSortConfigs, createTypeScriptConfigs, createTypeScriptParserOptions, createUniAppConfigs, createVueConfigs, createVueJsxConfigs, getTypeScriptPresetConfigs };
|
|
@@ -19,7 +19,9 @@ const createJavaScriptConfigs = (files = GLOBS_JAVASCRIPT) => defineConfig([{
|
|
|
19
19
|
extends: [eslint.configs.recommended],
|
|
20
20
|
languageOptions: {
|
|
21
21
|
ecmaVersion: "latest",
|
|
22
|
-
parserOptions: { ecmaFeatures: {
|
|
22
|
+
parserOptions: { ecmaFeatures: {
|
|
23
|
+
/** 普通 `.jsx` 文件需要显式开启 JSX 语法解析。 */
|
|
24
|
+
jsx: true } }
|
|
23
25
|
},
|
|
24
26
|
rules: javascriptRules
|
|
25
27
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.mjs","names":[],"sources":["../../src/configs/javascript.ts"],"sourcesContent":["import eslint from \"@eslint/js\";\nimport { defineConfig } from \"eslint/config\";\nimport { GLOBS_JAVASCRIPT } from \"../constants\";\nimport { javascriptRules } from \"../rules\";\n\n/**\n * 创建 JavaScript/JSX 配置。\n *\n * @remarks\n * `@eslint/js` 提供基础正确性规则,本仓库只在其后补充有明确维护理由的规则。\n * 普通 `.jsx` 文件会显式启用 JSX 语法解析,但不会因此自动启用 React 规则。\n *\n * @param files - 应用 JavaScript 基础规则的 ESLint glob 列表。\n * @returns 包含 JavaScript 推荐预置、本地规则与 JSX 解析设置的 Flat Config 数组。\n */\nexport const createJavaScriptConfigs = (files: readonly string[] = GLOBS_JAVASCRIPT): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/javascript\",\n\t\t\tfiles: [...files],\n\t\t\textends: [eslint.configs.recommended],\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparserOptions: {\n\t\t\t\t\tecmaFeatures: {\n\t\t\t\t\t\t
|
|
1
|
+
{"version":3,"file":"javascript.mjs","names":[],"sources":["../../src/configs/javascript.ts"],"sourcesContent":["import eslint from \"@eslint/js\";\nimport { defineConfig } from \"eslint/config\";\nimport { GLOBS_JAVASCRIPT } from \"../constants\";\nimport { javascriptRules } from \"../rules\";\n\n/**\n * 创建 JavaScript/JSX 配置。\n *\n * @remarks\n * `@eslint/js` 提供基础正确性规则,本仓库只在其后补充有明确维护理由的规则。\n * 普通 `.jsx` 文件会显式启用 JSX 语法解析,但不会因此自动启用 React 规则。\n *\n * @param files - 应用 JavaScript 基础规则的 ESLint glob 列表。\n * @returns 包含 JavaScript 推荐预置、本地规则与 JSX 解析设置的 Flat Config 数组。\n */\nexport const createJavaScriptConfigs = (files: readonly string[] = GLOBS_JAVASCRIPT): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/javascript\",\n\t\t\tfiles: [...files],\n\t\t\textends: [eslint.configs.recommended],\n\t\t\tlanguageOptions: {\n\t\t\t\tecmaVersion: \"latest\",\n\t\t\t\tparserOptions: {\n\t\t\t\t\tecmaFeatures: {\n\t\t\t\t\t\t/** 普通 `.jsx` 文件需要显式开启 JSX 语法解析。 */\n\t\t\t\t\t\tjsx: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\trules: javascriptRules,\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,2BAA2B,QAA2B,qBAClE,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,GAAG,KAAK;CAChB,SAAS,CAAC,OAAO,QAAQ,WAAW;CACpC,iBAAiB;EAChB,aAAa;EACb,eAAe,EACd,cAAc;;AAEb,KAAK,KACN,EACD;CACD;CACA,OAAO;AACR,CACD,CAAC"}
|
package/dist/configs/json.mjs
CHANGED
|
@@ -31,7 +31,9 @@ const createJsonConfigs = () => defineConfig([
|
|
|
31
31
|
{
|
|
32
32
|
name: "@fast-china/json/vscode",
|
|
33
33
|
files: ["**/.vscode/extensions.json", "**/.vscode/settings.json"],
|
|
34
|
-
rules: {
|
|
34
|
+
rules: {
|
|
35
|
+
/** VS Code 的工作区设置和扩展推荐文件使用带注释的 JSONC 方言。 */
|
|
36
|
+
"jsonc/no-comments": "off" }
|
|
35
37
|
}
|
|
36
38
|
]);
|
|
37
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.mjs","names":[],"sources":["../../src/configs/json.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginJsonc from \"eslint-plugin-jsonc\";\nimport { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from \"../constants\";\n\n/**\n * 创建 JSON、JSONC 与 JSON5 配置。\n *\n * @remarks\n * 三种方言使用各自的官方推荐预置,避免严格 JSON 规则错误覆盖允许注释或尾随逗号的文件。\n * VS Code 的 `.vscode/settings.json` 与 `.vscode/extensions.json` 仍以 `.json` 结尾,\n * 因此额外允许其中出现注释。\n *\n * @returns 按 JSON、JSONC、JSON5 与 VS Code 工作区文件覆盖顺序排列的 Flat Config 数组。\n */\nexport const createJsonConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/json/json\",\n\t\t\tfiles: [GLOB_JSON],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-json\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/jsonc\",\n\t\t\tfiles: [GLOB_JSONC],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-jsonc\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/json5\",\n\t\t\tfiles: [GLOB_JSON5],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-json5\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/vscode\",\n\t\t\tfiles: [\"**/.vscode/extensions.json\", \"**/.vscode/settings.json\"],\n\t\t\trules: {\n\t\t\t\t
|
|
1
|
+
{"version":3,"file":"json.mjs","names":[],"sources":["../../src/configs/json.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintPluginJsonc from \"eslint-plugin-jsonc\";\nimport { GLOB_JSON, GLOB_JSON5, GLOB_JSONC } from \"../constants\";\n\n/**\n * 创建 JSON、JSONC 与 JSON5 配置。\n *\n * @remarks\n * 三种方言使用各自的官方推荐预置,避免严格 JSON 规则错误覆盖允许注释或尾随逗号的文件。\n * VS Code 的 `.vscode/settings.json` 与 `.vscode/extensions.json` 仍以 `.json` 结尾,\n * 因此额外允许其中出现注释。\n *\n * @returns 按 JSON、JSONC、JSON5 与 VS Code 工作区文件覆盖顺序排列的 Flat Config 数组。\n */\nexport const createJsonConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/json/json\",\n\t\t\tfiles: [GLOB_JSON],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-json\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/jsonc\",\n\t\t\tfiles: [GLOB_JSONC],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-jsonc\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/json5\",\n\t\t\tfiles: [GLOB_JSON5],\n\t\t\textends: [eslintPluginJsonc.configs[\"flat/recommended-with-json5\"]],\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/json/vscode\",\n\t\t\tfiles: [\"**/.vscode/extensions.json\", \"**/.vscode/settings.json\"],\n\t\t\trules: {\n\t\t\t\t/** VS Code 的工作区设置和扩展推荐文件使用带注释的 JSONC 方言。 */\n\t\t\t\t\"jsonc/no-comments\": \"off\",\n\t\t\t},\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,0BACZ,aAAa;CACZ;EACC,MAAM;EACN,OAAO,CAAC,SAAS;EACjB,SAAS,CAAC,kBAAkB,QAAQ,6BAA6B;CAClE;CACA;EACC,MAAM;EACN,OAAO,CAAC,UAAU;EAClB,SAAS,CAAC,kBAAkB,QAAQ,8BAA8B;CACnE;CACA;EACC,MAAM;EACN,OAAO,CAAC,UAAU;EAClB,SAAS,CAAC,kBAAkB,QAAQ,8BAA8B;CACnE;CACA;EACC,MAAM;EACN,OAAO,CAAC,8BAA8B,0BAA0B;EAChE,OAAO;;AAEN,qBAAqB,MACtB;CACD;AACD,CAAC"}
|
|
@@ -4,7 +4,8 @@ import { defineConfig } from "eslint/config";
|
|
|
4
4
|
* 创建 Markdown 结构与语法检查配置。
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
7
|
+
* 该配置按 GitHub Flavored Markdown 检查文档本身,使表格等 GFM 结构也能进入对应规则;
|
|
8
|
+
* 代码块是否接受额外语言规则由项目覆盖配置决定。
|
|
8
9
|
*
|
|
9
10
|
* @returns 包含 `@eslint/markdown` 推荐预置的 Flat Config 数组。
|
|
10
11
|
*/
|
|
@@ -6,14 +6,16 @@ import eslintMarkdown from "@eslint/markdown";
|
|
|
6
6
|
* 创建 Markdown 结构与语法检查配置。
|
|
7
7
|
*
|
|
8
8
|
* @remarks
|
|
9
|
-
*
|
|
9
|
+
* 该配置按 GitHub Flavored Markdown 检查文档本身,使表格等 GFM 结构也能进入对应规则;
|
|
10
|
+
* 代码块是否接受额外语言规则由项目覆盖配置决定。
|
|
10
11
|
*
|
|
11
12
|
* @returns 包含 `@eslint/markdown` 推荐预置的 Flat Config 数组。
|
|
12
13
|
*/
|
|
13
14
|
const createMarkdownConfigs = () => defineConfig([{
|
|
14
15
|
name: "@fast-china/markdown",
|
|
15
16
|
files: [GLOB_MARKDOWN],
|
|
16
|
-
extends: [eslintMarkdown.configs.recommended]
|
|
17
|
+
extends: [eslintMarkdown.configs.recommended],
|
|
18
|
+
language: "markdown/gfm"
|
|
17
19
|
}]);
|
|
18
20
|
//#endregion
|
|
19
21
|
export { createMarkdownConfigs };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.mjs","names":[],"sources":["../../src/configs/markdown.ts"],"sourcesContent":["import eslintMarkdown from \"@eslint/markdown\";\nimport { defineConfig } from \"eslint/config\";\nimport { GLOB_MARKDOWN } from \"../constants\";\n\n/**\n * 创建 Markdown 结构与语法检查配置。\n *\n * @remarks\n *
|
|
1
|
+
{"version":3,"file":"markdown.mjs","names":[],"sources":["../../src/configs/markdown.ts"],"sourcesContent":["import eslintMarkdown from \"@eslint/markdown\";\nimport { defineConfig } from \"eslint/config\";\nimport { GLOB_MARKDOWN } from \"../constants\";\n\n/**\n * 创建 Markdown 结构与语法检查配置。\n *\n * @remarks\n * 该配置按 GitHub Flavored Markdown 检查文档本身,使表格等 GFM 结构也能进入对应规则;\n * 代码块是否接受额外语言规则由项目覆盖配置决定。\n *\n * @returns 包含 `@eslint/markdown` 推荐预置的 Flat Config 数组。\n */\nexport const createMarkdownConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/markdown\",\n\t\t\tfiles: [GLOB_MARKDOWN],\n\t\t\textends: [eslintMarkdown.configs.recommended],\n\t\t\tlanguage: \"markdown/gfm\",\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,8BACZ,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,aAAa;CACrB,SAAS,CAAC,eAAe,QAAQ,WAAW;CAC5C,UAAU;AACX,CACD,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineConfig } from "eslint/config";
|
|
2
2
|
import eslintConfigPrettierFlat from "eslint-config-prettier/flat";
|
|
3
3
|
//#region src/configs/prettier.ts
|
|
4
|
+
/** 与 Prettier 输出兼容且承载项目约定、无需由兼容层关闭的最终规则记录。 */
|
|
4
5
|
const prettierRules = { ...eslintConfigPrettierFlat.rules };
|
|
5
6
|
delete prettierRules.curly;
|
|
6
|
-
delete prettierRules["vue/html-closing-bracket-newline"];
|
|
7
7
|
/**
|
|
8
8
|
* 创建 Prettier 兼容层。
|
|
9
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prettier.mjs","names":[],"sources":["../../src/configs/prettier.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintConfigPrettierFlat from \"eslint-config-prettier/flat\";\n\n
|
|
1
|
+
{"version":3,"file":"prettier.mjs","names":[],"sources":["../../src/configs/prettier.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport eslintConfigPrettierFlat from \"eslint-config-prettier/flat\";\n\n/** 与 Prettier 输出兼容且承载项目约定、无需由兼容层关闭的最终规则记录。 */\nconst prettierRules = { ...eslintConfigPrettierFlat.rules };\ndelete prettierRules.curly;\n\n/**\n * 创建 Prettier 兼容层。\n *\n * @remarks\n * 它只关闭与 Prettier 冲突的 ESLint 格式规则,不会在 ESLint 进程中执行 Prettier。\n * 工厂始终把它放在内置配置之后,使上游预置的格式规则能够被正确覆盖。\n *\n * @returns 包含命名后的 `eslint-config-prettier` Flat Config 数组。\n */\nexport const createPrettierConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\t...eslintConfigPrettierFlat,\n\t\t\tname: \"@fast-china/prettier\",\n\t\t\trules: prettierRules,\n\t\t},\n\t]);\n"],"mappings":";;;;AAIA,MAAM,gBAAgB,EAAE,GAAG,yBAAyB,MAAM;AAC1D,OAAO,cAAc;;;;;;;;;;AAWrB,MAAa,8BACZ,aAAa,CACZ;CACC,GAAG;CACH,MAAM;CACN,OAAO;AACR,CACD,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { defineConfig } from "eslint/config";
|
|
|
4
4
|
* 创建 package.json 排序配置。
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
7
|
+
* 完整项目配置默认启用该能力。首次修复可能产生较大的排序 diff;规则不会进入顺序
|
|
8
8
|
* 具有条件导出语义的 `exports` 对象内部。
|
|
9
9
|
*
|
|
10
10
|
* @returns 仅匹配 `package.json` 的字段排序 Flat Config 数组。
|
|
@@ -5,7 +5,7 @@ import { defineConfig } from "eslint/config";
|
|
|
5
5
|
* 创建 package.json 排序配置。
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
*
|
|
8
|
+
* 完整项目配置默认启用该能力。首次修复可能产生较大的排序 diff;规则不会进入顺序
|
|
9
9
|
* 具有条件导出语义的 `exports` 对象内部。
|
|
10
10
|
*
|
|
11
11
|
* @returns 仅匹配 `package.json` 的字段排序 Flat Config 数组。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-package.mjs","names":[],"sources":["../../src/configs/sort-package.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport { packageJsonSortRules } from \"../rules\";\n\n/**\n * 创建 package.json 排序配置。\n *\n * @remarks\n *
|
|
1
|
+
{"version":3,"file":"sort-package.mjs","names":[],"sources":["../../src/configs/sort-package.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport { packageJsonSortRules } from \"../rules\";\n\n/**\n * 创建 package.json 排序配置。\n *\n * @remarks\n * 完整项目配置默认启用该能力。首次修复可能产生较大的排序 diff;规则不会进入顺序\n * 具有条件导出语义的 `exports` 对象内部。\n *\n * @returns 仅匹配 `package.json` 的字段排序 Flat Config 数组。\n */\nexport const createPackageJsonSortConfigs = (): ReturnType<typeof defineConfig> =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/sort/package-json\",\n\t\t\tfiles: [\"**/package.json\"],\n\t\t\trules: packageJsonSortRules,\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,qCACZ,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,iBAAiB;CACzB,OAAO;AACR,CACD,CAAC"}
|
|
@@ -4,8 +4,8 @@ import { defineConfig } from "eslint/config";
|
|
|
4
4
|
* 创建 tsconfig.json 排序配置。
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* 排序只改变字段阅读顺序,不改变编译选项值。完整项目配置默认启用,首次修复可能
|
|
8
|
+
* 产生较大的排序 diff。
|
|
9
9
|
*
|
|
10
10
|
* @returns 匹配 `tsconfig.json` 与 `tsconfig.*.json` 的字段排序 Flat Config 数组。
|
|
11
11
|
*/
|