@fast-china/eslint-config 2.0.0 → 2.0.2

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 DELETED
@@ -1,809 +0,0 @@
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"];
35
-
36
- // src/rules/common.ts
37
- var commonRules = {
38
- // 要求数组回调在所有可到达分支返回值,避免 map/filter 等调用静默产生 undefined。
39
- "array-callback-return": "error",
40
- // 浏览器弹窗通常不适合生产代码;使用 warn 允许原型调试,同时确保发布前能够被发现。
41
- "no-alert": "warn",
42
- // switch 的 case 不创建词法作用域;要求用花括号包裹声明,避免跨 case 冲突。
43
- "no-case-declarations": "error",
44
- // 禁止反斜杠续行字符串,优先使用可读性更好的模板字符串。
45
- "no-multi-str": "error",
46
- // with 会让标识符解析不可预测,并且在严格模式和 ESM 中不可用。
47
- "no-with": "error",
48
- // 允许用 `void promise` 明确忽略 Promise,但禁止在普通表达式中滥用 void。
49
- "no-void": [
50
- "error",
51
- {
52
- allowAsStatement: true
53
- }
54
- ],
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 的成员。
62
- "sort-imports": [
63
- "warn",
64
- {
65
- ignoreCase: false,
66
- ignoreDeclarationSort: true,
67
- ignoreMemberSort: false,
68
- memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
69
- allowSeparatedGroups: false
70
- }
71
- ]
72
- };
73
-
74
- // src/rules/import.ts
75
- var importRules = {
76
- // import 必须位于其他语句之前,避免模块依赖散落在执行逻辑中。
77
- "import-x/first": "error",
78
- // 合并同一模块的重复 import,避免绑定分散或副作用被误读。
79
- "import-x/no-duplicates": "error",
80
- // [高影响][可自动修复] 按来源分组并排序;带副作用的裸 import 仅报告,人工移动前必须确认执行顺序。
81
- "import-x/order": [
82
- "error",
83
- {
84
- groups: [
85
- // Node.js 内置模块
86
- "builtin",
87
- // 第三方依赖
88
- "external",
89
- // 项目内部别名模块
90
- "internal",
91
- // 父级目录模块
92
- "parent",
93
- // 同级目录模块
94
- "sibling",
95
- // 当前目录入口模块
96
- "index",
97
- // TypeScript import = require() 导入
98
- "object",
99
- // TypeScript 类型导入
100
- "type",
101
- // 无法识别分类的导入
102
- "unknown"
103
- ],
104
- // 不同 import 分组之间必须保留一个空行
105
- "newlines-between": "always",
106
- // 同一分组内按照模块路径字母升序排列
107
- alphabetize: {
108
- order: "asc",
109
- caseInsensitive: true
110
- },
111
- // 对没有赋值给变量的副作用导入进行排序检查
112
- warnOnUnassignedImports: true
113
- }
114
- ],
115
- // [默认关闭] Vite/TypeScript 别名由项目解析器校验,避免共享配置绑定特定 resolver。
116
- "import-x/no-unresolved": "off",
117
- // [默认关闭] 未配置 resolver 时,namespace 导出的静态分析容易产生误报。
118
- "import-x/namespace": "off",
119
- // [默认关闭] 未配置 resolver 时,默认导出的静态分析容易产生误报。
120
- "import-x/default": "off",
121
- // [默认关闭] 不限制同时存在默认导出与相近命名导出的模块 API 风格。
122
- "import-x/no-named-as-default": "off",
123
- // [默认关闭] 不限制通过默认导入对象访问同名属性的项目 API 风格。
124
- "import-x/no-named-as-default-member": "off",
125
- // [默认关闭] 未配置 resolver 时,命名导出的静态分析容易产生误报。
126
- "import-x/named": "off"
127
- };
128
-
129
- // src/rules/javascript.ts
130
- var javascriptRules = {
131
- // 控制台调用在应用源码中需要人工确认;warn/error 仍可用于必要的诊断输出。
132
- "no-console": [
133
- "warn",
134
- {
135
- allow: ["warn", "error"]
136
- }
137
- ],
138
- // 防止调试断点进入发布代码并中断运行。
139
- "no-debugger": "error",
140
- // 禁止意外的恒定条件,但允许 while (true) 等有明确退出逻辑的循环。
141
- "no-constant-condition": [
142
- "error",
143
- {
144
- checkLoops: false
145
- }
146
- ],
147
- // [高影响] 禁止标签语句;包含多层循环 labeled break/continue 的代码需先重构控制流。
148
- "no-restricted-syntax": ["error", "LabeledStatement"],
149
- // [高影响][可自动修复] 使用 let/const 替代 var;首次启用需复核循环闭包和声明提升行为。
150
- "no-var": "error",
151
- // 禁止无说明的空代码块;允许用于“忽略失败”语义的空 catch。
152
- "no-empty": [
153
- "error",
154
- {
155
- allowEmptyCatch: true
156
- }
157
- ],
158
- // 拒绝肉眼难以识别、可能导致解析差异的非常规空白字符。
159
- "no-irregular-whitespace": "error",
160
- // 变量和类先声明后使用;函数声明允许提升。warn 保留函数式组合和循环依赖重构空间。
161
- "no-use-before-define": [
162
- "warn",
163
- {
164
- classes: true,
165
- functions: false,
166
- variables: true
167
- }
168
- ],
169
- // [可自动修复] 能保持引用不变的变量优先使用 const;读取发生在赋值前时不做不可靠判断。
170
- "prefer-const": [
171
- "warn",
172
- {
173
- destructuring: "all",
174
- ignoreReadBeforeAssign: true
175
- }
176
- ],
177
- // [高影响][可自动修复] 优先箭头回调;批量修复后应复核 this/arguments 与函数名栈信息。
178
- "prefer-arrow-callback": [
179
- "error",
180
- {
181
- allowNamedFunctions: false,
182
- allowUnboundThis: true
183
- }
184
- ],
185
- // [可自动修复] 属性和值同名时使用对象简写,带引号键名不强制改写。
186
- "object-shorthand": [
187
- "error",
188
- "always",
189
- {
190
- ignoreConstructors: false,
191
- avoidQuotes: true
192
- }
193
- ],
194
- // [高影响][可自动修复] 使用 ||=、&&=、??=;涉及 getter/Proxy 的代码应复核求值次数。
195
- "logical-assignment-operators": ["error", "always", { enforceForIfStatements: true }],
196
- // [可自动修复] 合并对象时优先展开语法,避免 Object.assign 的额外目标对象样板。
197
- "prefer-object-spread": "error",
198
- // 可变参数函数优先 rest 参数,避免依赖类数组 arguments;该规则只报告,不自动改写签名。
199
- "prefer-rest-params": "error",
200
- // 调用可迭代对象时优先 spread;该规则只报告,避免自动改变 apply 的 this 语义。
201
- "prefer-spread": "error",
202
- // [可自动修复] 字符串拼接优先模板字符串,便于阅读和多段插值。
203
- "prefer-template": "error",
204
- // 同一作用域禁止重复声明,避免后声明遮盖前声明。
205
- "no-redeclare": "error"
206
- };
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
-
258
- // src/rules/sort-package.ts
259
- var packageJsonSortRules = {
260
- // [高影响][可自动修复][按需启用] npm 的 files 清单按字母排序;数组顺序不改打包集合,但首次 diff 较大。
261
- "jsonc/sort-array-values": [
262
- "error",
263
- {
264
- order: { type: "asc" },
265
- pathPattern: "^files$"
266
- }
267
- ],
268
- // [高影响][可自动修复][按需启用] 仅排序明确安全的 package.json 区域,不进入 exports 条件对象。
269
- "jsonc/sort-keys": [
270
- "error",
271
- // 根字段按常见阅读顺序组织,减少不同项目之间的清单噪声。
272
- {
273
- order: [
274
- "name",
275
- "version",
276
- "private",
277
- "packageManager",
278
- "description",
279
- "type",
280
- "keywords",
281
- "license",
282
- "homepage",
283
- "bugs",
284
- "repository",
285
- "author",
286
- "contributors",
287
- "funding",
288
- "files",
289
- "main",
290
- "module",
291
- "types",
292
- "exports",
293
- "typesVersions",
294
- "sideEffects",
295
- "unpkg",
296
- "jsdelivr",
297
- "browser",
298
- "bin",
299
- "man",
300
- "directories",
301
- "publishConfig",
302
- "scripts",
303
- "peerDependencies",
304
- "peerDependenciesMeta",
305
- "optionalDependencies",
306
- "dependencies",
307
- "devDependencies",
308
- "engines",
309
- "config",
310
- "overrides",
311
- "pnpm",
312
- "husky",
313
- "lint-staged",
314
- "eslintConfig",
315
- "prettier"
316
- ],
317
- pathPattern: "^$"
318
- },
319
- // 各类依赖映射按包名排序,方便发现重复或异常依赖。
320
- {
321
- order: { type: "asc" },
322
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
323
- },
324
- // overrides/resolutions 只排序直接键;修改前仍应关注包管理器的模式匹配语义。
325
- {
326
- order: { type: "asc" },
327
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
328
- }
329
- ]
330
- };
331
-
332
- // src/rules/sort-tsconfig.ts
333
- var tsconfigJsonSortRules = {
334
- // tsconfig 是 JSONC,注释用于解释不直观的编译器取舍,必须保留。
335
- "jsonc/no-comments": "off",
336
- // [高影响][可自动修复][按需启用] 只调整顶层和 compilerOptions 的键顺序,不改写任何选项值或数组。
337
- "jsonc/sort-keys": [
338
- "error",
339
- // 顶层按继承、选项、项目引用和文件范围的阅读顺序排列。
340
- {
341
- order: ["extends", "compilerOptions", "references", "files", "include", "exclude"],
342
- pathPattern: "^$"
343
- },
344
- // compilerOptions 的顺序跟随 TypeScript 文档主题,便于检索和代码审查。
345
- {
346
- order: [
347
- /* Projects */
348
- "incremental",
349
- "composite",
350
- "tsBuildInfoFile",
351
- "disableSourceOfProjectReferenceRedirect",
352
- "disableSolutionSearching",
353
- "disableReferencedProjectLoad",
354
- /* Language and Environment */
355
- "target",
356
- "jsx",
357
- "jsxFactory",
358
- "jsxFragmentFactory",
359
- "jsxImportSource",
360
- "lib",
361
- "moduleDetection",
362
- "noLib",
363
- "reactNamespace",
364
- "useDefineForClassFields",
365
- "emitDecoratorMetadata",
366
- "experimentalDecorators",
367
- /* Modules */
368
- "baseUrl",
369
- "rootDir",
370
- "rootDirs",
371
- "customConditions",
372
- "module",
373
- "moduleResolution",
374
- "moduleSuffixes",
375
- "noResolve",
376
- "paths",
377
- "resolveJsonModule",
378
- "resolvePackageJsonExports",
379
- "resolvePackageJsonImports",
380
- "typeRoots",
381
- "types",
382
- "allowArbitraryExtensions",
383
- "allowImportingTsExtensions",
384
- "allowUmdGlobalAccess",
385
- /* JavaScript Support */
386
- "allowJs",
387
- "checkJs",
388
- "maxNodeModuleJsDepth",
389
- /* Type Checking */
390
- "strict",
391
- "strictBindCallApply",
392
- "strictFunctionTypes",
393
- "strictNullChecks",
394
- "strictPropertyInitialization",
395
- "allowUnreachableCode",
396
- "allowUnusedLabels",
397
- "alwaysStrict",
398
- "exactOptionalPropertyTypes",
399
- "noFallthroughCasesInSwitch",
400
- "noImplicitAny",
401
- "noImplicitOverride",
402
- "noImplicitReturns",
403
- "noImplicitThis",
404
- "noPropertyAccessFromIndexSignature",
405
- "noUncheckedIndexedAccess",
406
- "noUnusedLocals",
407
- "noUnusedParameters",
408
- "useUnknownInCatchVariables",
409
- /* Emit */
410
- "declaration",
411
- "declarationDir",
412
- "declarationMap",
413
- "downlevelIteration",
414
- "emitBOM",
415
- "emitDeclarationOnly",
416
- "importHelpers",
417
- "importsNotUsedAsValues",
418
- "inlineSourceMap",
419
- "inlineSources",
420
- "isolatedDeclarations",
421
- "mapRoot",
422
- "newLine",
423
- "noEmit",
424
- "noEmitHelpers",
425
- "noEmitOnError",
426
- "outDir",
427
- "outFile",
428
- "preserveConstEnums",
429
- "preserveValueImports",
430
- "removeComments",
431
- "sourceMap",
432
- "sourceRoot",
433
- "stripInternal",
434
- /* Interop Constraints */
435
- "allowSyntheticDefaultImports",
436
- "esModuleInterop",
437
- "forceConsistentCasingInFileNames",
438
- "isolatedModules",
439
- "preserveSymlinks",
440
- "verbatimModuleSyntax",
441
- /* Completeness */
442
- "skipDefaultLibCheck",
443
- "skipLibCheck"
444
- ],
445
- pathPattern: "^compilerOptions$"
446
- }
447
- ]
448
- };
449
-
450
- // src/rules/typescript.ts
451
- var typescriptRules = {
452
- // 使用 TypeScript 版本避免核心规则误判声明合并、类型和值的同名声明。
453
- "@typescript-eslint/no-redeclare": "error",
454
- // [高影响][可自动修复] 未使用符号视为错误;以下划线开头可显式表示参数或变量被有意忽略。
455
- "@typescript-eslint/no-unused-vars": [
456
- "error",
457
- {
458
- args: "after-used",
459
- argsIgnorePattern: "^_",
460
- caughtErrors: "all",
461
- caughtErrorsIgnorePattern: "^_",
462
- ignoreRestSiblings: true,
463
- varsIgnorePattern: "^_"
464
- }
465
- ],
466
- // [默认关闭] 声明文件、全局扩展和部分 SDK 仍需要 namespace。
467
- "@typescript-eslint/no-namespace": "off",
468
- // any 会绕过类型检查,但在第三方边界和渐进式类型完善中有合理用途,因此只警告。
469
- "@typescript-eslint/no-explicit-any": "warn",
470
- // [高影响] 默认要求 ESM import;CommonJS、动态加载或工具链互操作代码可能需要按文件关闭。
471
- "@typescript-eslint/no-require-imports": "error",
472
- // 使用 TS 版本识别类型断言等语法;允许常见的短路和三元表达式调用模式。
473
- "@typescript-eslint/no-unused-expressions": [
474
- "error",
475
- {
476
- allowShortCircuit: true,
477
- allowTernary: true
478
- }
479
- ],
480
- // [可自动修复] 删除可由 TypeScript 明确推断的原始值类型标注,减少重复信息。
481
- "@typescript-eslint/no-inferrable-types": "error",
482
- // 非空断言可能隐藏空值缺陷;以警告提示逐步消除,避免一次性产生大量阻断错误。
483
- "@typescript-eslint/no-non-null-assertion": "warn",
484
- // 可选链之后再做非空断言逻辑矛盾,通常表示边界条件设计有误。
485
- "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
486
- // [高影响][可自动修复] 类型依赖改用内联 type import;需复核仅靠 import 触发的模块副作用。
487
- "@typescript-eslint/consistent-type-imports": [
488
- "error",
489
- {
490
- disallowTypeAnnotations: false,
491
- fixStyle: "inline-type-imports",
492
- prefer: "type-imports"
493
- }
494
- ]
495
- };
496
-
497
- // src/rules/vue.ts
498
- var vueRules = {
499
- // [安全关注] v-html 可能引入 XSS;保留 warn 以兼容经过净化的富文本场景。
500
- "vue/no-v-html": "warn",
501
- // [默认关闭] TypeScript 类型 props 和 required 声明已能表达可选性,不强制每个可选 prop 提供默认值。
502
- "vue/require-default-prop": "off",
503
- // [高影响] 组件必须声明对外事件;首次启用时会暴露未建模的公共事件 API。
504
- "vue/require-explicit-emits": "error",
505
- // [默认关闭] 允许 App、Layout 等约定俗成的单词组件名。
506
- "vue/multi-word-component-names": "off",
507
- // 优先从 vue 入口导入由 Vue 重新导出的 API,避免依赖内部包边界。
508
- "vue/prefer-import-from-vue": "warn",
509
- // 防止 props、data、computed、methods 等组件命名空间出现冲突。
510
- "vue/no-dupe-keys": "error",
511
- // [高影响] 禁止组件直接修改 props,要求通过事件或本地状态维持单向数据流。
512
- "vue/no-mutating-props": "error",
513
- // 避免自定义组件名与 Vue 内置组件冲突。
514
- "vue/no-reserved-component-names": "error",
515
- // [安全关注] 禁止在组件节点上使用 v-text/v-html,避免覆盖组件内容和模糊数据边界。
516
- "vue/no-v-text-v-html-on-component": "error",
517
- // 统一模板与脚本中的自定义事件名称为 camelCase。
518
- "vue/custom-event-name-casing": ["error", "camelCase"],
519
- // [默认关闭] 允许在一个 SFC 中声明仅供当前文件使用的小型辅助组件。
520
- "vue/one-component-per-file": "off",
521
- // [高影响][可自动修复] 统一模板属性分组;首次启用可能产生大量仅排序的模板差异。
522
- "vue/attributes-order": [
523
- "error",
524
- {
525
- order: ["DEFINITION", "LIST_RENDERING", "CONDITIONALS", "RENDER_MODIFIERS", "GLOBAL", "UNIQUE", "OTHER_ATTR", "EVENTS", "CONTENT"]
526
- }
527
- ]
528
- };
529
-
530
- // src/configs/common.ts
531
- var createBaseConfigs = (files = GLOBS_CODE) => defineConfig([
532
- {
533
- name: "@fast-china/common",
534
- files: [...files],
535
- linterOptions: {
536
- reportUnusedDisableDirectives: "error"
537
- },
538
- rules: commonRules
539
- }
540
- ]);
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([
586
- {
587
- name: "@fast-china/ignores/git",
588
- ...eslintConfigFlatGitignore({ strict: false })
589
- }
590
- ]);
591
- var createImportConfigs = (files = GLOBS_CODE) => defineConfig([
592
- {
593
- name: "@fast-china/import",
594
- files: [...files],
595
- extends: [eslintPluginImportX.flatConfigs.recommended],
596
- rules: importRules
597
- }
598
- ]);
599
- var createJavaScriptConfigs = (files = GLOBS_JAVASCRIPT) => defineConfig([
600
- {
601
- name: "@fast-china/javascript",
602
- files: [...files],
603
- extends: [eslint.configs.recommended],
604
- languageOptions: {
605
- ecmaVersion: "latest",
606
- parserOptions: {
607
- ecmaFeatures: {
608
- // 普通 `.jsx` 文件需要显式开启 JSX 语法解析。
609
- jsx: true
610
- }
611
- }
612
- },
613
- rules: javascriptRules
614
- }
615
- ]);
616
- var createJsonConfigs = () => defineConfig([
617
- {
618
- name: "@fast-china/json/json",
619
- files: [GLOB_JSON],
620
- extends: [eslintPluginJsonc.configs["flat/recommended-with-json"]]
621
- },
622
- {
623
- name: "@fast-china/json/jsonc",
624
- files: [GLOB_JSONC],
625
- extends: [eslintPluginJsonc.configs["flat/recommended-with-jsonc"]]
626
- },
627
- {
628
- name: "@fast-china/json/json5",
629
- files: [GLOB_JSON5],
630
- extends: [eslintPluginJsonc.configs["flat/recommended-with-json5"]]
631
- },
632
- {
633
- name: "@fast-china/json/vscode-settings",
634
- files: ["**/.vscode/settings.json"],
635
- rules: {
636
- // VS Code 的 settings.json 使用带注释的 JSONC 方言。
637
- "jsonc/no-comments": "off"
638
- }
639
- }
640
- ]);
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([
649
- {
650
- name: "@fast-china/markdown",
651
- files: [GLOB_MARKDOWN],
652
- extends: [eslintMarkdown.configs.recommended]
653
- }
654
- ]);
655
- var createPrettierConfigs = () => defineConfig([
656
- {
657
- ...eslintConfigPrettierFlat,
658
- name: "@fast-china/prettier"
659
- }
660
- ]);
661
- var createRegexpConfigs = (files = GLOBS_CODE) => defineConfig([
662
- {
663
- name: "@fast-china/regexp",
664
- files: [...files],
665
- extends: [eslintPluginRegexp.configs["flat/recommended"]]
666
- }
667
- ]);
668
- var createPackageJsonSortConfigs = () => defineConfig([
669
- {
670
- name: "@fast-china/sort/package-json",
671
- files: ["**/package.json"],
672
- rules: packageJsonSortRules
673
- }
674
- ]);
675
- var createTsconfigSortConfigs = () => defineConfig([
676
- {
677
- name: "@fast-china/sort/tsconfig",
678
- files: [...GLOBS_TSCONFIG],
679
- rules: tsconfigJsonSortRules
680
- }
681
- ]);
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([
698
- {
699
- name: options.typeChecked ? "@fast-china/typescript/type-checked" : "@fast-china/typescript",
700
- files: [...files],
701
- extends: getTypeScriptPresetConfigs(options.typeChecked ?? false),
702
- languageOptions: {
703
- ecmaVersion: "latest",
704
- parserOptions: createTypeScriptParserOptions(options)
705
- },
706
- rules: typescriptRules
707
- }
708
- ]);
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
- }
733
- }
734
- ]);
735
- };
736
-
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
801
- }
802
- ] : [],
803
- ...overrides
804
- ]);
805
- };
806
-
807
- export { fastConfig as default, defaultConfigOptions, defineRules, fastConfig };
808
- //# sourceMappingURL=index.js.map
809
- //# sourceMappingURL=index.js.map