@fast-china/eslint-config 2.0.3 → 2.0.4

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +77 -18
  3. package/README.zh.md +77 -18
  4. package/dist/configs/angular.d.mts +41 -0
  5. package/dist/configs/angular.d.mts.map +1 -0
  6. package/dist/configs/angular.mjs +33 -0
  7. package/dist/configs/angular.mjs.map +1 -0
  8. package/dist/configs/common.d.mts +11 -0
  9. package/dist/configs/common.d.mts.map +1 -0
  10. package/dist/configs/common.mjs +20 -0
  11. package/dist/configs/common.mjs.map +1 -0
  12. package/dist/configs/environment.d.mts +61 -0
  13. package/dist/configs/environment.d.mts.map +1 -0
  14. package/dist/configs/environment.mjs +33 -0
  15. package/dist/configs/environment.mjs.map +1 -0
  16. package/dist/configs/ignores.d.mts +15 -0
  17. package/dist/configs/ignores.d.mts.map +1 -0
  18. package/dist/configs/ignores.mjs +32 -0
  19. package/dist/configs/ignores.mjs.map +1 -0
  20. package/dist/configs/import.d.mts +11 -0
  21. package/dist/configs/import.d.mts.map +1 -0
  22. package/dist/configs/import.mjs +21 -0
  23. package/dist/configs/import.mjs.map +1 -0
  24. package/dist/configs/index.d.mts +17 -0
  25. package/dist/configs/index.mjs +17 -0
  26. package/dist/configs/javascript.d.mts +10 -0
  27. package/dist/configs/javascript.d.mts.map +1 -0
  28. package/dist/configs/javascript.mjs +24 -0
  29. package/dist/configs/javascript.mjs.map +1 -0
  30. package/dist/configs/json.d.mts +10 -0
  31. package/dist/configs/json.d.mts.map +1 -0
  32. package/dist/configs/json.mjs +35 -0
  33. package/dist/configs/json.mjs.map +1 -0
  34. package/dist/configs/lodash.d.mts +12 -0
  35. package/dist/configs/lodash.d.mts.map +1 -0
  36. package/dist/configs/lodash.mjs +18 -0
  37. package/dist/configs/lodash.mjs.map +1 -0
  38. package/dist/configs/markdown.d.mts +10 -0
  39. package/dist/configs/markdown.d.mts.map +1 -0
  40. package/dist/configs/markdown.mjs +18 -0
  41. package/dist/configs/markdown.mjs.map +1 -0
  42. package/dist/configs/prettier.d.mts +11 -0
  43. package/dist/configs/prettier.d.mts.map +1 -0
  44. package/dist/configs/prettier.mjs +17 -0
  45. package/dist/configs/prettier.mjs.map +1 -0
  46. package/dist/configs/react.d.mts +86 -0
  47. package/dist/configs/react.d.mts.map +1 -0
  48. package/dist/configs/react.mjs +31 -0
  49. package/dist/configs/react.mjs.map +1 -0
  50. package/dist/configs/regexp.d.mts +11 -0
  51. package/dist/configs/regexp.d.mts.map +1 -0
  52. package/dist/configs/regexp.mjs +19 -0
  53. package/dist/configs/regexp.mjs.map +1 -0
  54. package/dist/configs/sort-package.d.mts +11 -0
  55. package/dist/configs/sort-package.d.mts.map +1 -0
  56. package/dist/configs/sort-package.mjs +18 -0
  57. package/dist/configs/sort-package.mjs.map +1 -0
  58. package/dist/configs/sort-tsconfig.d.mts +10 -0
  59. package/dist/configs/sort-tsconfig.d.mts.map +1 -0
  60. package/dist/configs/sort-tsconfig.mjs +18 -0
  61. package/dist/configs/sort-tsconfig.mjs.map +1 -0
  62. package/dist/configs/typescript.d.mts +60 -0
  63. package/dist/configs/typescript.d.mts.map +1 -0
  64. package/dist/configs/typescript.mjs +44 -0
  65. package/dist/configs/typescript.mjs.map +1 -0
  66. package/dist/configs/vue.d.mts +43 -0
  67. package/dist/configs/vue.d.mts.map +1 -0
  68. package/dist/configs/vue.mjs +50 -0
  69. package/dist/configs/vue.mjs.map +1 -0
  70. package/dist/constants/index.d.mts +34 -0
  71. package/dist/constants/index.d.mts.map +1 -0
  72. package/dist/constants/index.mjs +52 -0
  73. package/dist/constants/index.mjs.map +1 -0
  74. package/dist/index.d.mts +19 -146
  75. package/dist/index.d.mts.map +1 -1
  76. package/dist/index.mjs +31 -402
  77. package/dist/index.mjs.map +1 -1
  78. package/dist/rules/angular.d.mts +46 -0
  79. package/dist/rules/angular.d.mts.map +1 -0
  80. package/dist/rules/angular.mjs +47 -0
  81. package/dist/rules/angular.mjs.map +1 -0
  82. package/dist/rules/common.d.mts +32 -0
  83. package/dist/rules/common.d.mts.map +1 -0
  84. package/dist/rules/common.mjs +38 -0
  85. package/dist/rules/common.mjs.map +1 -0
  86. package/dist/rules/import.d.mts +24 -0
  87. package/dist/rules/import.d.mts.map +1 -0
  88. package/dist/rules/import.mjs +35 -0
  89. package/dist/rules/import.mjs.map +1 -0
  90. package/dist/rules/index.d.mts +12 -309
  91. package/dist/rules/index.mjs +10 -1
  92. package/dist/rules/javascript.d.mts +48 -0
  93. package/dist/rules/javascript.d.mts.map +1 -0
  94. package/dist/rules/javascript.mjs +49 -0
  95. package/dist/rules/javascript.mjs.map +1 -0
  96. package/dist/rules/lodash.d.mts +40 -0
  97. package/dist/rules/lodash.d.mts.map +1 -0
  98. package/dist/rules/lodash.mjs +43 -0
  99. package/dist/rules/lodash.mjs.map +1 -0
  100. package/dist/rules/react.d.mts +26 -0
  101. package/dist/rules/react.d.mts.map +1 -0
  102. package/dist/rules/react.mjs +27 -0
  103. package/dist/rules/react.mjs.map +1 -0
  104. package/dist/rules/sort-package.d.mts +32 -0
  105. package/dist/rules/sort-package.d.mts.map +1 -0
  106. package/dist/rules/sort-package.mjs +75 -0
  107. package/dist/rules/sort-package.mjs.map +1 -0
  108. package/dist/rules/sort-tsconfig.d.mts +20 -0
  109. package/dist/rules/sort-tsconfig.d.mts.map +1 -0
  110. package/dist/rules/sort-tsconfig.mjs +122 -0
  111. package/dist/rules/sort-tsconfig.mjs.map +1 -0
  112. package/dist/rules/typescript.d.mts +34 -0
  113. package/dist/rules/typescript.d.mts.map +1 -0
  114. package/dist/rules/typescript.mjs +35 -0
  115. package/dist/rules/typescript.mjs.map +1 -0
  116. package/dist/rules/vue.d.mts +24 -0
  117. package/dist/rules/vue.d.mts.map +1 -0
  118. package/dist/rules/vue.mjs +33 -0
  119. package/dist/rules/vue.mjs.map +1 -0
  120. package/dist/typegen.d.mts +1 -1
  121. package/docs/engineering-audit.zh.md +25 -23
  122. package/docs/rules-risk.md +3 -3
  123. package/docs/rules-risk.zh.md +3 -3
  124. package/package.json +16 -6
  125. package/dist/rules/index.d.mts.map +0 -1
  126. package/dist/rules.mjs +0 -477
  127. package/dist/rules.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 2.0.4 - 2026-08-02
