@fast-china/eslint-config 2.0.3 → 2.0.5

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 +23 -0
  2. package/README.md +78 -19
  3. package/README.zh.md +78 -19
  4. package/dist/configs/angular.d.mts +46 -0
  5. package/dist/configs/angular.d.mts.map +1 -0
  6. package/dist/configs/angular.mjs +37 -0
  7. package/dist/configs/angular.mjs.map +1 -0
  8. package/dist/configs/common.d.mts +15 -0
  9. package/dist/configs/common.d.mts.map +1 -0
  10. package/dist/configs/common.mjs +24 -0
  11. package/dist/configs/common.mjs.map +1 -0
  12. package/dist/configs/environment.d.mts +73 -0
  13. package/dist/configs/environment.d.mts.map +1 -0
  14. package/dist/configs/environment.mjs +37 -0
  15. package/dist/configs/environment.mjs.map +1 -0
  16. package/dist/configs/ignores.d.mts +29 -0
  17. package/dist/configs/ignores.d.mts.map +1 -0
  18. package/dist/configs/ignores.mjs +46 -0
  19. package/dist/configs/ignores.mjs.map +1 -0
  20. package/dist/configs/import.d.mts +15 -0
  21. package/dist/configs/import.d.mts.map +1 -0
  22. package/dist/configs/import.mjs +25 -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 +15 -0
  27. package/dist/configs/javascript.d.mts.map +1 -0
  28. package/dist/configs/javascript.mjs +29 -0
  29. package/dist/configs/javascript.mjs.map +1 -0
  30. package/dist/configs/json.d.mts +14 -0
  31. package/dist/configs/json.d.mts.map +1 -0
  32. package/dist/configs/json.mjs +39 -0
  33. package/dist/configs/json.mjs.map +1 -0
  34. package/dist/configs/lodash.d.mts +22 -0
  35. package/dist/configs/lodash.d.mts.map +1 -0
  36. package/dist/configs/lodash.mjs +24 -0
  37. package/dist/configs/lodash.mjs.map +1 -0
  38. package/dist/configs/markdown.d.mts +13 -0
  39. package/dist/configs/markdown.d.mts.map +1 -0
  40. package/dist/configs/markdown.mjs +21 -0
  41. package/dist/configs/markdown.mjs.map +1 -0
  42. package/dist/configs/prettier.d.mts +14 -0
  43. package/dist/configs/prettier.d.mts.map +1 -0
  44. package/dist/configs/prettier.mjs +20 -0
  45. package/dist/configs/prettier.mjs.map +1 -0
  46. package/dist/configs/react.d.mts +93 -0
  47. package/dist/configs/react.d.mts.map +1 -0
  48. package/dist/configs/react.mjs +36 -0
  49. package/dist/configs/react.mjs.map +1 -0
  50. package/dist/configs/regexp.d.mts +15 -0
  51. package/dist/configs/regexp.d.mts.map +1 -0
  52. package/dist/configs/regexp.mjs +23 -0
  53. package/dist/configs/regexp.mjs.map +1 -0
  54. package/dist/configs/sort-package.d.mts +14 -0
  55. package/dist/configs/sort-package.d.mts.map +1 -0
  56. package/dist/configs/sort-package.mjs +21 -0
  57. package/dist/configs/sort-package.mjs.map +1 -0
  58. package/dist/configs/sort-tsconfig.d.mts +13 -0
  59. package/dist/configs/sort-tsconfig.d.mts.map +1 -0
  60. package/dist/configs/sort-tsconfig.mjs +21 -0
  61. package/dist/configs/sort-tsconfig.mjs.map +1 -0
  62. package/dist/configs/typescript.d.mts +76 -0
  63. package/dist/configs/typescript.d.mts.map +1 -0
  64. package/dist/configs/typescript.mjs +59 -0
  65. package/dist/configs/typescript.mjs.map +1 -0
  66. package/dist/configs/vue.d.mts +48 -0
  67. package/dist/configs/vue.d.mts.map +1 -0
  68. package/dist/configs/vue.mjs +54 -0
  69. package/dist/configs/vue.mjs.map +1 -0
  70. package/dist/constants/index.d.mts +44 -0
  71. package/dist/constants/index.d.mts.map +1 -0
  72. package/dist/constants/index.mjs +62 -0
  73. package/dist/constants/index.mjs.map +1 -0
  74. package/dist/index.d.mts +65 -163
  75. package/dist/index.d.mts.map +1 -1
  76. package/dist/index.mjs +56 -397
  77. package/dist/index.mjs.map +1 -1
  78. package/dist/rules/angular.d.mts +59 -0
  79. package/dist/rules/angular.d.mts.map +1 -0
  80. package/dist/rules/angular.mjs +60 -0
  81. package/dist/rules/angular.mjs.map +1 -0
  82. package/dist/rules/common.d.mts +33 -0
  83. package/dist/rules/common.d.mts.map +1 -0
  84. package/dist/rules/common.mjs +39 -0
  85. package/dist/rules/common.mjs.map +1 -0
  86. package/dist/rules/import.d.mts +30 -0
  87. package/dist/rules/import.d.mts.map +1 -0
  88. package/dist/rules/import.mjs +41 -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 +50 -0
  93. package/dist/rules/javascript.d.mts.map +1 -0
  94. package/dist/rules/javascript.mjs +51 -0
  95. package/dist/rules/javascript.mjs.map +1 -0
  96. package/dist/rules/lodash.d.mts +42 -0
  97. package/dist/rules/lodash.d.mts.map +1 -0
  98. package/dist/rules/lodash.mjs +45 -0
  99. package/dist/rules/lodash.mjs.map +1 -0
  100. package/dist/rules/react.d.mts +27 -0
  101. package/dist/rules/react.d.mts.map +1 -0
  102. package/dist/rules/react.mjs +28 -0
  103. package/dist/rules/react.mjs.map +1 -0
  104. package/dist/rules/sort-package.d.mts +33 -0
  105. package/dist/rules/sort-package.d.mts.map +1 -0
  106. package/dist/rules/sort-package.mjs +76 -0
  107. package/dist/rules/sort-package.mjs.map +1 -0
  108. package/dist/rules/sort-tsconfig.d.mts +21 -0
  109. package/dist/rules/sort-tsconfig.d.mts.map +1 -0
  110. package/dist/rules/sort-tsconfig.mjs +123 -0
  111. package/dist/rules/sort-tsconfig.mjs.map +1 -0
  112. package/dist/rules/typescript.d.mts +36 -0
  113. package/dist/rules/typescript.d.mts.map +1 -0
  114. package/dist/rules/typescript.mjs +37 -0
  115. package/dist/rules/typescript.mjs.map +1 -0
  116. package/dist/rules/vue.d.mts +26 -0
  117. package/dist/rules/vue.d.mts.map +1 -0
  118. package/dist/rules/vue.mjs +35 -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 +29 -24
  122. package/docs/rules-risk.md +3 -3
  123. package/docs/rules-risk.zh.md +3 -3
  124. package/package.json +21 -8
  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,29 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 2.0.5 - 2026-08-02
