@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/dist/index.js CHANGED
@@ -1,273 +1,263 @@
1
- // src/configs/common.ts
2
- import { defineConfig } from "eslint/config";
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
- // 确保数组的回调函数(如 Array.prototype.map、Array.prototype.filter、Array.prototype.reduce 等)总是有一个返回值
38
+ // 要求数组回调在所有可到达分支返回值,避免 map/filter 等调用静默产生 undefined。
7
39
  "array-callback-return": "error",
8
- // 强制使用块级作用域变量(let 或 const),避免使用函数作用域变量(var)
9
- "block-scoped-var": "error",
10
- // 禁止使用 alert、confirm 和 prompt 等浏览器弹出对话框
40
+ // 浏览器弹窗通常不适合生产代码;使用 warn 允许原型调试,同时确保发布前能够被发现。
11
41
  "no-alert": "warn",
12
- // 禁止在 switch 语句的 case 或 default 子句中声明变量
42
+ // switch 的 case 不创建词法作用域;要求用花括号包裹声明,避免跨 case 冲突。
13
43
  "no-case-declarations": "error",
14
- // 禁止使用多行字符串,即不允许使用反斜杠 \ 来连接多行字符串
44
+ // 禁止反斜杠续行字符串,优先使用可读性更好的模板字符串。
15
45
  "no-multi-str": "error",
16
- // 禁止使用 with 语句
46
+ // with 会让标识符解析不可预测,并且在严格模式和 ESM 中不可用。
17
47
  "no-with": "error",
18
- // 禁止使用 void 操作符
19
- "no-void": "error",
20
- // 禁止多个空行
21
- "@stylistic/no-multiple-empty-lines": [
48
+ // 允许用 `void promise` 明确忽略 Promise,但禁止在普通表达式中滥用 void。
49
+ "no-void": [
22
50
  "error",
23
51
  {
24
- // 最多允许1行
25
- max: 1
52
+ allowAsStatement: true
26
53
  }
27
54
  ],
28
- // import 排序
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
- // 确保所有的 import 语句位于文件的顶部,紧接在文件的开头部分,且在任何其他代码之前
76
+ // import 必须位于其他语句之前,避免模块依赖散落在执行逻辑中。
69
77
  "import-x/first": "error",
70
- // 禁止在同一文件中出现重复的 import 语句
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
- // 当前目录的 index.js 或 index.ts 文件
95
+ // 当前目录入口模块
89
96
  "index",
97
+ // TypeScript import = require() 导入
90
98
  "object",
99
+ // TypeScript 类型导入
91
100
  "type",
101
+ // 无法识别分类的导入
92
102
  "unknown"
93
103
  ],