10
+
11
+ ### Added
12
+
13
+ - Added dedicated `@fast-china/eslint-config/configs` and `@fast-china/eslint-config/constants` subpaths for advanced Flat Config composition.
14
+
15
+ ### Changed
16
+
17
+ - Changed the `configs` and `rules` barrels to forward every module export, including configuration option types, while keeping configuration types out of the root entry.
18
+ - Changed this repository's own ESLint configuration to compose focused config fragments and constants instead of calling the root `fastConfig()` factory.
19
+ - Moved the `fastConfig()` implementation from `src/core/index.ts` directly into `src/index.ts` so the source root matches the package root entry.
20
+ - Narrowed the default preset to conventional Vue 3 browser administration projects by making Markdown linting opt-in alongside React, Angular, and manifest sorting.
21
+ - Removed Lodash policy selection from `fastConfig()` and the temporary `./lodash` subpath; optional Lodash restrictions now compose exclusively through `createLodashConfigs()` from `./configs`.
22
+ - Changed `createGlobalIgnores()` to return a config array like the other fragment factories, so direct composition consistently uses spread syntax.
23
+ - Updated `@eslint-react/eslint-plugin`, `@eslint/config-inspector`, and `globals` within their existing compatible version ranges.
24
+
9
25
  ## 2.0.3 - 2026-07-29
10
26
 
11
27
  ### Changed
package/README.md CHANGED
@@ -21,9 +21,9 @@ A practical, typed ESLint Flat Config for Vue 3, React, Angular, Vite, TypeScrip
21
21
 
22
22
  ## Requirements
23
23
 
24
- - Node.js `^22.18.0` or `>=24.11.0`
24
+ - Node.js `^22.18.0` or `^24.18.0`
25
25
  - ESLint `^10.0.0`
26
- - TypeScript `>=6.0.0 <6.1.0`
26
+ - TypeScript `^6.0.0`
27
27
 
28
28
  These versions follow the runtime requirements of ESLint 10 and the included language plugins.
29
29
 
@@ -45,13 +45,15 @@ import fastChina from "@fast-china/eslint-config";
45
45
  export default fastChina();
46
46
  ```
47
47
 
48
- The default enables Vue 3, TypeScript, JavaScript, JSON dialects, Markdown, import ordering, RegExp checks, `.gitignore`, browser globals, and Node globals for common config, script, test, and CLI files.
48
+ The default targets a conventional Vue 3 browser-based administration project. It enables Vue 3, TypeScript, JavaScript, JSON dialects, import ordering, RegExp checks, `.gitignore`, browser globals, and Node globals for common config, script, test, and CLI files. Markdown, React, Angular, and manifest sorting remain opt-in. Lodash policies are composed separately from the `configs` subpath.
49
49
 
50
50
  ## Other project types
51
51
 
52
- Use the default `fastConfig()` factory to keep only what a project needs.
52
+ Other projects can either configure the root factory or compose focused fragments directly.
53
53
 
54
- ### React + Vite
54
+ ### Use `fastConfig()`
55
+
56
+ #### React + Vite
55
57
 
56
58
  ```js
57
59
  import fastChina from "@fast-china/eslint-config";