10
+
11
+ ### Changed
12
+
13
+ - Upgraded public API documentation to complete TSDoc, including standard defaults, parameters, return values, thrown errors, remarks, examples, and package-level documentation.
14
+ - Separated runtime, type-contract, rule-governance, and package-contract tests, and replaced the hard-coded release version assertion with SemVer and changelog consistency checks.
15
+
16
+ ## 2.0.4 - 2026-08-02
17
+
18
+ ### Added
19
+
20
+ - Added dedicated `@fast-china/eslint-config/configs` and `@fast-china/eslint-config/constants` subpaths for advanced Flat Config composition.
21
+
22
+ ### Changed
23
+
24
+ - Changed the `configs` and `rules` barrels to forward every module export, including configuration option types, while keeping configuration types out of the root entry.
25
+ - Changed this repository's own ESLint configuration to compose focused config fragments and constants instead of calling the root `fastConfig()` factory.
26
+ - Moved the `fastConfig()` implementation from `src/core/index.ts` directly into `src/index.ts` so the source root matches the package root entry.
27
+ - Narrowed the default preset to conventional Vue 3 browser administration projects by making Markdown linting opt-in alongside React, Angular, and manifest sorting.
28
+ - Removed Lodash policy selection from `fastConfig()` and the temporary `./lodash` subpath; optional Lodash restrictions now compose exclusively through `createLodashConfigs()` from `./configs`.
29
+ - Changed `createGlobalIgnores()` to return a config array like the other fragment factories, so direct composition consistently uses spread syntax.
30
+ - Updated `@eslint-react/eslint-plugin`, `@eslint/config-inspector`, and `globals` within their existing compatible version ranges.
31
+
9
32
  ## 2.0.3 - 2026-07-29
