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