@@ -64,7 +66,7 @@ export default fastChina({
64
66
 
65
67
  React support applies the modern `@eslint-react` JavaScript/TypeScript preset, the official React Hooks Flat Config, and additional DOM safety checks. JSX and TSX are parsed by the existing JavaScript and TypeScript integrations. For a React-compatible JSX runtime such as Preact, set `react: { importSource: "preact" }`.
66
68
 
67
- ### Angular
69
+ #### Angular
68
70
 
69
71
  ```js
70
72
  import fastChina from "@fast-china/eslint-config";
@@ -89,7 +91,7 @@ export default fastChina({
89
91
 
90
92
  Angular requires the TypeScript integration; `angular: true` together with `typescript: false` fails early with a clear configuration error.
91
93
 
92
- ### Node.js + TypeScript
94
+ #### Node.js + TypeScript
93
95
 
94
96
  ```js
95
97
  import fastChina from "@fast-china/eslint-config";
@@ -100,7 +102,7 @@ export default fastChina({
100
102
  });
101
103
  ```
102
104
 
103
- ### JavaScript only
105
+ #### JavaScript only
104
106
 
105
107
  ```js
106
108
  import fastChina from "@fast-china/eslint-config";
@@ -114,7 +116,7 @@ export default fastChina({
114
116
  });
115
117
  ```
116
118
 
117
- ### Type-aware TypeScript rules
119
+ #### Type-aware TypeScript rules
118
120
 
119
121
  ```js
120
122
  import fastChina from "@fast-china/eslint-config";
@@ -129,6 +131,45 @@ export default fastChina({
129
131
 
130
132
  Type-aware linting uses the typescript-eslint Project Service. Project files must belong to a `tsconfig.json`. Most projects can omit `tsconfigRootDir`; complex monorepos should pass the directory containing the ESLint config explicitly.
131
133
 
134
+ ### Compose config fragments directly
135
+
136
+ Projects that do not want the root factory can assemble only the required fragments. This React browser example is fully independent of `fastConfig()`:
137
+
138
+ ```js
139
+ import { defineConfig } from "eslint/config";
140
+
141
+ import {
142
+ createCommonConfigs,
143
+ createEnvironmentConfigs,
144
+ createGitignoreConfigs,
145
+ createGlobalIgnores,
146
+ createImportConfigs,
147
+ createJavaScriptConfigs,
148
+ createPrettierConfigs,
149
+ createReactConfigs,
150
+ createRegexpConfigs,
151
+ createTypeScriptConfigs,
152
+ } from "@fast-china/eslint-config/configs";
153
+ import { GLOBS_JAVASCRIPT, GLOBS_TYPESCRIPT } from "@fast-china/eslint-config/constants";
154
+
155
+ const codeFiles = [...GLOBS_JAVASCRIPT, ...GLOBS_TYPESCRIPT];
156
+
157
+ export default defineConfig([
158
+ ...createGlobalIgnores(),
159
+ ...createGitignoreConfigs(),
160
+ ...createEnvironmentConfigs({ environment: "browser", files: codeFiles, nodeFiles: codeFiles }),
161
+ ...createCommonConfigs(codeFiles),
162
+ ...createJavaScriptConfigs(),
163
+ ...createImportConfigs(codeFiles),
164
+ ...createRegexpConfigs(codeFiles),
165
+ ...createTypeScriptConfigs(),
166
+ ...createReactConfigs({}, { javascript: true, typescript: true }),
167
+ ...createPrettierConfigs(),
168
+ ]);
169
+ ```
170
+
171
+ Use `createVueConfigs()` for Vue SFCs, `createAngularConfigs()` for Angular, or set `environment: "node"` for Node.js. Fragment order is significant: project overrides should remain last.
172
+
132
173
  ## Options
133
174
 
134
175
  | Option | Default | Purpose |
@@ -141,8 +182,7 @@ Type-aware linting uses the typescript-eslint Project Service. Project files mus
141
182
  | `imports` | `true` | Enable import-x correctness and ordering rules. |
142
183
  | `javascript` | `true` | Process JavaScript and JSX files. |
143
184
  | `json` | `true` | Enable recommended JSON, JSONC, and JSON5 rules. |
144
- | `lodash` | `false` | Select `"lodash"` or `"lodash-unified"` for static imports. |
145
- | `markdown` | `true` | Enable the official Markdown language rules. |
185
+ | `markdown` | `false` | Enable the official Markdown language rules. |
146
186
  | `prettier` | `true` | Disable ESLint rules that conflict with Prettier. |
147
187
  | `react` | `false` | Enable React/JSX/Hooks, or pass runtime and React-version settings. |
148
188
  | `regexp` | `true` | Enable recommended RegExp rules. |
@@ -160,10 +200,10 @@ Svelte, Astro, and Solid use different template or compiler semantics and are no
160
200
 
161
201
  ## Lodash import policy
162
202
 
163
- The default, `lodash: false`, leaves the dependency choice to the project. Select one policy when every static import should use the same package:
203
+ Lodash policy is not a `fastConfig()` option. Import `createLodashConfigs()` from `@fast-china/eslint-config/configs` only when every static import should use one package:
164
204
 
165
- - `lodash: "lodash-unified"` rejects static imports and re-exports from `lodash`, `lodash-es`, and their subpaths.
166
- - `lodash: "lodash"` rejects static imports and re-exports from `lodash-es`, `lodash-unified`, and their subpaths. The `lodash` root and `lodash/*` method imports remain valid.
205
+ - `createLodashConfigs("lodash-unified")` rejects static imports and re-exports from `lodash`, `lodash-es`, and their subpaths.
206
+ - `createLodashConfigs("lodash")` rejects static imports and re-exports from `lodash-es`, `lodash-unified`, and their subpaths. The `lodash` root and `lodash/*` method imports remain valid.
167
207
 
168
208
  Choose `lodash-unified`:
169
209
 
@@ -172,10 +212,13 @@ pnpm add lodash-unified
172
212
  ```
173
213
 
174
214
  ```js
215
+ import { defineConfig } from "eslint/config";
216
+
175
217
  import fastChina from "@fast-china/eslint-config";
218
+ import { createLodashConfigs } from "@fast-china/eslint-config/configs";
176
219
  import { cloneDeep, debounce } from "lodash-unified";
177
220
 
178
- export default fastChina({ lodash: "lodash-unified" });
221
+ export default defineConfig([...fastChina(), ...createLodashConfigs("lodash-unified")]);
179
222
  ```
180
223
 
181
224
  Choose standard `lodash`:
@@ -186,13 +229,16 @@ pnpm add -D @types/lodash
186
229
  ```
187
230
 
188
231
  ```js
232
+ import { defineConfig } from "eslint/config";
233
+
189
234
  import fastChina from "@fast-china/eslint-config";
235
+ import { createLodashConfigs } from "@fast-china/eslint-config/configs";
190
236
  import debounce from "lodash/debounce";
191
237
 
192
- export default fastChina({ lodash: "lodash" });
238
+ export default defineConfig([...fastChina(), ...createLodashConfigs("lodash")]);
193
239
  ```
194
240
 
195
- This feature uses ESLint core `no-restricted-imports`, adds no plugin, and does not install Lodash for the project. It checks static `import`/`export` only, not dynamic `import()` or CommonJS `require()`. Setting `imports: false` disables import-x but leaves an explicitly selected Lodash policy active.
241
+ This fragment uses ESLint core `no-restricted-imports`, adds no plugin, and does not install Lodash for the project. It checks static `import`/`export` only, not dynamic `import()` or CommonJS `require()`. It is independent of the root factory's `imports` option.
196
242
 
197
243
  If a later `rules` record or file-scoped override sets `no-restricted-imports`, ESLint replaces this complete policy instead of merging its options. Projects that need additional package restrictions can import raw `preferLodashRules` or `preferLodashUnifiedRules` from `@fast-china/eslint-config/rules` and maintain one combined rule.
198
244
 
@@ -262,7 +308,20 @@ export default fastChina(
262
308
  );
263
309
  ```
264
310
 
265
- The root entry exports only `fastConfig`, `defaultConfigOptions`, `defineRules`, and their related types. Advanced consumers can import the fully commented raw rule records from `@fast-china/eslint-config/rules`.
311
+ The root entry exports only `fastConfig`, `defaultConfigOptions`, `defineRules`, `FastConfigOptions`, and `RuleOptions`. Advanced composition uses focused subpaths instead of widening the root API:
312
+
313
+ - `@fast-china/eslint-config/configs` exports every configuration creator and its option types.
314
+ - `@fast-china/eslint-config/constants` exports all maintained file globs.
315
+ - `@fast-china/eslint-config/rules` exports the fully commented raw rule records and `RuleOptions`.
316
+
317
+ ```js
318
+ import { defineConfig } from "eslint/config";
319
+
320
+ import { createCommonConfigs, createTypeScriptConfigs } from "@fast-china/eslint-config/configs";
321
+ import { GLOBS_TYPESCRIPT } from "@fast-china/eslint-config/constants";
322
+
323
+ export default defineConfig([...createCommonConfigs(GLOBS_TYPESCRIPT), ...createTypeScriptConfigs({ typeChecked: true })]);
324
+ ```
266
325
 
267
326
  ## Prettier
268
327
 
package/README.zh.md CHANGED
@@ -21,9 +21,9 @@
21
21
 
22
22
  ## 环境要求
23
23
 
24
- - Node.js `^22.18.0` 或 `>=24.11.0`
24
+ - Node.js `^22.18.0` 或 `^24.18.0`
25
25
  - ESLint `^10.0.0`
26
- - TypeScript `>=6.0.0 <6.1.0`
26
+ - TypeScript `^6.0.0`
27
27
 
28
28
  这些版本范围与 ESLint 10 及内置语言插件的运行要求保持一致。
29
29
 
@@ -45,13 +45,15 @@ import fastChina from "@fast-china/eslint-config";
45
45
  export default fastChina();
46
46
  ```
47
47
 
48
- 默认配置会启用 Vue 3、TypeScript、JavaScript、JSON 各方言、Markdown、导入排序、正则检查、`.gitignore` 与浏览器全局变量;常见配置文件、脚本、测试和 CLI 文件会额外获得 Node.js 全局变量。
48
+ 默认配置面向普通 Vue 3 浏览器后台管理项目,启用 Vue 3、TypeScript、JavaScript、JSON 各方言、导入排序、正则检查、`.gitignore` 与浏览器全局变量;常见配置文件、脚本、测试和 CLI 文件会额外获得 Node.js 全局变量。Markdown、React、Angular 和清单排序按需启用;Lodash 策略通过 `configs` 子路径独立组合。
49
49
 
50
50
  ## 适配其他项目
51
51
 
52
- 通过默认导出的 `fastConfig()` 只保留项目真正需要的能力。
52
+ 其他项目可以配置根工厂,也可以完全绕过根工厂,直接组合所需片段。
53
53
 
54
- ### React + Vite
54
+ ### 使用 `fastConfig()`
55
+
56
+ #### React + Vite
55
57
 
56
58
  ```js
57
59
  import fastChina from "@fast-china/eslint-config";
@@ -64,7 +66,7 @@ export default fastChina({
64
66
 
65
67
  React 集成会应用现代 `@eslint-react` JavaScript/TypeScript 预置、React 官方 Hooks Flat Config,以及额外的 DOM 安全检查。JSX 与 TSX 分别复用现有 JavaScript、TypeScript 解析能力。Preact 等兼容 React 的 JSX 运行时可设置 `react: { importSource: "preact" }`。
66
68
 
67
- ### Angular
69
+ #### Angular
68
70
 
69
71
  ```js
70
72
  import fastChina from "@fast-china/eslint-config";
@@ -89,7 +91,7 @@ export default fastChina({
89
91
 
90
92
  Angular 依赖 TypeScript 集成;同时设置 `angular: true` 与 `typescript: false` 时会立即抛出清晰的配置错误。
91
93
 
92
- ### Node.js + TypeScript
94
+ #### Node.js + TypeScript
93
95
 
94
96
  ```js
95
97
  import fastChina from "@fast-china/eslint-config";
@@ -100,7 +102,7 @@ export default fastChina({
100
102
  });
101
103
  ```
102
104
 
103
- ### 纯 JavaScript
105
+ #### 纯 JavaScript
104
106
 
105
107
  ```js
106
108
  import fastChina from "@fast-china/eslint-config";
@@ -114,7 +116,7 @@ export default fastChina({
114
116
  });
115
117
  ```
116
118
 
117
- ### 启用 TypeScript 类型感知规则
119
+ #### 启用 TypeScript 类型感知规则
118
120
 
119
121
  ```js
120
122
  import fastChina from "@fast-china/eslint-config";
@@ -129,6 +131,45 @@ export default fastChina({
129
131
 
130
132
  类型感知模式使用 typescript-eslint Project Service,被检查的文件必须属于某个 `tsconfig.json`。普通项目通常可省略 `tsconfigRootDir`;复杂 monorepo 建议显式传入配置文件所在目录。
131
133
 
134
+ ### 直接组合配置片段
135
+
136
+ 不希望使用根工厂的项目可以只组装需要的片段。以下 React 浏览器项目示例完全不依赖 `fastConfig()`:
137
+
138
+ ```js
139
+ import { defineConfig } from "eslint/config";
140
+
141
+ import {
142
+ createCommonConfigs,
143
+ createEnvironmentConfigs,
144
+ createGitignoreConfigs,
145
+ createGlobalIgnores,
146
+ createImportConfigs,
147
+ createJavaScriptConfigs,
148
+ createPrettierConfigs,
149
+ createReactConfigs,
150
+ createRegexpConfigs,
151
+ createTypeScriptConfigs,
152
+ } from "@fast-china/eslint-config/configs";
153
+ import { GLOBS_JAVASCRIPT, GLOBS_TYPESCRIPT } from "@fast-china/eslint-config/constants";
154
+
155
+ const codeFiles = [...GLOBS_JAVASCRIPT, ...GLOBS_TYPESCRIPT];
156
+
157
+ export default defineConfig([
158
+ ...createGlobalIgnores(),
159
+ ...createGitignoreConfigs(),
160
+ ...createEnvironmentConfigs({ environment: "browser", files: codeFiles, nodeFiles: codeFiles }),
161
+ ...createCommonConfigs(codeFiles),
162
+ ...createJavaScriptConfigs(),
163
+ ...createImportConfigs(codeFiles),
164
+ ...createRegexpConfigs(codeFiles),
165
+ ...createTypeScriptConfigs(),
166
+ ...createReactConfigs({}, { javascript: true, typescript: true }),
167
+ ...createPrettierConfigs(),
168
+ ]);
169
+ ```
170
+
171
+ Vue SFC 可增加 `createVueConfigs()`,Angular 可增加 `createAngularConfigs()`,Node.js 项目则将环境设为 `"node"`。配置片段的顺序具有语义,项目覆写应始终放在最后。
172
+
132
173
  ## 配置选项
133
174
 
134
175
  | 选项 | 默认值 | 作用 |
@@ -141,8 +182,7 @@ export default fastChina({
141
182
  | `imports` | `true` | 启用 import-x 正确性与排序规则。 |
142
183
  | `javascript` | `true` | 处理 JavaScript 与 JSX。 |
143
184
  | `json` | `true` | 启用 JSON、JSONC 与 JSON5 推荐规则。 |
144
- | `lodash` | `false` | 可选 `"lodash"` 或 `"lodash-unified"`,统一静态导入来源。 |
145
- | `markdown` | `true` | 启用官方 Markdown 语言规则。 |
185
+ | `markdown` | `false` | 启用官方 Markdown 语言规则。 |
146
186
  | `prettier` | `true` | 关闭与 Prettier 冲突的 ESLint 规则。 |
147
187
  | `react` | `false` | 启用 React、JSX 与 Hooks,或传入运行时和 React 版本设置。 |
148
188
  | `regexp` | `true` | 启用推荐的正则表达式规则。 |
@@ -160,10 +200,10 @@ Svelte、Astro 与 Solid 具有不同的模板或编译器语义,目前不会
160
200
 
161
201
  ## Lodash 导入策略
162
202
 
163
- 默认值 `lodash: false` 不限制项目选择。需要统一依赖入口时,可选择以下任一策略:
203
+ Lodash 策略不是 `fastConfig()` 选项。只有需要统一静态导入来源时,才从 `@fast-china/eslint-config/configs` 导入 `createLodashConfigs()`:
164
204
 
165
- - `lodash: "lodash-unified"`:禁止从 `lodash`、`lodash-es` 及其子路径静态导入或重新导出。
166
- - `lodash: "lodash"`:禁止从 `lodash-es`、`lodash-unified` 及其子路径静态导入或重新导出;允许 `lodash` 根入口和 `lodash/*` 按方法导入。
205
+ - `createLodashConfigs("lodash-unified")`:禁止从 `lodash`、`lodash-es` 及其子路径静态导入或重新导出。
206
+ - `createLodashConfigs("lodash")`:禁止从 `lodash-es`、`lodash-unified` 及其子路径静态导入或重新导出;允许 `lodash` 根入口和 `lodash/*` 按方法导入。
167
207
 
168
208
  选择 `lodash-unified`:
169
209
 
@@ -172,10 +212,13 @@ pnpm add lodash-unified
172
212
  ```
173
213
 
174
214
  ```js
215
+ import { defineConfig } from "eslint/config";
216
+
175
217
  import fastChina from "@fast-china/eslint-config";
218
+ import { createLodashConfigs } from "@fast-china/eslint-config/configs";
176
219
  import { cloneDeep, debounce } from "lodash-unified";
177
220
 
178
- export default fastChina({ lodash: "lodash-unified" });
221
+ export default defineConfig([...fastChina(), ...createLodashConfigs("lodash-unified")]);
179
222
  ```
180
223
 
181
224
  选择标准 `lodash`:
@@ -186,13 +229,16 @@ pnpm add -D @types/lodash
186
229
  ```
187
230
 
188
231
  ```js
232
+ import { defineConfig } from "eslint/config";
233
+
189
234
  import fastChina from "@fast-china/eslint-config";
235
+ import { createLodashConfigs } from "@fast-china/eslint-config/configs";
190
236
  import debounce from "lodash/debounce";
191
237
 
192
- export default fastChina({ lodash: "lodash" });
238
+ export default defineConfig([...fastChina(), ...createLodashConfigs("lodash")]);
193
239
  ```
194
240
 
195
- 该能力使用 ESLint 核心 `no-restricted-imports`,不需要额外插件,也不会替项目安装 Lodash。它只检查静态 `import`/`export`,不检查动态 `import()` 或 CommonJS `require()`。`imports: false` 只关闭 import-x,不会关闭已经显式选择的 Lodash 策略。
241
+ 该片段使用 ESLint 核心 `no-restricted-imports`,不需要额外插件,也不会替项目安装 Lodash。它只检查静态 `import`/`export`,不检查动态 `import()` 或 CommonJS `require()`,并且独立于根工厂的 `imports` 选项。
196
242
 
197
243
  如果后续 `rules` 或文件级覆写再次设置 `no-restricted-imports`,ESLint 会用后面的完整规则替换这套策略,而不是合并选项。需要组合更多包限制时,可从 `@fast-china/eslint-config/rules` 导入原始 `preferLodashRules` 或 `preferLodashUnifiedRules`,统一维护一份完整规则。
198
244
 
@@ -262,7 +308,20 @@ export default fastChina(
262
308
  );
263
309
  ```
264
310
 
265
- 根入口只公开 `fastConfig`、`defaultConfigOptions`、`defineRules` 及相关类型。高级使用者可以从 `@fast-china/eslint-config/rules` 导入有完整注释的原始规则记录。
311
+ 根入口只公开 `fastConfig`、`defaultConfigOptions`、`defineRules`、`FastConfigOptions` `RuleOptions`。高级组合通过职责明确的子路径完成,避免扩大根入口:
312
+
313
+ - `@fast-china/eslint-config/configs` 导出全部配置创建函数及其选项类型。
314
+ - `@fast-china/eslint-config/constants` 导出项目维护的全部文件 glob。
315
+ - `@fast-china/eslint-config/rules` 导出带完整注释的原始规则记录和 `RuleOptions`。
316
+
317
+ ```js
318
+ import { defineConfig } from "eslint/config";
319
+
320
+ import { createCommonConfigs, createTypeScriptConfigs } from "@fast-china/eslint-config/configs";
321
+ import { GLOBS_TYPESCRIPT } from "@fast-china/eslint-config/constants";
322
+
323
+ export default defineConfig([...createCommonConfigs(GLOBS_TYPESCRIPT), ...createTypeScriptConfigs({ typeChecked: true })]);
324
+ ```
266
325
 
267
326
  ## Prettier
268
327
 
@@ -0,0 +1,41 @@
1
+ //#region src/configs/angular.d.ts
2
+ /**
3
+ * Angular TypeScript 源码与 HTML 模板检查的细分选项。
4
+ *
5
+ * 该对象通过 `fastConfig({ angular: { ... } })` 传入。只要传入对象,Angular 支持就会
6
+ * 被启用;未指定的字段继续使用各自默认值。Angular 配置始终包含框架 TypeScript 规则
7
+ * 和外部 `.html` 模板基础规则,本接口只控制成本或迁移影响较高的可选部分。
8
+ *
9
+ * Angular 支持依赖顶层 `typescript` 能力,不能与 `typescript: false` 同时使用。
10
+ * 这些选项不会修改 Angular 编译器、CLI 或模板类型检查配置。
11
+ */
12
+ interface AngularConfigOptions {
13
+ /**
14
+ * 是否使用 Angular 官方 processor,从 TypeScript 文件的
15
+ * `@Component({ template: ... })` 元数据中提取内联 HTML 并复用模板规则进行检查。
16
+ *
17
+ * 关闭后仍会检查 Angular TypeScript 源码和外部 `.html` 模板,只是不再处理组件中的
18
+ * 内联模板。大型项目若主要使用外部模板,或 processor 与其他工具发生冲突,可暂时关闭。
19
+ * @default true
20
+ */
21
+ inlineTemplates?: boolean;
22
+ /**
23
+ * 是否在模板基础正确性规则之外启用 Angular 模板无障碍规则组。
24
+ *
25
+ * 该规则组检查替代文本、键盘交互、焦点、表单标签和 ARIA 等可访问性问题,适用于
26
+ * 外部模板与已提取的内联模板。关闭后仍保留模板语法、严格比较和现代控制流等基础规则。
27
+ * 对旧项目而言可能一次产生较多报告,建议在确认迁移计划后再决定是否临时关闭。
28
+ * @default true
29
+ */
30
+ templateAccessibility?: boolean;
31
+ }
32
+ /**
33
+ * 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。
34
+ *
35
+ * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由
36
+ * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。
37
+ */
38
+ declare const createAngularConfigs: ({ inlineTemplates, templateAccessibility }?: AngularConfigOptions) => import("eslint/config").ConfigObject[];
39
+ //#endregion
40
+ export { AngularConfigOptions, createAngularConfigs };
41
+ //# sourceMappingURL=angular.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.d.mts","names":[],"sources":["../../src/configs/angular.ts"],"mappings":";;;;;;;;;;;UAoBiB;;;;;;;;;EAShB;;;;;;;;;EASA;;;;;;;;cASY,yBAAwB,iBAAA,0BAA0D,iDAAyB"}
@@ -0,0 +1,33 @@
1
+ import { GLOB_ANGULAR_TEMPLATE, GLOB_ANGULAR_TYPESCRIPT } from "../constants/index.mjs";
2
+ import { angularRules, angularTemplateAccessibilityRules, angularTemplateRules } from "../rules/angular.mjs";
3
+ import angularPlugin from "@angular-eslint/eslint-plugin";
4
+ import angularTemplatePlugin from "@angular-eslint/eslint-plugin-template";
5
+ import angularTemplateParser from "@angular-eslint/template-parser";
6
+ import { defineConfig } from "eslint/config";
7
+ //#region src/configs/angular.ts
8
+ /**
9
+ * 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。
10
+ *
11
+ * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由
12
+ * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。
13
+ */
14
+ const createAngularConfigs = ({ inlineTemplates = true, templateAccessibility = true } = {}) => defineConfig([{
15
+ name: inlineTemplates ? "@fast-china/angular/typescript-with-inline-templates" : "@fast-china/angular/typescript",
16
+ files: [GLOB_ANGULAR_TYPESCRIPT],
17
+ plugins: { "@angular-eslint": angularPlugin },
18
+ ...inlineTemplates ? { processor: angularTemplatePlugin.processors["extract-inline-html"] } : {},
19
+ rules: angularRules
20
+ }, {
21
+ name: templateAccessibility ? "@fast-china/angular/template-accessibility" : "@fast-china/angular/template",
22
+ files: [GLOB_ANGULAR_TEMPLATE],
23
+ languageOptions: { parser: angularTemplateParser },
24
+ plugins: { "@angular-eslint/template": angularTemplatePlugin },
25
+ rules: {
26
+ ...angularTemplateRules,
27
+ ...templateAccessibility ? angularTemplateAccessibilityRules : {}
28
+ }
29
+ }]);
30
+ //#endregion
31
+ export { createAngularConfigs };
32
+
33
+ //# sourceMappingURL=angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.mjs","names":[],"sources":["../../src/configs/angular.ts"],"sourcesContent":["import angularPlugin from \"@angular-eslint/eslint-plugin\";\nimport angularTemplatePlugin from \"@angular-eslint/eslint-plugin-template\";\nimport angularTemplateParser from \"@angular-eslint/template-parser\";\nimport { defineConfig } from \"eslint/config\";\n\nimport { GLOB_ANGULAR_TEMPLATE, GLOB_ANGULAR_TYPESCRIPT } from \"../constants\";\nimport { angularRules, angularTemplateAccessibilityRules, angularTemplateRules } from \"../rules\";\n\nimport type { ESLint, Linter } from \"eslint\";\n\n/**\n * Angular TypeScript 源码与 HTML 模板检查的细分选项。\n *\n * 该对象通过 `fastConfig({ angular: { ... } })` 传入。只要传入对象,Angular 支持就会\n * 被启用;未指定的字段继续使用各自默认值。Angular 配置始终包含框架 TypeScript 规则\n * 和外部 `.html` 模板基础规则,本接口只控制成本或迁移影响较高的可选部分。\n *\n * Angular 支持依赖顶层 `typescript` 能力,不能与 `typescript: false` 同时使用。\n * 这些选项不会修改 Angular 编译器、CLI 或模板类型检查配置。\n */\nexport interface AngularConfigOptions {\n\t/**\n\t * 是否使用 Angular 官方 processor,从 TypeScript 文件的\n\t * `@Component({ template: ... })` 元数据中提取内联 HTML 并复用模板规则进行检查。\n\t *\n\t * 关闭后仍会检查 Angular TypeScript 源码和外部 `.html` 模板,只是不再处理组件中的\n\t * 内联模板。大型项目若主要使用外部模板,或 processor 与其他工具发生冲突,可暂时关闭。\n\t * @default true\n\t */\n\tinlineTemplates?: boolean;\n\t/**\n\t * 是否在模板基础正确性规则之外启用 Angular 模板无障碍规则组。\n\t *\n\t * 该规则组检查替代文本、键盘交互、焦点、表单标签和 ARIA 等可访问性问题,适用于\n\t * 外部模板与已提取的内联模板。关闭后仍保留模板语法、严格比较和现代控制流等基础规则。\n\t * 对旧项目而言可能一次产生较多报告,建议在确认迁移计划后再决定是否临时关闭。\n\t * @default true\n\t */\n\ttemplateAccessibility?: boolean;\n}\n\n/**\n * 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。\n *\n * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由\n * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。\n */\nexport const createAngularConfigs = ({ inlineTemplates = true, templateAccessibility = true }: AngularConfigOptions = {}) =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: inlineTemplates ? \"@fast-china/angular/typescript-with-inline-templates\" : \"@fast-china/angular/typescript\",\n\t\t\tfiles: [GLOB_ANGULAR_TYPESCRIPT],\n\t\t\tplugins: {\n\t\t\t\t\"@angular-eslint\": angularPlugin as unknown as ESLint.Plugin,\n\t\t\t},\n\t\t\t...(inlineTemplates\n\t\t\t\t? {\n\t\t\t\t\t\tprocessor: angularTemplatePlugin.processors[\"extract-inline-html\"] as Linter.Processor,\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\trules: angularRules,\n\t\t},\n\t\t{\n\t\t\tname: templateAccessibility ? \"@fast-china/angular/template-accessibility\" : \"@fast-china/angular/template\",\n\t\t\tfiles: [GLOB_ANGULAR_TEMPLATE],\n\t\t\tlanguageOptions: {\n\t\t\t\tparser: angularTemplateParser as unknown as Linter.Parser,\n\t\t\t},\n\t\t\tplugins: {\n\t\t\t\t\"@angular-eslint/template\": angularTemplatePlugin as unknown as ESLint.Plugin,\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t...angularTemplateRules,\n\t\t\t\t...(templateAccessibility ? angularTemplateAccessibilityRules : {}),\n\t\t\t},\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;;;;AA+CA,MAAa,wBAAwB,EAAE,kBAAkB,MAAM,wBAAwB,SAA+B,CAAC,MACtH,aAAa,CACZ;CACC,MAAM,kBAAkB,yDAAyD;CACjF,OAAO,CAAC,uBAAuB;CAC/B,SAAS,EACR,mBAAmB,cACpB;CACA,GAAI,kBACD,EACA,WAAW,sBAAsB,WAAW,uBAC7C,IACC,CAAC;CACJ,OAAO;AACR,GACA;CACC,MAAM,wBAAwB,+CAA+C;CAC7E,OAAO,CAAC,qBAAqB;CAC7B,iBAAiB,EAChB,QAAQ,sBACT;CACA,SAAS,EACR,4BAA4B,sBAC7B;CACA,OAAO;EACN,GAAG;EACH,GAAI,wBAAwB,oCAAoC,CAAC;CAClE;AACD,CACD,CAAC"}
@@ -0,0 +1,11 @@
1
+ //#region src/configs/common.d.ts
2
+ /**
3
+ * 创建跨 JavaScript、TypeScript 与 Vue 脚本生效的通用配置。
4
+ *
5
+ * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后
6
+ * 留下长期失效的抑制注释。
7
+ */
8
+ declare const createCommonConfigs: (files?: readonly string[]) => import("eslint/config").ConfigObject[];
9
+ //#endregion
10
+ export { createCommonConfigs };
11
+ //# sourceMappingURL=common.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.mts","names":[],"sources":["../../src/configs/common.ts"],"mappings":";;;;;;;cAWa,sBAAuB,sDAAqC"}
@@ -0,0 +1,20 @@
1
+ import { GLOBS_CODE } from "../constants/index.mjs";
2
+ import { commonRules } from "../rules/common.mjs";
3
+ import { defineConfig } from "eslint/config";
4
+ //#region src/configs/common.ts
5
+ /**
6
+ * 创建跨 JavaScript、TypeScript 与 Vue 脚本生效的通用配置。
7
+ *
8
+ * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后
9
+ * 留下长期失效的抑制注释。
10
+ */
11
+ const createCommonConfigs = (files = GLOBS_CODE) => defineConfig([{
12
+ name: "@fast-china/common",
13
+ files: [...files],
14
+ linterOptions: { reportUnusedDisableDirectives: "error" },
15
+ rules: commonRules
16
+ }]);
17
+ //#endregion
18
+ export { createCommonConfigs };
19
+
20
+ //# sourceMappingURL=common.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.mjs","names":[],"sources":["../../src/configs/common.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\n\nimport { GLOBS_CODE } from \"../constants\";\nimport { commonRules } from \"../rules\";\n\n/**\n * 创建跨 JavaScript、TypeScript 与 Vue 脚本生效的通用配置。\n *\n * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后\n * 留下长期失效的抑制注释。\n */\nexport const createCommonConfigs = (files: readonly string[] = GLOBS_CODE) =>\n\tdefineConfig([\n\t\t{\n\t\t\tname: \"@fast-china/common\",\n\t\t\tfiles: [...files],\n\t\t\tlinterOptions: {\n\t\t\t\treportUnusedDisableDirectives: \"error\",\n\t\t\t},\n\t\t\trules: commonRules,\n\t\t},\n\t]);\n"],"mappings":";;;;;;;;;;AAWA,MAAa,uBAAuB,QAA2B,eAC9D,aAAa,CACZ;CACC,MAAM;CACN,OAAO,CAAC,GAAG,KAAK;CAChB,eAAe,EACd,+BAA+B,QAChC;CACA,OAAO;AACR,CACD,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { Linter } from "eslint";
2
+ //#region src/configs/environment.d.ts
3
+ type RuntimeEnvironment = "browser" | "node" | "universal";
4
+ /**
5
+ * 运行时全局变量配置片段的选项。
6
+ *
7
+ * `fastConfig()` 会根据已启用的语言和框架计算 `files`、`nodeFiles`,再调用
8
+ * `createEnvironmentConfigs()`。该接口仍保持独立,以便环境片段的输入、默认值和文件
9
+ * 范围在源码中具有明确契约;直接组合配置片段时可从 `./configs` 子路径使用。
10
+ *
11
+ * 应用代码与 Node.js 工程文件使用两个独立 Flat Config 片段,避免浏览器源码无条件获得
12
+ * `process`、`Buffer` 等 Node.js 全局变量,也避免配置文件误报这些合法全局变量未定义。
13
+ */
14
+ interface EnvironmentConfigOptions {
15
+ /**
16
+ * 应用代码实际运行的环境,决定 `files` 范围内注入哪组标准全局变量。
17
+ *
18
+ * `"browser"` 只注入浏览器全局变量,`"node"` 只注入 Node.js 全局变量,
19
+ * `"universal"` 同时注入两组。该值不会影响 `nodeFiles` 对应的工程文件;后者始终
20
+ * 使用 Node.js 全局变量。
21
+ * @default "browser"
22
+ */
23
+ environment?: RuntimeEnvironment;
24
+ /**
25
+ * 需要获得所选运行时全局变量的应用代码 glob 列表。
26
+ *
27
+ * 工厂会把当前启用的 JavaScript、TypeScript 和 Vue 文件范围传入这里。数组会复制到
28
+ * 生成配置中,不会在函数内部修改调用方传入的值。
29
+ * @default GLOBS_CODE
30
+ */
31
+ files?: readonly string[];
32
+ /**
33
+ * 当前启用且允许作为 Node.js 工程文件执行的脚本扩展名 glob 列表。
34
+ *
35
+ * 每一项都会与内置的配置文件、脚本目录、测试文件和 CLI 文件模式组合为 ESLint
36
+ * Flat Config 的 AND 文件条件。例如顶层关闭 TypeScript 后,Node.js 工程片段也不会
37
+ * 因自身模式较宽而意外接管 `.ts` 文件。
38
+ * @default GLOBS_JAVASCRIPT
39
+ */
40
+ nodeFiles?: readonly string[];
41
+ /**
42
+ * 追加到应用代码环境中的项目级全局变量及其读写权限。
43
+ *
44
+ * 该记录在标准环境全局变量之后合并,所以同名条目可以覆盖预置权限。它应用于完整
45
+ * `files` 范围;其中属于 Node.js 工程文件的子集还会由后续片段追加标准 Node.js 全局
46
+ * 变量。值格式遵循 ESLint `Linter.Globals`。
47
+ * @default {}
48
+ */
49
+ globals?: Linter.Globals;
50
+ }
51
+ /**
52
+ * 创建运行时环境相关的 ESLint 配置。
53
+ *
54
+ * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局
55
+ * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量
56
+ * 并允许使用 `console`。分离范围可以减少跨运行时的假阴性。
57
+ */
58
+ declare const createEnvironmentConfigs: ({ environment, files, nodeFiles, globals: projectGlobals }?: EnvironmentConfigOptions) => import("eslint/config").ConfigObject[];
59
+ //#endregion
60
+ export { EnvironmentConfigOptions, RuntimeEnvironment, createEnvironmentConfigs };
61
+ //# sourceMappingURL=environment.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.d.mts","names":[],"sources":["../../src/configs/environment.ts"],"mappings":";;KAOY;;;;;;;;;;;UAYK;;;;;;;;;EAShB,cAAc;;;;;;;;EAQd;;;;;;;;;EASA;;;;;;;;;EASA,UAAU,OAAO;;;;;;;;;cAUL,6BAA4B,aAAA,OAAA,WAAA,SAAA,mBAKtC,qDAA6B"}
@@ -0,0 +1,33 @@
1
+ import { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_NODE_TOOLING } from "../constants/index.mjs";
2
+ import { defineConfig } from "eslint/config";
3
+ import globals from "globals";
4
+ //#region src/configs/environment.ts
5
+ /**
6
+ * 创建运行时环境相关的 ESLint 配置。
7
+ *
8
+ * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局
9
+ * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量
10
+ * 并允许使用 `console`。分离范围可以减少跨运行时的假阴性。
11
+ */
12
+ const createEnvironmentConfigs = ({ environment = "browser", files = GLOBS_CODE, nodeFiles = GLOBS_JAVASCRIPT, globals: projectGlobals = {} } = {}) => {
13
+ const runtimeGlobals = {
14
+ ...environment !== "node" ? globals.browser : {},
15
+ ...environment !== "browser" ? globals.node : {},
16
+ ...projectGlobals
17
+ };
18
+ const nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));
19
+ return defineConfig([{
20
+ name: `@fast-china/globals/${environment}`,
21
+ files: [...files],
22
+ languageOptions: { globals: runtimeGlobals }
23
+ }, {
24
+ name: "@fast-china/globals/node-tooling",
25
+ files: nodeToolingFiles,
26
+ languageOptions: { globals: globals.node },
27
+ rules: { "no-console": "off" }
28
+ }]);
29
+ };
30
+ //#endregion
31
+ export { createEnvironmentConfigs };
32
+
33
+ //# sourceMappingURL=environment.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment.mjs","names":[],"sources":["../../src/configs/environment.ts"],"sourcesContent":["import { defineConfig } from \"eslint/config\";\nimport globals from \"globals\";\n\nimport { GLOBS_CODE, GLOBS_JAVASCRIPT, GLOBS_NODE_TOOLING } from \"../constants\";\n\nimport type { Linter } from \"eslint\";\n\nexport type RuntimeEnvironment = \"browser\" | \"node\" | \"universal\";\n\n/**\n * 运行时全局变量配置片段的选项。\n *\n * `fastConfig()` 会根据已启用的语言和框架计算 `files`、`nodeFiles`,再调用\n * `createEnvironmentConfigs()`。该接口仍保持独立,以便环境片段的输入、默认值和文件\n * 范围在源码中具有明确契约;直接组合配置片段时可从 `./configs` 子路径使用。\n *\n * 应用代码与 Node.js 工程文件使用两个独立 Flat Config 片段,避免浏览器源码无条件获得\n * `process`、`Buffer` 等 Node.js 全局变量,也避免配置文件误报这些合法全局变量未定义。\n */\nexport interface EnvironmentConfigOptions {\n\t/**\n\t * 应用代码实际运行的环境,决定 `files` 范围内注入哪组标准全局变量。\n\t *\n\t * `\"browser\"` 只注入浏览器全局变量,`\"node\"` 只注入 Node.js 全局变量,\n\t * `\"universal\"` 同时注入两组。该值不会影响 `nodeFiles` 对应的工程文件;后者始终\n\t * 使用 Node.js 全局变量。\n\t * @default \"browser\"\n\t */\n\tenvironment?: RuntimeEnvironment;\n\t/**\n\t * 需要获得所选运行时全局变量的应用代码 glob 列表。\n\t *\n\t * 工厂会把当前启用的 JavaScript、TypeScript 和 Vue 文件范围传入这里。数组会复制到\n\t * 生成配置中,不会在函数内部修改调用方传入的值。\n\t * @default GLOBS_CODE\n\t */\n\tfiles?: readonly string[];\n\t/**\n\t * 当前启用且允许作为 Node.js 工程文件执行的脚本扩展名 glob 列表。\n\t *\n\t * 每一项都会与内置的配置文件、脚本目录、测试文件和 CLI 文件模式组合为 ESLint\n\t * Flat Config 的 AND 文件条件。例如顶层关闭 TypeScript 后,Node.js 工程片段也不会\n\t * 因自身模式较宽而意外接管 `.ts` 文件。\n\t * @default GLOBS_JAVASCRIPT\n\t */\n\tnodeFiles?: readonly string[];\n\t/**\n\t * 追加到应用代码环境中的项目级全局变量及其读写权限。\n\t *\n\t * 该记录在标准环境全局变量之后合并,所以同名条目可以覆盖预置权限。它应用于完整\n\t * `files` 范围;其中属于 Node.js 工程文件的子集还会由后续片段追加标准 Node.js 全局\n\t * 变量。值格式遵循 ESLint `Linter.Globals`。\n\t * @default {}\n\t */\n\tglobals?: Linter.Globals;\n}\n\n/**\n * 创建运行时环境相关的 ESLint 配置。\n *\n * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局\n * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量\n * 并允许使用 `console`。分离范围可以减少跨运行时的假阴性。\n */\nexport const createEnvironmentConfigs = ({\n\tenvironment = \"browser\",\n\tfiles = GLOBS_CODE,\n\tnodeFiles = GLOBS_JAVASCRIPT,\n\tglobals: projectGlobals = {},\n}: EnvironmentConfigOptions = {}) => {\n\tconst runtimeGlobals = {\n\t\t...(environment !== \"node\" ? globals.browser : {}),\n\t\t...(environment !== \"browser\" ? globals.node : {}),\n\t\t...projectGlobals,\n\t};\n\tconst nodeToolingFiles = GLOBS_NODE_TOOLING.flatMap((nodeGlob) => nodeFiles.map((fileGlob) => [nodeGlob, fileGlob]));\n\n\treturn defineConfig([\n\t\t{\n\t\t\tname: `@fast-china/globals/${environment}`,\n\t\t\tfiles: [...files],\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: runtimeGlobals,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"@fast-china/globals/node-tooling\",\n\t\t\tfiles: nodeToolingFiles,\n\t\t\tlanguageOptions: {\n\t\t\t\tglobals: globals.node,\n\t\t\t},\n\t\t\trules: {\n\t\t\t\t\"no-console\": \"off\",\n\t\t\t},\n\t\t},\n\t]);\n};\n"],"mappings":";;;;;;;;;;;AAgEA,MAAa,4BAA4B,EACxC,cAAc,WACd,QAAQ,YACR,YAAY,kBACZ,SAAS,iBAAiB,CAAC,MACE,CAAC,MAAM;CACpC,MAAM,iBAAiB;EACtB,GAAI,gBAAgB,SAAS,QAAQ,UAAU,CAAC;EAChD,GAAI,gBAAgB,YAAY,QAAQ,OAAO,CAAC;EAChD,GAAG;CACJ;CACA,MAAM,mBAAmB,mBAAmB,SAAS,aAAa,UAAU,KAAK,aAAa,CAAC,UAAU,QAAQ,CAAC,CAAC;CAEnH,OAAO,aAAa,CACnB;EACC,MAAM,uBAAuB;EAC7B,OAAO,CAAC,GAAG,KAAK;EAChB,iBAAiB,EAChB,SAAS,eACV;CACD,GACA;EACC,MAAM;EACN,OAAO;EACP,iBAAiB,EAChB,SAAS,QAAQ,KAClB;EACA,OAAO,EACN,cAAc,MACf;CACD,CACD,CAAC;AACF"}