10
33
 
11
34
  ### 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
 
@@ -284,7 +343,7 @@ pnpm check
284
343
  pnpm pack --dry-run
285
344
  ```
286
345
 
287
- Run `pnpm typegen` after upgrading ESLint or a plugin and commit `src/typegen.d.ts`; never edit the generated file manually. `pnpm check` verifies that generated types are current, builds the package, type-checks source, lints all supported file types, checks formatting, and runs both runtime and consumer type tests against the built package.
346
+ Run `pnpm typegen` after upgrading ESLint or a plugin and commit `src/typegen.d.ts`; never edit the generated file manually. `pnpm test` rebuilds the package before running consumer type-contract, runtime integration, rule-governance, and package-contract tests. `pnpm check` adds source type-checking, full-repository linting, and formatting verification.
288
347
 
289
348
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for the contribution workflow, the [default-rule and risk guide](./docs/rules-risk.md) for rule maintenance, and [the engineering audit](./docs/engineering-audit.zh.md) for the current quality baseline.
290
349
 
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
 
@@ -284,7 +343,7 @@ pnpm check
284
343
  pnpm pack --dry-run
285
344
  ```
286
345
 
287
- 升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`;不要手工编辑生成文件。`pnpm check` 会验证生成类型没有漂移,然后依次构建、类型检查、检查所有支持的文件类型、验证格式,并针对构建后的真实包运行运行时和消费者类型测试。
346
+ 升级 ESLint 或插件后运行 `pnpm typegen` 并提交 `src/typegen.d.ts`;不要手工编辑生成文件。`pnpm test` 会先重新构建发布产物,再分别执行消费者类型契约、运行时集成、规则治理和发布包契约测试。`pnpm check` 在此基础上增加源码类型检查、全仓 ESLint 和格式验证。
288
347
 
289
348
  贡献流程见 [CONTRIBUTING.md](./CONTRIBUTING.md),规则维护约定见 [默认规则与风险指南](./docs/rules-risk.zh.md),本次工程审查和质量基线见 [工程质量审查报告](./docs/engineering-audit.zh.md)。
290
349
 
@@ -0,0 +1,46 @@
1
+ //#region src/configs/angular.d.ts
2
+ /**
3
+ * Angular TypeScript 源码与 HTML 模板检查的细分选项。
4
+ *
5
+ * @remarks
6
+ * 该对象通过 `fastConfig({ angular: { ... } })` 传入。只要传入对象,Angular 支持就会
7
+ * 被启用;未指定的字段继续使用各自默认值。Angular 配置始终包含框架 TypeScript 规则
8
+ * 和外部 `.html` 模板基础规则,本接口只控制成本或迁移影响较高的可选部分。
9
+ *
10
+ * Angular 支持依赖顶层 `typescript` 能力,不能与 `typescript: false` 同时使用。
11
+ * 这些选项不会修改 Angular 编译器、CLI 或模板类型检查配置。
12
+ */
13
+ interface AngularConfigOptions {
14
+ /**
15
+ * 是否使用 Angular 官方 processor,从 TypeScript 文件的
16
+ * `@Component({ template: ... })` 元数据中提取内联 HTML 并复用模板规则进行检查。
17
+ *
18
+ * 关闭后仍会检查 Angular TypeScript 源码和外部 `.html` 模板,只是不再处理组件中的
19
+ * 内联模板。大型项目若主要使用外部模板,或 processor 与其他工具发生冲突,可暂时关闭。
20
+ * @defaultValue `true`
21
+ */
22
+ inlineTemplates?: boolean;
23
+ /**
24
+ * 是否在模板基础正确性规则之外启用 Angular 模板无障碍规则组。
25
+ *
26
+ * 该规则组检查替代文本、键盘交互、焦点、表单标签和 ARIA 等可访问性问题,适用于
27
+ * 外部模板与已提取的内联模板。关闭后仍保留模板语法、严格比较和现代控制流等基础规则。
28
+ * 对旧项目而言可能一次产生较多报告,建议在确认迁移计划后再决定是否临时关闭。
29
+ * @defaultValue `true`
30
+ */
31
+ templateAccessibility?: boolean;
32
+ }
33
+ /**
34
+ * 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。
35
+ *
36
+ * @remarks
37
+ * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由
38
+ * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。
39
+ *
40
+ * @param options - 控制内联模板处理与模板无障碍规则的 Angular 选项。
41
+ * @returns 按 TypeScript 源码、外部模板顺序排列的 ESLint Flat Config 数组。
42
+ */
43
+ declare const createAngularConfigs: ({ inlineTemplates, templateAccessibility }?: AngularConfigOptions) => import("eslint/config").ConfigObject[];
44
+ //#endregion
45
+ export { AngularConfigOptions, createAngularConfigs };
46
+ //# sourceMappingURL=angular.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular.d.mts","names":[],"sources":["../../src/configs/angular.ts"],"mappings":";;;;;;;;;;;;UAqBiB;;;;;;;;;EAShB;;;;;;;;;EASA;;;;;;;;;;;;cAaY,yBAAwB,iBAAA,0BAA0D,iDAAyB"}
@@ -0,0 +1,37 @@
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
+ * @remarks
12
+ * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由
13
+ * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。
14
+ *
15
+ * @param options - 控制内联模板处理与模板无障碍规则的 Angular 选项。
16
+ * @returns 按 TypeScript 源码、外部模板顺序排列的 ESLint Flat Config 数组。
17
+ */
18
+ const createAngularConfigs = ({ inlineTemplates = true, templateAccessibility = true } = {}) => defineConfig([{
19
+ name: inlineTemplates ? "@fast-china/angular/typescript-with-inline-templates" : "@fast-china/angular/typescript",
20
+ files: [GLOB_ANGULAR_TYPESCRIPT],
21
+ plugins: { "@angular-eslint": angularPlugin },
22
+ ...inlineTemplates ? { processor: angularTemplatePlugin.processors["extract-inline-html"] } : {},
23
+ rules: angularRules
24
+ }, {
25
+ name: templateAccessibility ? "@fast-china/angular/template-accessibility" : "@fast-china/angular/template",
26
+ files: [GLOB_ANGULAR_TEMPLATE],
27
+ languageOptions: { parser: angularTemplateParser },
28
+ plugins: { "@angular-eslint/template": angularTemplatePlugin },
29
+ rules: {
30
+ ...angularTemplateRules,
31
+ ...templateAccessibility ? angularTemplateAccessibilityRules : {}
32
+ }
33
+ }]);
34
+ //#endregion
35
+ export { createAngularConfigs };
36
+
37
+ //# 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 * @remarks\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 * @defaultValue `true`\n\t */\n\tinlineTemplates?: boolean;\n\t/**\n\t * 是否在模板基础正确性规则之外启用 Angular 模板无障碍规则组。\n\t *\n\t * 该规则组检查替代文本、键盘交互、焦点、表单标签和 ARIA 等可访问性问题,适用于\n\t * 外部模板与已提取的内联模板。关闭后仍保留模板语法、严格比较和现代控制流等基础规则。\n\t * 对旧项目而言可能一次产生较多报告,建议在确认迁移计划后再决定是否临时关闭。\n\t * @defaultValue `true`\n\t */\n\ttemplateAccessibility?: boolean;\n}\n\n/**\n * 创建 Angular TypeScript、外部 HTML 模板与内联模板配置。\n *\n * @remarks\n * Angular 支持依赖工厂的 TypeScript 配置先注册 typescript-eslint 解析器;模板由\n * Angular 专用 parser 解析,内联模板通过官方 processor 复用同一套 HTML 规则。\n *\n * @param options - 控制内联模板处理与模板无障碍规则的 Angular 选项。\n * @returns 按 TypeScript 源码、外部模板顺序排列的 ESLint Flat Config 数组。\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":";;;;;;;;;;;;;;;;;AAoDA,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,15 @@
1
+ //#region src/configs/common.d.ts
2
+ /**
3
+ * 创建跨 JavaScript、TypeScript 与 Vue 脚本生效的通用配置。
4
+ *
5
+ * @remarks
6
+ * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后
7
+ * 留下长期失效的抑制注释。
8
+ *
9
+ * @param files - 应用公共规则的 ESLint glob 列表。
10
+ * @returns 包含公共规则与无效禁用指令检查的 Flat Config 数组。
11
+ */
12
+ declare const createCommonConfigs: (files?: readonly string[]) => import("eslint/config").ConfigObject[];
13
+ //#endregion
14
+ export { createCommonConfigs };
15
+ //# sourceMappingURL=common.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.mts","names":[],"sources":["../../src/configs/common.ts"],"mappings":";;;;;;;;;;;cAea,sBAAuB,sDAAqC"}
@@ -0,0 +1,24 @@
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
+ * @remarks
9
+ * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后
10
+ * 留下长期失效的抑制注释。
11
+ *
12
+ * @param files - 应用公共规则的 ESLint glob 列表。
13
+ * @returns 包含公共规则与无效禁用指令检查的 Flat Config 数组。
14
+ */
15
+ const createCommonConfigs = (files = GLOBS_CODE) => defineConfig([{
16
+ name: "@fast-china/common",
17
+ files: [...files],
18
+ linterOptions: { reportUnusedDisableDirectives: "error" },
19
+ rules: commonRules
20
+ }]);
21
+ //#endregion
22
+ export { createCommonConfigs };
23
+
24
+ //# 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 * @remarks\n * 除公共规则外,这里还把无效的 `eslint-disable` 指令提升为错误,避免规则被移除后\n * 留下长期失效的抑制注释。\n *\n * @param files - 应用公共规则的 ESLint glob 列表。\n * @returns 包含公共规则与无效禁用指令检查的 Flat Config 数组。\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":";;;;;;;;;;;;;;AAeA,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,73 @@
1
+ import { Linter } from "eslint";
2
+ //#region src/configs/environment.d.ts
3
+ /**
4
+ * 应用源码可声明的运行时环境。
5
+ *
6
+ * - `"browser"` 仅提供浏览器全局变量。
7
+ * - `"node"` 仅提供 Node.js 全局变量。
8
+ * - `"universal"` 同时提供浏览器与 Node.js 全局变量。
9
+ */
10
+ type RuntimeEnvironment = "browser" | "node" | "universal";
11
+ /**
12
+ * 运行时全局变量配置片段的选项。
13
+ *
14
+ * @remarks
15
+ * `fastConfig()` 会根据已启用的语言和框架计算 `files`、`nodeFiles`,再调用
16
+ * `createEnvironmentConfigs()`。该接口仍保持独立,以便环境片段的输入、默认值和文件
17
+ * 范围在源码中具有明确契约;直接组合配置片段时可从 `./configs` 子路径使用。
18
+ *
19
+ * 应用代码与 Node.js 工程文件使用两个独立 Flat Config 片段,避免浏览器源码无条件获得
20
+ * `process`、`Buffer` 等 Node.js 全局变量,也避免配置文件误报这些合法全局变量未定义。
21
+ */
22
+ interface EnvironmentConfigOptions {
23
+ /**
24
+ * 应用代码实际运行的环境,决定 `files` 范围内注入哪组标准全局变量。
25
+ *
26
+ * `"browser"` 只注入浏览器全局变量,`"node"` 只注入 Node.js 全局变量,
27
+ * `"universal"` 同时注入两组。该值不会影响 `nodeFiles` 对应的工程文件;后者始终
28
+ * 使用 Node.js 全局变量。
29
+ * @defaultValue `"browser"`
30
+ */
31
+ environment?: RuntimeEnvironment;
32
+ /**
33
+ * 需要获得所选运行时全局变量的应用代码 glob 列表。
34
+ *
35
+ * 工厂会把当前启用的 JavaScript、TypeScript 和 Vue 文件范围传入这里。数组会复制到
36
+ * 生成配置中,不会在函数内部修改调用方传入的值。
37
+ * @defaultValue {@link GLOBS_CODE}
38
+ */
39
+ files?: readonly string[];
40
+ /**
41
+ * 当前启用且允许作为 Node.js 工程文件执行的脚本扩展名 glob 列表。
42
+ *
43
+ * 每一项都会与内置的配置文件、脚本目录、测试文件和 CLI 文件模式组合为 ESLint
44
+ * Flat Config 的 AND 文件条件。例如顶层关闭 TypeScript 后,Node.js 工程片段也不会
45
+ * 因自身模式较宽而意外接管 `.ts` 文件。
46
+ * @defaultValue {@link GLOBS_JAVASCRIPT}
47
+ */
48
+ nodeFiles?: readonly string[];
49
+ /**
50
+ * 追加到应用代码环境中的项目级全局变量及其读写权限。
51
+ *
52
+ * 该记录在标准环境全局变量之后合并,所以同名条目可以覆盖预置权限。它应用于完整
53
+ * `files` 范围;其中属于 Node.js 工程文件的子集还会由后续片段追加标准 Node.js 全局
54
+ * 变量。值格式遵循 ESLint `Linter.Globals`。
55
+ * @defaultValue `{}`
56
+ */
57
+ globals?: Linter.Globals;
58
+ }
59
+ /**
60
+ * 创建运行时环境相关的 ESLint 配置。
61
+ *
62
+ * @remarks
63
+ * 返回两个相互独立的 Flat Config 片段:第一个为应用源码配置所选环境和项目级全局
64
+ * 变量;第二个仅命中配置、脚本、测试与 CLI 等工程文件,为它们配置 Node.js 全局变量
65
+ * 并允许使用 `console`。分离范围可以减少跨运行时的假阴性。
66
+ *
67
+ * @param options - 运行时环境、目标文件范围与项目级全局变量。
68
+ * @returns 依次包含应用运行时环境和 Node.js 工程文件环境的 Flat Config 数组。
69
+ */
70
+ declare const createEnvironmentConfigs: ({ environment, files, nodeFiles, globals: projectGlobals }?: EnvironmentConfigOptions) => import("eslint/config").ConfigObject[];
71
+ //#endregion
72
+ export { EnvironmentConfigOptions, RuntimeEnvironment, createEnvironmentConfigs };
73
+ //# sourceMappingURL=environment.d.mts.map