@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/dist/index.js
CHANGED
|
@@ -1,273 +1,263 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import eslintConfigFlatGitignore from 'eslint-config-flat-gitignore';
|
|
4
|
+
import eslintPluginImportX from 'eslint-plugin-import-x';
|
|
5
|
+
import eslint from '@eslint/js';
|
|
6
|
+
import eslintPluginJsonc from 'eslint-plugin-jsonc';
|
|
7
|
+
import eslintMarkdown from '@eslint/markdown';
|
|
8
|
+
import eslintConfigPrettierFlat from 'eslint-config-prettier/flat';
|
|
9
|
+
import eslintPluginRegexp from 'eslint-plugin-regexp';
|
|
10
|
+
import tseslint from 'typescript-eslint';
|
|
11
|
+
import eslintPluginVue from 'eslint-plugin-vue';
|
|
12
|
+
import vueEslintParser from 'vue-eslint-parser';
|
|
13
|
+
|
|
14
|
+
// src/define-rules.ts
|
|
15
|
+
var defineRules = (rules) => rules;
|
|
16
|
+
|
|
17
|
+
// src/constants/index.ts
|
|
18
|
+
var GLOBS_JAVASCRIPT = ["**/*.{js,cjs,mjs,jsx}"];
|
|
19
|
+
var GLOBS_TYPESCRIPT = ["**/*.{ts,cts,mts,tsx}"];
|
|
20
|
+
var GLOB_VUE = "**/*.vue";
|
|
21
|
+
var GLOB_JSON = "**/*.json";
|
|
22
|
+
var GLOB_JSONC = "**/*.jsonc";
|
|
23
|
+
var GLOB_JSON5 = "**/*.json5";
|
|
24
|
+
var GLOB_MARKDOWN = "**/*.md";
|
|
25
|
+
var GLOBS_CODE = [...GLOBS_JAVASCRIPT, ...GLOBS_TYPESCRIPT, GLOB_VUE];
|
|
26
|
+
var GLOBS_NODE_TOOLING = [
|
|
27
|
+
"**/*.{config,setup}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
28
|
+
"**/{scripts,bin}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
29
|
+
"**/{test,tests}/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
30
|
+
"**/*.{test,spec}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
31
|
+
"**/cli.{js,cjs,mjs,ts,cts,mts}"
|
|
32
|
+
];
|
|
33
|
+
var GLOBS_TSCONFIG = ["**/tsconfig.json", "**/tsconfig.*.json"];
|
|
34
|
+
var GLOBS_LOCKFILES = ["**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/bun.lock", "**/bun.lockb", "**/deno.lock"];
|
|
3
35
|
|
|
4
36
|
// src/rules/common.ts
|
|
5
37
|
var commonRules = {
|
|
6
|
-
//
|
|
38
|
+
// 要求数组回调在所有可到达分支返回值,避免 map/filter 等调用静默产生 undefined。
|
|
7
39
|
"array-callback-return": "error",
|
|
8
|
-
//
|
|
9
|
-
"block-scoped-var": "error",
|
|
10
|
-
// 禁止使用 alert、confirm 和 prompt 等浏览器弹出对话框
|
|
40
|
+
// 浏览器弹窗通常不适合生产代码;使用 warn 允许原型调试,同时确保发布前能够被发现。
|
|
11
41
|
"no-alert": "warn",
|
|
12
|
-
//
|
|
42
|
+
// switch 的 case 不创建词法作用域;要求用花括号包裹声明,避免跨 case 冲突。
|
|
13
43
|
"no-case-declarations": "error",
|
|
14
|
-
//
|
|
44
|
+
// 禁止反斜杠续行字符串,优先使用可读性更好的模板字符串。
|
|
15
45
|
"no-multi-str": "error",
|
|
16
|
-
//
|
|
46
|
+
// with 会让标识符解析不可预测,并且在严格模式和 ESM 中不可用。
|
|
17
47
|
"no-with": "error",
|
|
18
|
-
//
|
|
19
|
-
"no-void":
|
|
20
|
-
// 禁止多个空行
|
|
21
|
-
"@stylistic/no-multiple-empty-lines": [
|
|
48
|
+
// 允许用 `void promise` 明确忽略 Promise,但禁止在普通表达式中滥用 void。
|
|
49
|
+
"no-void": [
|
|
22
50
|
"error",
|
|
23
51
|
{
|
|
24
|
-
|
|
25
|
-
max: 1
|
|
52
|
+
allowAsStatement: true
|
|
26
53
|
}
|
|
27
54
|
],
|
|
28
|
-
//
|
|
55
|
+
// 要求严格相等;保留 `value == null` 同时判断 null/undefined 的常用写法。
|
|
56
|
+
eqeqeq: ["error", "always", { null: "ignore" }],
|
|
57
|
+
// 幂运算统一使用 **,减少 Math.pow 嵌套并保持现代语法风格。
|
|
58
|
+
"prefer-exponentiation-operator": "error",
|
|
59
|
+
// 使用 Object.hasOwn,避免对象覆盖或缺少 hasOwnProperty 时产生异常。
|
|
60
|
+
"prefer-object-has-own": "error",
|
|
61
|
+
// [可自动修复] 声明间顺序交给 import-x;这里只排序同一 import 的成员。
|
|
29
62
|
"sort-imports": [
|
|
30
63
|
"warn",
|
|
31
64
|
{
|
|
32
|
-
// 不忽略导入语句中模块名的大小写
|
|
33
65
|
ignoreCase: false,
|
|
34
|
-
// 忽略导入声明的排序
|
|
35
66
|
ignoreDeclarationSort: true,
|
|
36
|
-
// 不忽略导入成员的排序
|
|
37
67
|
ignoreMemberSort: false,
|
|
38
|
-
// 成员语法排序顺序
|
|
39
68
|
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
|
|
40
|
-
// 不允许分组导入
|
|
41
69
|
allowSeparatedGroups: false
|
|
42
70
|
}
|
|
43
|
-
]
|
|
44
|
-
// 强制在数学运算中使用 ** 运算符代替 Math.pow()
|
|
45
|
-
"prefer-exponentiation-operator": "error"
|
|
71
|
+
]
|
|
46
72
|
};
|
|
47
73
|
|
|
48
74
|
// src/rules/import.ts
|
|
49
|
-
var importUseLodashUnifiedRules = {
|
|
50
|
-
// 限制某些模块导入
|
|
51
|
-
"no-restricted-imports": [
|
|
52
|
-
"error",
|
|
53
|
-
{
|
|
54
|
-
paths: [
|
|
55
|
-
{ name: "lodash", message: "Use lodash-unified instead." },
|
|
56
|
-
{ name: "lodash-es", message: "Use lodash-unified instead." }
|
|
57
|
-
],
|
|
58
|
-
patterns: [
|
|
59
|
-
{
|
|
60
|
-
group: ["lodash/*", "lodash-es/*"],
|
|
61
|
-
message: "Use lodash-unified instead."
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
]
|
|
66
|
-
};
|
|
67
75
|
var importRules = {
|
|
68
|
-
//
|
|
76
|
+
// import 必须位于其他语句之前,避免模块依赖散落在执行逻辑中。
|
|
69
77
|
"import-x/first": "error",
|
|
70
|
-
//
|
|
78
|
+
// 合并同一模块的重复 import,避免绑定分散或副作用被误读。
|
|
71
79
|
"import-x/no-duplicates": "error",
|
|
72
|
-
//
|
|
80
|
+
// [高影响][可自动修复] 按来源分组并排序;带副作用的裸 import 仅报告,人工移动前必须确认执行顺序。
|
|
73
81
|
"import-x/order": [
|
|
74
82
|
"error",
|
|
75
83
|
{
|
|
76
|
-
// 导入模块分组
|
|
77
84
|
groups: [
|
|
78
85
|
// Node.js 内置模块
|
|
79
86
|
"builtin",
|
|
80
|
-
//
|
|
87
|
+
// 第三方依赖
|
|
81
88
|
"external",
|
|
82
|
-
//
|
|
89
|
+
// 项目内部别名模块
|
|
83
90
|
"internal",
|
|
84
|
-
//
|
|
91
|
+
// 父级目录模块
|
|
85
92
|
"parent",
|
|
86
|
-
//
|
|
93
|
+
// 同级目录模块
|
|
87
94
|
"sibling",
|
|
88
|
-
//
|
|
95
|
+
// 当前目录入口模块
|
|
89
96
|
"index",
|
|
97
|
+
// TypeScript import = require() 导入
|
|
90
98
|
"object",
|
|
99
|
+
// TypeScript 类型导入
|
|
91
100
|
"type",
|
|
101
|
+
// 无法识别分类的导入
|
|
92
102
|
"unknown"
|
|
93
103
|
],
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
group: "external",
|
|
98
|
-
position: "before"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
pattern: "vue",
|
|
102
|
-
group: "external",
|
|
103
|
-
position: "before"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
pattern: "@vue/**",
|
|
107
|
-
group: "external",
|
|
108
|
-
position: "before"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
pattern: "element-plus",
|
|
112
|
-
group: "external",
|
|
113
|
-
position: "before"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
pattern: "@element-plus/**",
|
|
117
|
-
group: "external",
|
|
118
|
-
position: "before"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
pattern: "fast-element-plus",
|
|
122
|
-
group: "external",
|
|
123
|
-
position: "before"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
pattern: "@fast-element-plus/**",
|
|
127
|
-
group: "external",
|
|
128
|
-
position: "before"
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
pattern: "@fast-china/**",
|
|
132
|
-
group: "external",
|
|
133
|
-
position: "before"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
pattern: "lodash",
|
|
137
|
-
group: "external",
|
|
138
|
-
position: "before"
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
pattern: "lodash-es",
|
|
142
|
-
group: "external",
|
|
143
|
-
position: "before"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
pattern: "lodash-unified",
|
|
147
|
-
group: "external",
|
|
148
|
-
position: "before"
|
|
149
|
-
}
|
|
150
|
-
],
|
|
151
|
-
pathGroupsExcludedImportTypes: ["type"],
|
|
152
|
-
// 禁止不同组之间进行换行
|
|
153
|
-
"newlines-between": "never",
|
|
154
|
-
// 根据字母顺序对每个组内的顺序进行排序
|
|
104
|
+
// 不同 import 分组之间必须保留一个空行
|
|
105
|
+
"newlines-between": "always",
|
|
106
|
+
// 同一分组内按照模块路径字母升序排列
|
|
155
107
|
alphabetize: {
|
|
156
108
|
order: "asc",
|
|
157
109
|
caseInsensitive: true
|
|
158
|
-
}
|
|
110
|
+
},
|
|
111
|
+
// 对没有赋值给变量的副作用导入进行排序检查
|
|
112
|
+
warnOnUnassignedImports: true
|
|
159
113
|
}
|
|
160
114
|
],
|
|
161
|
-
//
|
|
115
|
+
// [默认关闭] Vite/TypeScript 别名由项目解析器校验,避免共享配置绑定特定 resolver。
|
|
162
116
|
"import-x/no-unresolved": "off",
|
|
163
|
-
//
|
|
117
|
+
// [默认关闭] 未配置 resolver 时,namespace 导出的静态分析容易产生误报。
|
|
164
118
|
"import-x/namespace": "off",
|
|
165
|
-
//
|
|
119
|
+
// [默认关闭] 未配置 resolver 时,默认导出的静态分析容易产生误报。
|
|
166
120
|
"import-x/default": "off",
|
|
167
|
-
//
|
|
121
|
+
// [默认关闭] 不限制同时存在默认导出与相近命名导出的模块 API 风格。
|
|
168
122
|
"import-x/no-named-as-default": "off",
|
|
169
|
-
//
|
|
123
|
+
// [默认关闭] 不限制通过默认导入对象访问同名属性的项目 API 风格。
|
|
170
124
|
"import-x/no-named-as-default-member": "off",
|
|
171
|
-
//
|
|
125
|
+
// [默认关闭] 未配置 resolver 时,命名导出的静态分析容易产生误报。
|
|
172
126
|
"import-x/named": "off"
|
|
173
127
|
};
|
|
174
128
|
|
|
175
129
|
// src/rules/javascript.ts
|
|
176
130
|
var javascriptRules = {
|
|
177
|
-
//
|
|
178
|
-
// 强制使用 camelCase 命名风格
|
|
179
|
-
camelcase: [
|
|
180
|
-
"error",
|
|
181
|
-
{
|
|
182
|
-
// 允许对象属性使用非 camelCase 风格
|
|
183
|
-
properties: "never"
|
|
184
|
-
}
|
|
185
|
-
],
|
|
186
|
-
// 禁止使用控制台
|
|
131
|
+
// 控制台调用在应用源码中需要人工确认;warn/error 仍可用于必要的诊断输出。
|
|
187
132
|
"no-console": [
|
|
188
133
|
"warn",
|
|
189
134
|
{
|
|
190
|
-
// 允许除 warn/error 之外的其他 console.xx 方法
|
|
191
135
|
allow: ["warn", "error"]
|
|
192
136
|
}
|
|
193
137
|
],
|
|
194
|
-
//
|
|
195
|
-
"no-debugger": "
|
|
196
|
-
//
|
|
138
|
+
// 防止调试断点进入发布代码并中断运行。
|
|
139
|
+
"no-debugger": "error",
|
|
140
|
+
// 禁止意外的恒定条件,但允许 while (true) 等有明确退出逻辑的循环。
|
|
197
141
|
"no-constant-condition": [
|
|
198
142
|
"error",
|
|
199
143
|
{
|
|
200
|
-
// 允许在循环语句中使用常量条件
|
|
201
144
|
checkLoops: false
|
|
202
145
|
}
|
|
203
146
|
],
|
|
204
|
-
//
|
|
205
|
-
"no-restricted-syntax": [
|
|
206
|
-
|
|
207
|
-
// 禁止使用标记语句(labeled statements)
|
|
208
|
-
"LabeledStatement",
|
|
209
|
-
// 禁止使用 with 语句
|
|
210
|
-
"WithStatement"
|
|
211
|
-
],
|
|
212
|
-
// 禁止在 return 语句中使用 await
|
|
213
|
-
"@typescript-eslint/return-await": "error",
|
|
214
|
-
// 禁止使用 var 关键字,强制使用 let 或 const
|
|
147
|
+
// [高影响] 禁止标签语句;包含多层循环 labeled break/continue 的代码需先重构控制流。
|
|
148
|
+
"no-restricted-syntax": ["error", "LabeledStatement"],
|
|
149
|
+
// [高影响][可自动修复] 使用 let/const 替代 var;首次启用需复核循环闭包和声明提升行为。
|
|
215
150
|
"no-var": "error",
|
|
216
|
-
//
|
|
151
|
+
// 禁止无说明的空代码块;允许用于“忽略失败”语义的空 catch。
|
|
217
152
|
"no-empty": [
|
|
218
153
|
"error",
|
|
219
154
|
{
|
|
220
|
-
// 允许空的 catch 块
|
|
221
155
|
allowEmptyCatch: true
|
|
222
156
|
}
|
|
223
157
|
],
|
|
224
|
-
//
|
|
158
|
+
// 拒绝肉眼难以识别、可能导致解析差异的非常规空白字符。
|
|
225
159
|
"no-irregular-whitespace": "error",
|
|
226
|
-
//
|
|
227
|
-
"no-use-before-define":
|
|
228
|
-
|
|
160
|
+
// 变量和类先声明后使用;函数声明允许提升。warn 保留函数式组合和循环依赖重构空间。
|
|
161
|
+
"no-use-before-define": [
|
|
162
|
+
"warn",
|
|
163
|
+
{
|
|
164
|
+
classes: true,
|
|
165
|
+
functions: false,
|
|
166
|
+
variables: true
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
// [可自动修复] 能保持引用不变的变量优先使用 const;读取发生在赋值前时不做不可靠判断。
|
|
229
170
|
"prefer-const": [
|
|
230
171
|
"warn",
|
|
231
172
|
{
|
|
232
|
-
// 在解构赋值时也推荐使用 const
|
|
233
173
|
destructuring: "all",
|
|
234
|
-
// 允许在变量首次赋值前读取变量的值
|
|
235
174
|
ignoreReadBeforeAssign: true
|
|
236
175
|
}
|
|
237
176
|
],
|
|
238
|
-
//
|
|
177
|
+
// [高影响][可自动修复] 优先箭头回调;批量修复后应复核 this/arguments 与函数名栈信息。
|
|
239
178
|
"prefer-arrow-callback": [
|
|
240
179
|
"error",
|
|
241
180
|
{
|
|
242
|
-
// 不允许使用命名函数作为回调函数
|
|
243
181
|
allowNamedFunctions: false,
|
|
244
|
-
// 允许在箭头函数中使用 this 绑定的上下文
|
|
245
182
|
allowUnboundThis: true
|
|
246
183
|
}
|
|
247
184
|
],
|
|
248
|
-
//
|
|
185
|
+
// [可自动修复] 属性和值同名时使用对象简写,带引号键名不强制改写。
|
|
249
186
|
"object-shorthand": [
|
|
250
187
|
"error",
|
|
251
188
|
"always",
|
|
252
189
|
{
|
|
253
|
-
// 不忽略构造函数中的属性简写
|
|
254
190
|
ignoreConstructors: false,
|
|
255
|
-
// 强制避免在属性名中使用引号
|
|
256
191
|
avoidQuotes: true
|
|
257
192
|
}
|
|
258
193
|
],
|
|
259
|
-
//
|
|
194
|
+
// [高影响][可自动修复] 使用 ||=、&&=、??=;涉及 getter/Proxy 的代码应复核求值次数。
|
|
195
|
+
"logical-assignment-operators": ["error", "always", { enforceForIfStatements: true }],
|
|
196
|
+
// [可自动修复] 合并对象时优先展开语法,避免 Object.assign 的额外目标对象样板。
|
|
197
|
+
"prefer-object-spread": "error",
|
|
198
|
+
// 可变参数函数优先 rest 参数,避免依赖类数组 arguments;该规则只报告,不自动改写签名。
|
|
260
199
|
"prefer-rest-params": "error",
|
|
261
|
-
//
|
|
200
|
+
// 调用可迭代对象时优先 spread;该规则只报告,避免自动改变 apply 的 this 语义。
|
|
262
201
|
"prefer-spread": "error",
|
|
263
|
-
//
|
|
202
|
+
// [可自动修复] 字符串拼接优先模板字符串,便于阅读和多段插值。
|
|
264
203
|
"prefer-template": "error",
|
|
265
|
-
//
|
|
204
|
+
// 同一作用域禁止重复声明,避免后声明遮盖前声明。
|
|
266
205
|
"no-redeclare": "error"
|
|
267
206
|
};
|
|
268
207
|
|
|
208
|
+
// src/rules/lodash.ts
|
|
209
|
+
var preferLodashUnifiedRules = {
|
|
210
|
+
// [高影响][按需启用] 禁止混用 lodash 与 lodash-es,避免同一项目维护多套等价依赖入口。
|
|
211
|
+
"no-restricted-imports": [
|
|
212
|
+
"error",
|
|
213
|
+
{
|
|
214
|
+
paths: [
|
|
215
|
+
{
|
|
216
|
+
name: "lodash",
|
|
217
|
+
message: 'Use "lodash-unified" consistently instead of "lodash".'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "lodash-es",
|
|
221
|
+
message: 'Use "lodash-unified" consistently instead of "lodash-es".'
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
patterns: [
|
|
225
|
+
{
|
|
226
|
+
group: ["lodash/*", "lodash-es/*"],
|
|
227
|
+
message: 'Use exports from "lodash-unified" instead of Lodash subpath imports.'
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
};
|
|
233
|
+
var preferLodashRules = {
|
|
234
|
+
// [高影响][按需启用] 禁止混用 lodash-es 与 lodash-unified,保持运行时和类型来源一致。
|
|
235
|
+
"no-restricted-imports": [
|
|
236
|
+
"error",
|
|
237
|
+
{
|
|
238
|
+
paths: [
|
|
239
|
+
{
|
|
240
|
+
name: "lodash-es",
|
|
241
|
+
message: 'Use "lodash" consistently instead of "lodash-es".'
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "lodash-unified",
|
|
245
|
+
message: 'Use "lodash" consistently instead of "lodash-unified".'
|
|
246
|
+
}
|
|
247
|
+
],
|
|
248
|
+
patterns: [
|
|
249
|
+
{
|
|
250
|
+
group: ["lodash-es/*", "lodash-unified/*"],
|
|
251
|
+
message: 'Use "lodash" or a "lodash/*" subpath consistently.'
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
};
|
|
257
|
+
|
|
269
258
|
// src/rules/sort-package.ts
|
|
270
259
|
var packageJsonSortRules = {
|
|
260
|
+
// [高影响][可自动修复][按需启用] npm 的 files 清单按字母排序;数组顺序不改打包集合,但首次 diff 较大。
|
|
271
261
|
"jsonc/sort-array-values": [
|
|
272
262
|
"error",
|
|
273
263
|
{
|
|
@@ -275,8 +265,10 @@ var packageJsonSortRules = {
|
|
|
275
265
|
pathPattern: "^files$"
|
|
276
266
|
}
|
|
277
267
|
],
|
|
268
|
+
// [高影响][可自动修复][按需启用] 仅排序明确安全的 package.json 区域,不进入 exports 条件对象。
|
|
278
269
|
"jsonc/sort-keys": [
|
|
279
270
|
"error",
|
|
271
|
+
// 根字段按常见阅读顺序组织,减少不同项目之间的清单噪声。
|
|
280
272
|
{
|
|
281
273
|
order: [
|
|
282
274
|
"name",
|
|
@@ -324,14 +316,12 @@ var packageJsonSortRules = {
|
|
|
324
316
|
],
|
|
325
317
|
pathPattern: "^$"
|
|
326
318
|
},
|
|
319
|
+
// 各类依赖映射按包名排序,方便发现重复或异常依赖。
|
|
327
320
|
{
|
|
328
321
|
order: { type: "asc" },
|
|
329
322
|
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
|
|
330
323
|
},
|
|
331
|
-
|
|
332
|
-
order: ["types", "require", "import", "default"],
|
|
333
|
-
pathPattern: "^exports.*$"
|
|
334
|
-
},
|
|
324
|
+
// overrides/resolutions 只排序直接键;修改前仍应关注包管理器的模式匹配语义。
|
|
335
325
|
{
|
|
336
326
|
order: { type: "asc" },
|
|
337
327
|
pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
|
|
@@ -341,14 +331,17 @@ var packageJsonSortRules = {
|
|
|
341
331
|
|
|
342
332
|
// src/rules/sort-tsconfig.ts
|
|
343
333
|
var tsconfigJsonSortRules = {
|
|
344
|
-
//
|
|
334
|
+
// tsconfig 是 JSONC,注释用于解释不直观的编译器取舍,必须保留。
|
|
345
335
|
"jsonc/no-comments": "off",
|
|
336
|
+
// [高影响][可自动修复][按需启用] 只调整顶层和 compilerOptions 的键顺序,不改写任何选项值或数组。
|
|
346
337
|
"jsonc/sort-keys": [
|
|
347
338
|
"error",
|
|
339
|
+
// 顶层按继承、选项、项目引用和文件范围的阅读顺序排列。
|
|
348
340
|
{
|
|
349
341
|
order: ["extends", "compilerOptions", "references", "files", "include", "exclude"],
|
|
350
342
|
pathPattern: "^$"
|
|
351
343
|
},
|
|
344
|
+
// compilerOptions 的顺序跟随 TypeScript 文档主题,便于检索和代码审查。
|
|
352
345
|
{
|
|
353
346
|
order: [
|
|
354
347
|
/* Projects */
|
|
@@ -456,110 +449,76 @@ var tsconfigJsonSortRules = {
|
|
|
456
449
|
|
|
457
450
|
// src/rules/typescript.ts
|
|
458
451
|
var typescriptRules = {
|
|
459
|
-
//
|
|
460
|
-
|
|
461
|
-
|
|
452
|
+
// 使用 TypeScript 版本避免核心规则误判声明合并、类型和值的同名声明。
|
|
453
|
+
"@typescript-eslint/no-redeclare": "error",
|
|
454
|
+
// [高影响][可自动修复] 未使用符号视为错误;以下划线开头可显式表示参数或变量被有意忽略。
|
|
455
|
+
"@typescript-eslint/no-unused-vars": [
|
|
462
456
|
"error",
|
|
463
457
|
{
|
|
464
|
-
|
|
458
|
+
args: "after-used",
|
|
459
|
+
argsIgnorePattern: "^_",
|
|
460
|
+
caughtErrors: "all",
|
|
461
|
+
caughtErrorsIgnorePattern: "^_",
|
|
462
|
+
ignoreRestSiblings: true,
|
|
463
|
+
varsIgnorePattern: "^_"
|
|
465
464
|
}
|
|
466
465
|
],
|
|
467
|
-
//
|
|
468
|
-
"@typescript-eslint/explicit-function-return-type": "error",
|
|
469
|
-
// 禁止在同一作用域中重新声明 TypeScript 变量
|
|
470
|
-
"@typescript-eslint/no-redeclare": "error",
|
|
471
|
-
// 禁止定义未使用的变量,方法参数排除。
|
|
472
|
-
"@typescript-eslint/no-unused-vars": ["error", { args: "none" }],
|
|
473
|
-
// 允许使用自定义TypeScript模块和命名空间
|
|
466
|
+
// [默认关闭] 声明文件、全局扩展和部分 SDK 仍需要 namespace。
|
|
474
467
|
"@typescript-eslint/no-namespace": "off",
|
|
475
|
-
//
|
|
476
|
-
"@typescript-eslint/no-explicit-any": "
|
|
477
|
-
//
|
|
468
|
+
// any 会绕过类型检查,但在第三方边界和渐进式类型完善中有合理用途,因此只警告。
|
|
469
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
470
|
+
// [高影响] 默认要求 ESM import;CommonJS、动态加载或工具链互操作代码可能需要按文件关闭。
|
|
478
471
|
"@typescript-eslint/no-require-imports": "error",
|
|
479
|
-
//
|
|
480
|
-
"@typescript-eslint/no-empty-function": ["error", { allow: [] }],
|
|
481
|
-
// 禁止无用的表达式
|
|
472
|
+
// 使用 TS 版本识别类型断言等语法;允许常见的短路和三元表达式调用模式。
|
|
482
473
|
"@typescript-eslint/no-unused-expressions": [
|
|
483
474
|
"error",
|
|
484
475
|
{
|
|
485
|
-
// 允许短路操作符(&& 和 ||)中的无副作用表达式
|
|
486
476
|
allowShortCircuit: true,
|
|
487
|
-
// 允许三元操作符中的无副作用表达式
|
|
488
477
|
allowTernary: true
|
|
489
478
|
}
|
|
490
479
|
],
|
|
491
|
-
//
|
|
480
|
+
// [可自动修复] 删除可由 TypeScript 明确推断的原始值类型标注,减少重复信息。
|
|
492
481
|
"@typescript-eslint/no-inferrable-types": "error",
|
|
493
|
-
//
|
|
494
|
-
"@typescript-eslint/no-non-null-assertion": "
|
|
495
|
-
//
|
|
482
|
+
// 非空断言可能隐藏空值缺陷;以警告提示逐步消除,避免一次性产生大量阻断错误。
|
|
483
|
+
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
484
|
+
// 可选链之后再做非空断言逻辑矛盾,通常表示边界条件设计有误。
|
|
496
485
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
|
|
497
|
-
//
|
|
498
|
-
"@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": false }],
|
|
499
|
-
// 一致地使用 TypeScript 类型导入
|
|
486
|
+
// [高影响][可自动修复] 类型依赖改用内联 type import;需复核仅靠 import 触发的模块副作用。
|
|
500
487
|
"@typescript-eslint/consistent-type-imports": [
|
|
501
488
|
"error",
|
|
502
489
|
{
|
|
503
|
-
|
|
504
|
-
|
|
490
|
+
disallowTypeAnnotations: false,
|
|
491
|
+
fixStyle: "inline-type-imports",
|
|
492
|
+
prefer: "type-imports"
|
|
505
493
|
}
|
|
506
494
|
]
|
|
507
495
|
};
|
|
508
496
|
|
|
509
497
|
// src/rules/vue.ts
|
|
510
498
|
var vueRules = {
|
|
511
|
-
//
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
// 禁用所有 props 必填时,必须提供默认值
|
|
499
|
+
// [安全关注] v-html 可能引入 XSS;保留 warn 以兼容经过净化的富文本场景。
|
|
500
|
+
"vue/no-v-html": "warn",
|
|
501
|
+
// [默认关闭] TypeScript 类型 props 和 required 声明已能表达可选性,不强制每个可选 prop 提供默认值。
|
|
515
502
|
"vue/require-default-prop": "off",
|
|
516
|
-
//
|
|
503
|
+
// [高影响] 组件必须声明对外事件;首次启用时会暴露未建模的公共事件 API。
|
|
517
504
|
"vue/require-explicit-emits": "error",
|
|
518
|
-
//
|
|
505
|
+
// [默认关闭] 允许 App、Layout 等约定俗成的单词组件名。
|
|
519
506
|
"vue/multi-word-component-names": "off",
|
|
520
|
-
//
|
|
521
|
-
"vue/prefer-import-from-vue": "
|
|
522
|
-
//
|
|
523
|
-
"vue/attribute-hyphenation": [
|
|
524
|
-
"error",
|
|
525
|
-
"never",
|
|
526
|
-
{
|
|
527
|
-
ignore: [
|
|
528
|
-
// 忽略 Element-Plus 加载文案"element-loading-text"
|
|
529
|
-
"element-loading-text",
|
|
530
|
-
// 忽略 UniApp view 标签的一些属性
|
|
531
|
-
"hover-class",
|
|
532
|
-
"hover-stop-propagation",
|
|
533
|
-
"hover-start-time",
|
|
534
|
-
"hover-stay-time"
|
|
535
|
-
]
|
|
536
|
-
}
|
|
537
|
-
],
|
|
538
|
-
// 禁止重复的字段名
|
|
507
|
+
// 优先从 vue 入口导入由 Vue 重新导出的 API,避免依赖内部包边界。
|
|
508
|
+
"vue/prefer-import-from-vue": "warn",
|
|
509
|
+
// 防止 props、data、computed、methods 等组件命名空间出现冲突。
|
|
539
510
|
"vue/no-dupe-keys": "error",
|
|
540
|
-
//
|
|
511
|
+
// [高影响] 禁止组件直接修改 props,要求通过事件或本地状态维持单向数据流。
|
|
541
512
|
"vue/no-mutating-props": "error",
|
|
542
|
-
//
|
|
513
|
+
// 避免自定义组件名与 Vue 内置组件冲突。
|
|
543
514
|
"vue/no-reserved-component-names": "error",
|
|
544
|
-
//
|
|
545
|
-
"vue/no-v-text-v-html-on-component": "
|
|
546
|
-
//
|
|
547
|
-
// "vue/script-setup-uses-vars": "error",
|
|
548
|
-
// 强制自定义事件名称使用 camelCase 风格命名
|
|
515
|
+
// [安全关注] 禁止在组件节点上使用 v-text/v-html,避免覆盖组件内容和模糊数据边界。
|
|
516
|
+
"vue/no-v-text-v-html-on-component": "error",
|
|
517
|
+
// 统一模板与脚本中的自定义事件名称为 camelCase。
|
|
549
518
|
"vue/custom-event-name-casing": ["error", "camelCase"],
|
|
550
|
-
//
|
|
519
|
+
// [默认关闭] 允许在一个 SFC 中声明仅供当前文件使用的小型辅助组件。
|
|
551
520
|
"vue/one-component-per-file": "off",
|
|
552
|
-
//
|
|
553
|
-
"vue/html-closing-bracket-newline": [
|
|
554
|
-
"error",
|
|
555
|
-
{
|
|
556
|
-
// 强制要求当 HTML 元素跨多行时,闭合标签必须出现在新的一行上
|
|
557
|
-
multiline: "always",
|
|
558
|
-
// 强制要求当 HTML 元素只有一行时,闭合标签应与开始标签在同一行上
|
|
559
|
-
singleline: "never"
|
|
560
|
-
}
|
|
561
|
-
],
|
|
562
|
-
// 强制 Vue 模板中 HTML 元素的属性按照指定的顺序排列
|
|
521
|
+
// [高影响][可自动修复] 统一模板属性分组;首次启用可能产生大量仅排序的模板差异。
|
|
563
522
|
"vue/attributes-order": [
|
|
564
523
|
"error",
|
|
565
524
|
{
|
|
@@ -569,409 +528,282 @@ var vueRules = {
|
|
|
569
528
|
};
|
|
570
529
|
|
|
571
530
|
// src/configs/common.ts
|
|
572
|
-
var
|
|
531
|
+
var createBaseConfigs = (files = GLOBS_CODE) => defineConfig([
|
|
573
532
|
{
|
|
574
533
|
name: "@fast-china/common",
|
|
534
|
+
files: [...files],
|
|
535
|
+
linterOptions: {
|
|
536
|
+
reportUnusedDisableDirectives: "error"
|
|
537
|
+
},
|
|
575
538
|
rules: commonRules
|
|
576
539
|
}
|
|
577
540
|
]);
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
"**/*.min.*",
|
|
624
|
-
"**/LICENSE*",
|
|
625
|
-
"**/__snapshots__",
|
|
626
|
-
"**/auto-import?(s).d.ts",
|
|
627
|
-
"**/components.d.ts"
|
|
628
|
-
]
|
|
629
|
-
},
|
|
541
|
+
var createEnvironmentConfigs = ({
|
|
542
|
+
environment = "browser",
|
|
543
|
+
files = GLOBS_CODE,
|
|
544
|
+
nodeFiles = GLOBS_JAVASCRIPT,
|
|
545
|
+
globals: projectGlobals = {}
|
|
546
|
+
} = {}) => {
|
|
547
|
+
const runtimeGlobals = {
|
|
548
|
+
...environment !== "node" ? globals.browser : {},
|
|
549
|
+
...environment !== "browser" ? globals.node : {},
|
|
550
|
+
...projectGlobals
|
|
551
|
+
};
|
|
552
|
+
const nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));
|
|
553
|
+
return defineConfig([
|
|
554
|
+
{
|
|
555
|
+
name: `@fast-china/globals/${environment}`,
|
|
556
|
+
files: [...files],
|
|
557
|
+
languageOptions: {
|
|
558
|
+
globals: runtimeGlobals
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
name: "@fast-china/globals/node-tooling",
|
|
563
|
+
files: nodeToolingFiles,
|
|
564
|
+
languageOptions: {
|
|
565
|
+
globals: globals.node
|
|
566
|
+
},
|
|
567
|
+
rules: {
|
|
568
|
+
"no-console": "off"
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
]);
|
|
572
|
+
};
|
|
573
|
+
var DEFAULT_IGNORE_PATTERNS = Object.freeze([
|
|
574
|
+
"**/node_modules/**",
|
|
575
|
+
"**/{dist,build,coverage,output,temp,tmp}/**",
|
|
576
|
+
"**/{.cache,.nuxt,.output,.vercel,.nitro}/**",
|
|
577
|
+
"**/{.vitepress/cache,.vite-inspect}/**",
|
|
578
|
+
"**/__snapshots__/**",
|
|
579
|
+
"**/*.min.*",
|
|
580
|
+
"**/auto-import?(s).d.ts",
|
|
581
|
+
"**/components.d.ts",
|
|
582
|
+
...GLOBS_LOCKFILES
|
|
583
|
+
]);
|
|
584
|
+
var createGlobalIgnores = (additionalPatterns = []) => globalIgnores([...DEFAULT_IGNORE_PATTERNS, ...additionalPatterns], "@fast-china/ignores/global");
|
|
585
|
+
var createGitignoreConfigs = () => defineConfig([
|
|
630
586
|
{
|
|
631
587
|
name: "@fast-china/ignores/git",
|
|
632
588
|
...eslintConfigFlatGitignore({ strict: false })
|
|
633
589
|
}
|
|
634
590
|
]);
|
|
635
|
-
|
|
636
|
-
// src/configs/import.ts
|
|
637
|
-
import { defineConfig as defineConfig3 } from "eslint/config";
|
|
638
|
-
import eslintPluginImportX from "eslint-plugin-import-x";
|
|
639
|
-
var importConfigs = defineConfig3([
|
|
591
|
+
var createImportConfigs = (files = GLOBS_CODE) => defineConfig([
|
|
640
592
|
{
|
|
641
593
|
name: "@fast-china/import",
|
|
642
|
-
|
|
643
|
-
extends: [eslintPluginImportX.flatConfigs.recommended
|
|
644
|
-
|
|
645
|
-
// 确保 ESLint 和 eslint-plugin-import 能够正确解析项目中的所有相关文件类型
|
|
646
|
-
"import-x/resolver": {
|
|
647
|
-
node: {
|
|
648
|
-
alwaysTryTypes: true,
|
|
649
|
-
extensions: [CONST_JS, CONST_JSX, CONST_TS, CONST_TSX, CONST_DTS]
|
|
650
|
-
},
|
|
651
|
-
typescript: {
|
|
652
|
-
alwaysTryTypes: true,
|
|
653
|
-
project: ["./tsconfig.json", "./tsconfig.*.json", "./packages/*/tsconfig.json", "./packages/*/tsconfig.*.json"]
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
rules: {
|
|
658
|
-
...importRules,
|
|
659
|
-
...importUseLodashUnifiedRules
|
|
660
|
-
}
|
|
594
|
+
files: [...files],
|
|
595
|
+
extends: [eslintPluginImportX.flatConfigs.recommended],
|
|
596
|
+
rules: importRules
|
|
661
597
|
}
|
|
662
598
|
]);
|
|
663
|
-
|
|
664
|
-
// src/configs/javascript.ts
|
|
665
|
-
import eslint from "@eslint/js";
|
|
666
|
-
import { defineConfig as defineConfig4 } from "eslint/config";
|
|
667
|
-
import globals from "globals";
|
|
668
|
-
var javascriptConfigs = defineConfig4([
|
|
599
|
+
var createJavaScriptConfigs = (files = GLOBS_JAVASCRIPT) => defineConfig([
|
|
669
600
|
{
|
|
670
601
|
name: "@fast-china/javascript",
|
|
671
|
-
|
|
602
|
+
files: [...files],
|
|
672
603
|
extends: [eslint.configs.recommended],
|
|
673
604
|
languageOptions: {
|
|
674
|
-
// 允许使用最新的 ECMAScript 语法特性
|
|
675
605
|
ecmaVersion: "latest",
|
|
676
|
-
globals: {
|
|
677
|
-
...globals.browser,
|
|
678
|
-
...globals.es2022,
|
|
679
|
-
...globals.node
|
|
680
|
-
},
|
|
681
606
|
parserOptions: {
|
|
682
607
|
ecmaFeatures: {
|
|
683
|
-
//
|
|
608
|
+
// 普通 `.jsx` 文件需要显式开启 JSX 语法解析。
|
|
684
609
|
jsx: true
|
|
685
|
-
}
|
|
686
|
-
sourceType: "module"
|
|
610
|
+
}
|
|
687
611
|
}
|
|
688
612
|
},
|
|
689
613
|
rules: javascriptRules
|
|
690
|
-
}
|
|
614
|
+
}
|
|
615
|
+
]);
|
|
616
|
+
var createJsonConfigs = () => defineConfig([
|
|
691
617
|
{
|
|
692
|
-
name: "@fast-china/
|
|
693
|
-
files: [
|
|
694
|
-
|
|
695
|
-
// 使用使用控制台
|
|
696
|
-
"no-console": "off",
|
|
697
|
-
// 关闭 - 禁止使用未声明的变量,除非/*global *\/注释中提到
|
|
698
|
-
"no-undef": "off",
|
|
699
|
-
// 关闭 - 禁用对无法解析的模块导入的检查
|
|
700
|
-
"import/no-unresolved": "off",
|
|
701
|
-
// 关闭 - 禁止在文件中重复导入相同的模块
|
|
702
|
-
"import/no-duplicates": "off"
|
|
703
|
-
}
|
|
618
|
+
name: "@fast-china/json/json",
|
|
619
|
+
files: [GLOB_JSON],
|
|
620
|
+
extends: [eslintPluginJsonc.configs["flat/recommended-with-json"]]
|
|
704
621
|
},
|
|
705
622
|
{
|
|
706
|
-
name: "@fast-china/
|
|
707
|
-
files: [
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
"no-console": "off"
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
]);
|
|
714
|
-
|
|
715
|
-
// src/configs/json.ts
|
|
716
|
-
import { defineConfig as defineConfig5 } from "eslint/config";
|
|
717
|
-
import eslintPluginJsonc from "eslint-plugin-jsonc";
|
|
718
|
-
import * as jsoncEslintParser from "jsonc-eslint-parser";
|
|
719
|
-
var jsonConfigs = defineConfig5([
|
|
623
|
+
name: "@fast-china/json/jsonc",
|
|
624
|
+
files: [GLOB_JSONC],
|
|
625
|
+
extends: [eslintPluginJsonc.configs["flat/recommended-with-jsonc"]]
|
|
626
|
+
},
|
|
720
627
|
{
|
|
721
|
-
name: "@fast-china/json",
|
|
722
|
-
files: [
|
|
723
|
-
|
|
724
|
-
extends: [
|
|
725
|
-
...eslintPluginJsonc.configs["flat/recommended-with-json"],
|
|
726
|
-
...eslintPluginJsonc.configs["flat/recommended-with-jsonc"],
|
|
727
|
-
...eslintPluginJsonc.configs["flat/recommended-with-json5"]
|
|
728
|
-
],
|
|
729
|
-
languageOptions: {
|
|
730
|
-
parser: jsoncEslintParser
|
|
731
|
-
}
|
|
628
|
+
name: "@fast-china/json/json5",
|
|
629
|
+
files: [GLOB_JSON5],
|
|
630
|
+
extends: [eslintPluginJsonc.configs["flat/recommended-with-json5"]]
|
|
732
631
|
},
|
|
733
632
|
{
|
|
734
|
-
name: "@fast-china/json/settings",
|
|
633
|
+
name: "@fast-china/json/vscode-settings",
|
|
735
634
|
files: ["**/.vscode/settings.json"],
|
|
736
635
|
rules: {
|
|
737
|
-
//
|
|
636
|
+
// VS Code 的 settings.json 使用带注释的 JSONC 方言。
|
|
738
637
|
"jsonc/no-comments": "off"
|
|
739
638
|
}
|
|
740
639
|
}
|
|
741
640
|
]);
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
641
|
+
var createLodashConfigs = (preference, files = GLOBS_CODE) => defineConfig([
|
|
642
|
+
{
|
|
643
|
+
name: `@fast-china/lodash/${preference}`,
|
|
644
|
+
files: [...files],
|
|
645
|
+
rules: preference === "lodash" ? preferLodashRules : preferLodashUnifiedRules
|
|
646
|
+
}
|
|
647
|
+
]);
|
|
648
|
+
var createMarkdownConfigs = () => defineConfig([
|
|
747
649
|
{
|
|
748
650
|
name: "@fast-china/markdown",
|
|
749
|
-
files: [
|
|
750
|
-
|
|
751
|
-
extends: [...eslintMarkdown.configs["recommended"]],
|
|
752
|
-
plugins: {
|
|
753
|
-
markdown: eslintMarkdown
|
|
754
|
-
}
|
|
651
|
+
files: [GLOB_MARKDOWN],
|
|
652
|
+
extends: [eslintMarkdown.configs.recommended]
|
|
755
653
|
}
|
|
756
654
|
]);
|
|
757
|
-
|
|
758
|
-
// src/configs/prettier.ts
|
|
759
|
-
import { defineConfig as defineConfig7 } from "eslint/config";
|
|
760
|
-
import eslintConfigPrettierFlat from "eslint-config-prettier/flat";
|
|
761
|
-
import eslintPluginPrettier from "eslint-plugin-prettier";
|
|
762
|
-
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
|
|
763
|
-
var prettierConfigs = defineConfig7([
|
|
655
|
+
var createPrettierConfigs = () => defineConfig([
|
|
764
656
|
{
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
extends: [eslintConfigPrettierFlat, eslintPluginPrettierRecommended],
|
|
768
|
-
plugins: {
|
|
769
|
-
prettier: eslintPluginPrettier
|
|
770
|
-
},
|
|
771
|
-
rules: {
|
|
772
|
-
// 确保 Prettier 错误被 ESLint 捕获
|
|
773
|
-
"prettier/prettier": "error"
|
|
774
|
-
}
|
|
657
|
+
...eslintConfigPrettierFlat,
|
|
658
|
+
name: "@fast-china/prettier"
|
|
775
659
|
}
|
|
776
660
|
]);
|
|
777
|
-
|
|
778
|
-
// src/configs/regexp.ts
|
|
779
|
-
import { defineConfig as defineConfig8 } from "eslint/config";
|
|
780
|
-
import eslintPluginRegexp from "eslint-plugin-regexp";
|
|
781
|
-
var regexpConfigs = defineConfig8([
|
|
661
|
+
var createRegexpConfigs = (files = GLOBS_CODE) => defineConfig([
|
|
782
662
|
{
|
|
783
663
|
name: "@fast-china/regexp",
|
|
784
|
-
...
|
|
664
|
+
files: [...files],
|
|
665
|
+
extends: [eslintPluginRegexp.configs["flat/recommended"]]
|
|
785
666
|
}
|
|
786
667
|
]);
|
|
787
|
-
|
|
788
|
-
// src/configs/sort-package.ts
|
|
789
|
-
import { defineConfig as defineConfig9 } from "eslint/config";
|
|
790
|
-
var packageJsonSortConfigs = defineConfig9([
|
|
668
|
+
var createPackageJsonSortConfigs = () => defineConfig([
|
|
791
669
|
{
|
|
792
|
-
name: "@fast-china/sort/package",
|
|
670
|
+
name: "@fast-china/sort/package-json",
|
|
793
671
|
files: ["**/package.json"],
|
|
794
672
|
rules: packageJsonSortRules
|
|
795
673
|
}
|
|
796
674
|
]);
|
|
797
|
-
|
|
798
|
-
// src/configs/sort-tsconfig.ts
|
|
799
|
-
import { defineConfig as defineConfig10 } from "eslint/config";
|
|
800
|
-
var tsconfigJsonSortConfigs = defineConfig10([
|
|
675
|
+
var createTsconfigSortConfigs = () => defineConfig([
|
|
801
676
|
{
|
|
802
677
|
name: "@fast-china/sort/tsconfig",
|
|
803
|
-
files:
|
|
678
|
+
files: [...GLOBS_TSCONFIG],
|
|
804
679
|
rules: tsconfigJsonSortRules
|
|
805
680
|
}
|
|
806
681
|
]);
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
682
|
+
var getTypeScriptPresetConfigs = (typeChecked, removeFileScopes = false) => {
|
|
683
|
+
const configs = [
|
|
684
|
+
...typeChecked ? tseslint.configs.recommendedTypeChecked : tseslint.configs.recommended,
|
|
685
|
+
...typeChecked ? tseslint.configs.stylisticTypeChecked : tseslint.configs.stylistic
|
|
686
|
+
];
|
|
687
|
+
if (!removeFileScopes) return configs;
|
|
688
|
+
return configs.map((config) => {
|
|
689
|
+
const { files: _files, ...configWithoutFiles } = config;
|
|
690
|
+
return configWithoutFiles;
|
|
691
|
+
});
|
|
692
|
+
};
|
|
693
|
+
var createTypeScriptParserOptions = ({ typeChecked = false, tsconfigRootDir } = {}) => ({
|
|
694
|
+
...typeChecked ? { projectService: true } : {},
|
|
695
|
+
...typeChecked && tsconfigRootDir ? { tsconfigRootDir } : {}
|
|
696
|
+
});
|
|
697
|
+
var createTypeScriptConfigs = (options = {}, files = GLOBS_TYPESCRIPT) => defineConfig([
|
|
812
698
|
{
|
|
813
|
-
name: "@fast-china/typescript",
|
|
814
|
-
files: [
|
|
815
|
-
|
|
816
|
-
extends: [tseslint.configs.recommended],
|
|
699
|
+
name: options.typeChecked ? "@fast-china/typescript/type-checked" : "@fast-china/typescript",
|
|
700
|
+
files: [...files],
|
|
701
|
+
extends: getTypeScriptPresetConfigs(options.typeChecked ?? false),
|
|
817
702
|
languageOptions: {
|
|
818
|
-
// 允许使用最新的 ECMAScript 语法特性
|
|
819
703
|
ecmaVersion: "latest",
|
|
820
|
-
|
|
821
|
-
parserOptions: {
|
|
822
|
-
ecmaFeatures: {
|
|
823
|
-
// 允许使用 TSX 语法,适用于 Vue 组件中的 TSX 代码。
|
|
824
|
-
tsx: true
|
|
825
|
-
},
|
|
826
|
-
sourceType: "module"
|
|
827
|
-
}
|
|
704
|
+
parserOptions: createTypeScriptParserOptions(options)
|
|
828
705
|
},
|
|
829
706
|
rules: typescriptRules
|
|
830
707
|
}
|
|
831
708
|
]);
|
|
832
|
-
var
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
709
|
+
var createVueConfigs = ({ typescript = true, typescriptOptions = {} } = {}) => {
|
|
710
|
+
const typeChecked = typescriptOptions.typeChecked ?? false;
|
|
711
|
+
const typeScriptConfigs = typescript ? getTypeScriptPresetConfigs(typeChecked, true) : [];
|
|
712
|
+
return defineConfig([
|
|
713
|
+
{
|
|
714
|
+
name: typeChecked ? "@fast-china/vue/type-checked" : "@fast-china/vue",
|
|
715
|
+
files: [GLOB_VUE],
|
|
716
|
+
extends: [eslint.configs.recommended, ...typeScriptConfigs, ...eslintPluginVue.configs["flat/recommended"]],
|
|
717
|
+
languageOptions: {
|
|
718
|
+
ecmaVersion: "latest",
|
|
719
|
+
parser: vueEslintParser,
|
|
720
|
+
parserOptions: {
|
|
721
|
+
...typescript ? { parser: tseslint.parser, extraFileExtensions: [".vue"] } : {},
|
|
722
|
+
ecmaFeatures: {
|
|
723
|
+
jsx: true
|
|
724
|
+
},
|
|
725
|
+
sourceType: "module",
|
|
726
|
+
...createTypeScriptParserOptions(typescriptOptions)
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
rules: {
|
|
730
|
+
...typescript ? typescriptRules : {},
|
|
731
|
+
...vueRules
|
|
732
|
+
}
|
|
856
733
|
}
|
|
857
|
-
|
|
858
|
-
]);
|
|
859
|
-
|
|
860
|
-
// src/configs/vue.ts
|
|
861
|
-
import { defineConfig as defineConfig12 } from "eslint/config";
|
|
862
|
-
import eslintPluginVue from "eslint-plugin-vue";
|
|
863
|
-
import tseslint2 from "typescript-eslint";
|
|
864
|
-
import vueEslintParser from "vue-eslint-parser";
|
|
865
|
-
|
|
866
|
-
// src/env/index.ts
|
|
867
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
868
|
-
var getVueVersion = () => {
|
|
869
|
-
const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
|
|
870
|
-
if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0])) {
|
|
871
|
-
return +pkg.version[0];
|
|
872
|
-
}
|
|
873
|
-
return 3;
|
|
734
|
+
]);
|
|
874
735
|
};
|
|
875
|
-
var isVue3 = getVueVersion() === 3;
|
|
876
736
|
|
|
877
|
-
// src/
|
|
878
|
-
var
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
737
|
+
// src/factory.ts
|
|
738
|
+
var defaultConfigOptions = Object.freeze({
|
|
739
|
+
environment: "browser",
|
|
740
|
+
gitignore: true,
|
|
741
|
+
imports: true,
|
|
742
|
+
javascript: true,
|
|
743
|
+
json: true,
|
|
744
|
+
lodash: false,
|
|
745
|
+
markdown: true,
|
|
746
|
+
prettier: true,
|
|
747
|
+
regexp: true,
|
|
748
|
+
sortPackageJson: false,
|
|
749
|
+
sortTsconfig: false,
|
|
750
|
+
typescript: true,
|
|
751
|
+
vue: true
|
|
752
|
+
});
|
|
753
|
+
var fastConfig = (options = {}, ...overrides) => {
|
|
754
|
+
const environment = options.environment ?? defaultConfigOptions.environment;
|
|
755
|
+
const gitignore = options.gitignore ?? defaultConfigOptions.gitignore;
|
|
756
|
+
const imports = options.imports ?? defaultConfigOptions.imports;
|
|
757
|
+
const javascript = options.javascript ?? defaultConfigOptions.javascript;
|
|
758
|
+
const json = options.json ?? defaultConfigOptions.json;
|
|
759
|
+
const lodash = options.lodash ?? defaultConfigOptions.lodash;
|
|
760
|
+
const markdown = options.markdown ?? defaultConfigOptions.markdown;
|
|
761
|
+
const prettier = options.prettier ?? defaultConfigOptions.prettier;
|
|
762
|
+
const regexp = options.regexp ?? defaultConfigOptions.regexp;
|
|
763
|
+
const sortPackageJson = options.sortPackageJson ?? defaultConfigOptions.sortPackageJson;
|
|
764
|
+
const sortTsconfig = options.sortTsconfig ?? defaultConfigOptions.sortTsconfig;
|
|
765
|
+
const typescript = options.typescript ?? defaultConfigOptions.typescript;
|
|
766
|
+
const vue = options.vue ?? defaultConfigOptions.vue;
|
|
767
|
+
const typeScriptEnabled = typescript !== false;
|
|
768
|
+
const typeScriptOptions = typeof typescript === "object" ? typescript : {};
|
|
769
|
+
const projectRules = options.rules;
|
|
770
|
+
const scriptFiles = [...javascript ? GLOBS_JAVASCRIPT : [], ...typeScriptEnabled ? GLOBS_TYPESCRIPT : []];
|
|
771
|
+
const codeFiles = [...scriptFiles, ...vue ? [GLOB_VUE] : []];
|
|
772
|
+
const jsonEnabled = json || sortPackageJson || sortTsconfig;
|
|
773
|
+
return defineConfig([
|
|
774
|
+
createGlobalIgnores(options.ignores),
|
|
775
|
+
...gitignore ? createGitignoreConfigs() : [],
|
|
776
|
+
...codeFiles.length ? [
|
|
777
|
+
...createEnvironmentConfigs({
|
|
778
|
+
environment,
|
|
779
|
+
files: codeFiles,
|
|
780
|
+
globals: options.globals,
|
|
781
|
+
nodeFiles: scriptFiles
|
|
782
|
+
}),
|
|
783
|
+
...createBaseConfigs(codeFiles)
|
|
784
|
+
] : [],
|
|
785
|
+
...javascript ? createJavaScriptConfigs() : [],
|
|
786
|
+
...imports && codeFiles.length ? createImportConfigs(codeFiles) : [],
|
|
787
|
+
...lodash && codeFiles.length ? createLodashConfigs(lodash, codeFiles) : [],
|
|
788
|
+
...regexp && codeFiles.length ? createRegexpConfigs(codeFiles) : [],
|
|
789
|
+
...typeScriptEnabled ? createTypeScriptConfigs(typeScriptOptions) : [],
|
|
790
|
+
...jsonEnabled ? createJsonConfigs() : [],
|
|
791
|
+
...sortPackageJson ? createPackageJsonSortConfigs() : [],
|
|
792
|
+
...sortTsconfig ? createTsconfigSortConfigs() : [],
|
|
793
|
+
...vue ? createVueConfigs({ typescript: typeScriptEnabled, typescriptOptions: typeScriptOptions }) : [],
|
|
794
|
+
...markdown ? createMarkdownConfigs() : [],
|
|
795
|
+
...prettier ? createPrettierConfigs() : [],
|
|
796
|
+
...projectRules && codeFiles.length ? [
|
|
797
|
+
{
|
|
798
|
+
name: "@fast-china/project/rules",
|
|
799
|
+
files: codeFiles,
|
|
800
|
+
rules: projectRules
|
|
932
801
|
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
]);
|
|
936
|
-
|
|
937
|
-
// src/index.ts
|
|
938
|
-
var PresetJavascriptConfigs = [...ignoresConfigs, ...commonConfigs, ...javascriptConfigs, ...importConfigs, ...regexpConfigs];
|
|
939
|
-
var PresetJsonConfigs = [...jsonConfigs, ...packageJsonSortConfigs, ...tsconfigJsonSortConfigs];
|
|
940
|
-
var PresetBasicConfigs = [...PresetJavascriptConfigs, ...typescriptConfigs, ...PresetJsonConfigs];
|
|
941
|
-
var index_default = [...PresetBasicConfigs, ...vueConfigs, ...markdownConfigs, ...prettierConfigs];
|
|
942
|
-
export {
|
|
943
|
-
CONST_DIST,
|
|
944
|
-
CONST_DTS,
|
|
945
|
-
CONST_JS,
|
|
946
|
-
CONST_JSON,
|
|
947
|
-
CONST_JSON5,
|
|
948
|
-
CONST_JSONC,
|
|
949
|
-
CONST_JSX,
|
|
950
|
-
CONST_LOCKFILE,
|
|
951
|
-
CONST_MD,
|
|
952
|
-
CONST_NODE_MODULES,
|
|
953
|
-
CONST_PUBLIC,
|
|
954
|
-
CONST_TS,
|
|
955
|
-
CONST_TSCONFIG,
|
|
956
|
-
CONST_TSX,
|
|
957
|
-
CONST_VUE,
|
|
958
|
-
CONST_YAML,
|
|
959
|
-
PresetBasicConfigs,
|
|
960
|
-
PresetJavascriptConfigs,
|
|
961
|
-
PresetJsonConfigs,
|
|
962
|
-
commonConfigs,
|
|
963
|
-
index_default as default,
|
|
964
|
-
ignoresConfigs,
|
|
965
|
-
importConfigs,
|
|
966
|
-
javascriptConfigs,
|
|
967
|
-
jsonConfigs,
|
|
968
|
-
markdownConfigs,
|
|
969
|
-
packageJsonSortConfigs,
|
|
970
|
-
prettierConfigs,
|
|
971
|
-
regexpConfigs,
|
|
972
|
-
tsconfigJsonSortConfigs,
|
|
973
|
-
typescriptConfigs,
|
|
974
|
-
typescriptCoreConfigs,
|
|
975
|
-
vueConfigs
|
|
802
|
+
] : [],
|
|
803
|
+
...overrides
|
|
804
|
+
]);
|
|
976
805
|
};
|
|
806
|
+
|
|
807
|
+
export { fastConfig as default, defaultConfigOptions, defineRules, fastConfig };
|
|
808
|
+
//# sourceMappingURL=index.js.map
|
|
977
809
|
//# sourceMappingURL=index.js.map
|