94
- pathGroups: [
95
- {
96
- pattern: "@dcloudio/*",
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
- // 关闭 - 禁用对命名空间导入(例如,import * as)的检查
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
- // JS/TS (http://eslint.cn/docs/rules)
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
- // 禁止使用 debugger
195
- "no-debugger": "warn",
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
- "error",
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": "warn",
228
- // 强制使用 const 声明不被修改的变量
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
- // 强制使用 rest 参数代替 arguments 对象
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
- // 强制使用展开运算符(...)代替 Function.prototype.apply
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
- // TS (https://typescript-eslint.io/rules)
460
- // 要求在导出函数和类的公共方法上显式声明返回类型
461
- "@typescript-eslint/explicit-module-boundary-types": [
452
+ // 使用 TypeScript 版本避免核心规则误判声明合并、类型和值的同名声明。
453
+ "@typescript-eslint/no-redeclare": "error",
454
+ // [高影响][可自动修复] 未使用符号视为错误;以下划线开头可显式表示参数或变量被有意忽略。
455
+ "@typescript-eslint/no-unused-vars": [
462
456
  "error",
463
457
  {
464
- allowArgumentsExplicitlyTypedAsAny: true
458
+ args: "after-used",
459
+ argsIgnorePattern: "^_",
460
+ caughtErrors: "all",
461
+ caughtErrorsIgnorePattern: "^_",
462
+ ignoreRestSiblings: true,
463
+ varsIgnorePattern: "^_"
465
464
  }
466
465
  ],
467
- // 要求在 TypeScript 函数和方法中显式地指定返回类型
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
- // 允许使用 any 类型
476
- "@typescript-eslint/no-explicit-any": "off",
477
- // 禁止在 TypeScript 文件中使用 require 函数进行模块导入
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
- // 禁止在 TypeScript 代码中对类型已经可以被推断的变量或参数进行显式的类型注解
480
+ // [可自动修复] 删除可由 TypeScript 明确推断的原始值类型标注,减少重复信息。
492
481
  "@typescript-eslint/no-inferrable-types": "error",
493
- // 禁止使用后缀运算符的非空断言(!)
494
- "@typescript-eslint/no-non-null-assertion": "error",
495
- // 禁止在可选链(?)后使用非空断言(!)
482
+ // 非空断言可能隐藏空值缺陷;以警告提示逐步消除,避免一次性产生大量阻断错误。
483
+ "@typescript-eslint/no-non-null-assertion": "warn",
484
+ // 可选链之后再做非空断言逻辑矛盾,通常表示边界条件设计有误。
496
485
  "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
497
- // 禁止在代码中使用 @ts-ignore 注释
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
- disallowTypeAnnotations: false
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
- // vue (https://eslint.vuejs.org/rules)
512
- // 允许使用 v-html
513
- "vue/no-v-html": "off",
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
- // 强制组件中必须使用 emits 选项声明事件
503
+ // [高影响] 组件必须声明对外事件;首次启用时会暴露未建模的公共事件 API。
517
504
  "vue/require-explicit-emits": "error",
518
- // 禁用组件名称必须是多单词
505
+ // [默认关闭] 允许 App、Layout 等约定俗成的单词组件名。
519
506
  "vue/multi-word-component-names": "off",
520
- // 关闭 - 强制从 vue 中导入 Vue相关 API
521
- "vue/prefer-import-from-vue": "off",
522
- // 强制 HTML 属性使用 camelCase 风格
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
- // 禁止直接修改 props 的值
511
+ // [高影响] 禁止组件直接修改 props,要求通过事件或本地状态维持单向数据流。
541
512
  "vue/no-mutating-props": "error",
542
- // 禁止使用 Vue.js 内置的保留组件名称(如 transition、keep-alive 等)作为自定义组件名称
513
+ // 避免自定义组件名与 Vue 内置组件冲突。
543
514
  "vue/no-reserved-component-names": "error",
544
- // 禁止在自定义组件上使用 v-text 或 v-html 指令
545
- "vue/no-v-text-v-html-on-component": "off",
546
- // 防止<script setup>使用的变量<template>被标记为未使用,此规则仅在启用该no-unused-vars规则时有效。
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
- // 强制每个 Vue 文件中只包含一个 Vue 组件
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 commonConfigs = defineConfig([
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
- // src/configs/ignores.ts
580
- import { defineConfig as defineConfig2 } from "eslint/config";
581
- import eslintConfigFlatGitignore from "eslint-config-flat-gitignore";
582
-
583
- // src/constants/index.ts
584
- var CONST_JS = "**/*.?([cm])js";
585
- var CONST_JSX = "**/*.?([cm])jsx";
586
- var CONST_TS = "**/*.?([cm])ts";
587
- var CONST_TSX = "**/*.?([cm])tsx";
588
- var CONST_DTS = "**/*.d.ts";
589
- var CONST_JSON = "**/*.json";
590
- var CONST_JSONC = "**/*.jsonc";
591
- var CONST_JSON5 = "**/*.json5";
592
- var CONST_MD = "**/*.md";
593
- var CONST_VUE = "**/*.vue";
594
- var CONST_YAML = "**/*.y?(a)ml";
595
- var CONST_NODE_MODULES = "**/node_modules";
596
- var CONST_DIST = "**/dist";
597
- var CONST_LOCKFILE = ["**/package-lock.json", "**/yarn.lock", "**/pnpm-lock.yaml", "**/bun.lockb"];
598
- var CONST_PUBLIC = "**/public";
599
- var CONST_TSCONFIG = ["**/tsconfig.json", "**/tsconfig.*.json"];
600
-
601
- // src/configs/ignores.ts
602
- var ignoresConfigs = defineConfig2([
603
- {
604
- name: "@fast-china/ignores/global",
605
- ignores: [
606
- CONST_NODE_MODULES,
607
- CONST_DIST,
608
- CONST_PUBLIC,
609
- ...CONST_LOCKFILE,
610
- "**/output",
611
- "**/coverage",
612
- "**/temp",
613
- "**/fixtures",
614
- "**/.vitepress/cache",
615
- "**/.nuxt",
616
- "**/.vercel",
617
- "**/.changeset",
618
- "**/.idea",
619
- "**/.output",
620
- "**/.vite-inspect",
621
- "**/.nitro",
622
- "**/CHANGELOG*.md",
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, eslintPluginImportX.flatConfigs.typescript],
644
- settings: {
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
- // 允许使用 JSX 语法,适用于 Vue 组件中的 JSX 代码。
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/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
- }
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/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([
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: [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
- }
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
- // src/configs/markdown.ts
744
- import eslintMarkdown from "@eslint/markdown";
745
- import { defineConfig as defineConfig6 } from "eslint/config";
746
- var markdownConfigs = defineConfig6([
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: [CONST_MD],
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
- name: "@fast-china/prettier",
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
- ...eslintPluginRegexp.configs["flat/recommended"]
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: CONST_TSCONFIG,
678
+ files: [...GLOBS_TSCONFIG],
804
679
  rules: tsconfigJsonSortRules
805
680
  }
806
681
  ]);
807
-
808
- // src/configs/typescript.ts
809
- import { defineConfig as defineConfig11 } from "eslint/config";
810
- import tseslint from "typescript-eslint";
811
- var typescriptCoreConfigs = defineConfig11([
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: [CONST_TS, CONST_TSX],
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
- parser: tseslint.parser,
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 typescriptConfigs = defineConfig11([
833
- ...typescriptCoreConfigs,
834
- {
835
- name: "@fast-china/typescript/dts",
836
- files: [CONST_DTS],
837
- rules: {
838
- // 关闭 - 一致地使用 TypeScript 类型导入
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
- // 允许定义未使用的变量
855
- "@typescript-eslint/no-unused-vars": "off"
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/configs/vue.ts
878
- var vueConfigs = defineConfig12([
879
- {
880
- name: "@fast-china/vue/ts",
881
- files: [CONST_VUE],
882
- // 继承某些已有的规则
883
- extends: [...typescriptCoreConfigs]
884
- },
885
- {
886
- name: "@fast-china/vue",
887
- files: [CONST_VUE],
888
- // 继承某些已有的规则
889
- extends: [...isVue3 ? eslintPluginVue.configs["flat/recommended"] : eslintPluginVue.configs["flat/vue2-recommended"]],
890
- languageOptions: {
891
- // 允许使用最新的 ECMAScript 语法特性
892
- ecmaVersion: "latest",
893
- // 允许 ESLint 处理 Vue 文件中的模板和脚本
894
- parser: vueEslintParser,
895
- parserOptions: {
896
- // 允许在 Vue 文件中的脚本部分使用 TypeScript 语法
897
- parser: tseslint2.parser,
898
- // parser: "@typescript-eslint/parser",
899
- // 指定额外的文件扩展名,告诉解析器 .vue 文件也需要处理
900
- extraFileExtensions: [".vue"],
901
- // 允许使用 JSX/TSX 语法,适用于 Vue 组件中的 JSX/TSX 代码。
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"
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