@fast-china/eslint-config 2.0.0 → 2.0.1

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.
@@ -11,15 +11,17 @@ This document records what the default config inherits, which rules can have a l
11
11
 
12
12
  High impact does not mean inherently unsafe. It means adoption or fix review is relatively expensive. Module side effects, getters and proxies, build-tool conventions, and public component APIs deserve particular attention.
13
13
 
14
- ## Upstream presets enabled by default
14
+ ## Bundled preset sources
15
15
 
16
- `fastConfig()` defaults to Vue 3, TypeScript, JavaScript, import, RegExp, JSON, Markdown, and the Prettier compatibility layer. Type-aware TypeScript linting and manifest sorting are opt-in.
16
+ `fastConfig()` defaults to Vue 3, TypeScript, JavaScript, import, RegExp, JSON, Markdown, and the Prettier compatibility layer. React, Angular, type-aware TypeScript linting, and manifest sorting are opt-in.
17
17
 
18
18
  | Scope | Inherited preset | Notes |
19
19
  | ---------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
20
20
  | JavaScript | `@eslint/js` `recommended` | Core syntax and runtime correctness, including `no-undef` and `no-unused-vars`. |
21
21
  | TypeScript | typescript-eslint `recommended` + `stylistic` | Does not read type information by default; local overrides are applied afterward. |
22
22
  | Vue 3 | `@eslint/js`, non-type-aware typescript-eslint presets, and `eslint-plugin-vue` `flat/recommended` | Handles Vue 3 SFCs and applies TypeScript rules to `<script lang="ts">` correctly. |
23
+ | React (opt-in) | `@eslint-react/recommended*` and `eslint-plugin-react-hooks` `flat/recommended` | Checks components, JSX/TSX, DOM APIs, Hooks, and stable React Compiler diagnostics. |
24
+ | Angular (opt-in) | angular-eslint 22.x TypeScript, template recommended, and template accessibility rule sets | Checks Angular TypeScript plus external and extracted inline templates; requires TypeScript support. |
23
25
  | Imports | `eslint-plugin-import-x` `recommended` | Local rules add import placement, deduplication, and ordering. Resolver-dependent checks stay disabled. |
24
26
  | RegExp | `eslint-plugin-regexp` `flat/recommended` | Some rules can rewrite regular expressions; run tests after bulk fixes. |
25
27
  | JSON dialects | The matching `eslint-plugin-jsonc` `flat/recommended-*` preset | JSON, JSONC, and JSON5 are scoped separately. |
@@ -52,11 +54,15 @@ The exact upstream rule set is defined by the dependency versions in `pnpm-lock.
52
54
  ## High-impact features not enabled by default
53
55
 
54
56
  - Type-aware TypeScript and Vue presets require `typeChecked: true`. They add project-service cost and rules such as `no-floating-promises`.
57
+ - React requires `react: true`. Its upstream recommended and official Hooks presets include blocking component, Hooks, and React Compiler rules; review existing custom hook and memoization patterns when adopting it.
58
+ - Angular requires `angular: true`. The framework bundle enables `prefer-inject`, OnPush change detection, standalone components, modern template control flow, and template accessibility. These policies are intentionally not active in the default Vue configuration.
55
59
  - The `jsonc/sort-keys` and `jsonc/sort-array-values` manifest rules require `sortPackageJson: true` or `sortTsconfig: true`. Isolate the first fix and verify the publish manifest.
56
60
  - Lodash import restrictions require `lodash: "lodash"` or `lodash: "lodash-unified"`. They use `no-restricted-imports` to prevent mixed static package entry points but do not inspect dynamic `import()` or CommonJS `require()`.
57
61
  - Resolver-dependent import checks such as `import-x/no-unresolved` and `import-x/named` stay disabled.
58
62
  - Keys inside `package.json#exports` are never sorted. Node conditional exports use key order during matching, so reordering can change the loaded file.
59
63
 
64
+ When Angular is enabled, the highest-adoption-cost rules are `@angular-eslint/prefer-inject`, `@angular-eslint/prefer-on-push-component-change-detection`, `@angular-eslint/prefer-standalone`, and `@angular-eslint/template/prefer-control-flow`. Treat their fixes as framework migrations rather than formatting cleanup. Set `angular: { templateAccessibility: false }` only when accessibility is enforced by another equivalent tool; individual exceptions should normally use file-scoped trailing overrides.
65
+
60
66
  ## Scoped overrides
61
67
 
62
68
  Overrides must follow the shared config and should target only the affected files:
@@ -13,15 +13,17 @@
13
13
 
14
14
  “高影响”不等于规则本身不安全。它表示规则的采用成本或修复审查成本较高。默认自动修复的目标仍是保持语义,但模块副作用、getter/Proxy、构建器约定和公共组件 API 都需要项目维护者复核。
15
15
 
16
- ## 默认继承的上游预置
16
+ ## 内置预置来源
17
17
 
18
- `fastConfig()` 默认开启 Vue 3、TypeScript、JavaScript、import、RegExp、JSON、Markdown 与 Prettier 兼容层;TypeScript 类型感知和清单排序默认关闭。
18
+ `fastConfig()` 默认开启 Vue 3、TypeScript、JavaScript、import、RegExp、JSON、Markdown 与 Prettier 兼容层;React、Angular、TypeScript 类型感知和清单排序默认关闭。
19
19
 
20
20
  | 范围 | 默认继承 | 说明 |
21
21
  | ---------------- | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
22
22
  | JavaScript | `@eslint/js` 的 `recommended` | 基础语法和运行时正确性,包括 `no-undef`、`no-unused-vars` 等。 |
23
23
  | TypeScript | typescript-eslint 的 `recommended` + `stylistic` | 默认不读取类型信息;本库规则在预置之后覆写。 |
24
24
  | Vue 3 | `@eslint/js`、typescript-eslint 非类型感知预置、`eslint-plugin-vue` 的 `flat/recommended` | 处理 Vue 3 单文件组件,并让 TypeScript 规则正确作用于 `<script lang="ts">`。 |
25
+ | React(按需) | `@eslint-react/recommended*` 与 `eslint-plugin-react-hooks` 的 `flat/recommended` | 检查组件、JSX/TSX、DOM API、Hooks 与稳定的 React Compiler 诊断。 |
26
+ | Angular(按需) | angular-eslint 22.x 的 TypeScript、模板推荐与模板无障碍规则集 | 检查 Angular TypeScript、外部模板和提取后的内联模板;必须启用 TypeScript。 |
25
27
  | import | `eslint-plugin-import-x` 的 `recommended` | 本库额外配置导入位置、去重和排序。解析器相关规则默认关闭,避免绑定具体别名方案。 |
26
28
  | RegExp | `eslint-plugin-regexp` 的 `flat/recommended` | 部分规则可自动改写正则表达式,批量修复后需运行测试。 |
27
29
  | JSON/JSONC/JSON5 | `eslint-plugin-jsonc` 对应方言的 `flat/recommended-*` | 三种方言按扩展名隔离,不会互相叠加。 |
@@ -56,11 +58,15 @@
56
58
  ## 明确不默认启用的高影响能力
57
59
 
58
60
  - TypeScript 和 Vue 的类型感知预置仅在 `typeChecked: true` 时启用;它们会增加项目服务开销,并启用 `no-floating-promises` 等需要类型信息的规则。
61
+ - React 仅在 `react: true` 时启用。其上游推荐预置和官方 Hooks 预置包含阻断级组件、Hooks 与 React Compiler 规则;接入旧项目时应重点审查自定义 Hook 和 memoization 写法。
62
+ - Angular 仅在 `angular: true` 时启用。框架规则默认要求 `inject()`、OnPush 变更检测、独立组件、现代模板控制流和模板无障碍;这些约束不会进入默认 Vue 配置。
59
63
  - 清单排序规则 `jsonc/sort-keys`、`jsonc/sort-array-values` 分别仅在 `sortPackageJson: true`、`sortTsconfig: true` 时启用;首次修复应单独提交并核对发布清单。
60
64
  - Lodash 静态导入限制仅在 `lodash: "lodash"` 或 `lodash: "lodash-unified"` 时启用。该策略使用 `no-restricted-imports` 阻止混用包入口,但不会检查动态 `import()` 或 CommonJS `require()`。
61
65
  - `import-x/no-unresolved`、`import-x/named` 等依赖 resolver 的检查默认关闭。
62
66
  - `package.json` 的 `exports` 条件键永不自动排序。Node 条件导出按键顺序匹配,改写顺序可能改变实际加载文件。
63
67
 
68
+ 启用 Angular 后,采用成本最高的规则是 `@angular-eslint/prefer-inject`、`@angular-eslint/prefer-on-push-component-change-detection`、`@angular-eslint/prefer-standalone` 与 `@angular-eslint/template/prefer-control-flow`。应把修复视为框架迁移,而不是格式整理。只有项目已使用等效工具保障无障碍时,才建议设置 `angular: { templateAccessibility: false }`;个别例外通常应通过末尾的文件级覆写处理。
69
+
64
70
  ## 按项目降低规则强度
65
71
 
66
72
  覆盖项必须放在共享配置之后,并尽量限定文件范围:
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@fast-china/eslint-config",
3
- "version": "2.0.0",
4
- "description": "Opinionated, typed ESLint Flat Config for Vue 3, Vite, TypeScript, JavaScript, and Node.js.",
3
+ "version": "2.0.1",
4
+ "description": "Opinionated, typed ESLint Flat Config for Vue 3, React, Angular, Vite, TypeScript, JavaScript, and Node.js.",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "fast",
8
+ "angular",
8
9
  "eslint",
9
10
  "eslint-config",
10
11
  "flat-config",
12
+ "react",
11
13
  "typescript",
12
14
  "vite",
13
15
  "vue",
@@ -32,19 +34,19 @@
32
34
  "dist",
33
35
  "docs"
34
36
  ],
35
- "main": "./dist/index.js",
36
- "module": "./dist/index.js",
37
- "types": "./dist/index.d.ts",
37
+ "main": "./dist/index.mjs",
38
+ "module": "./dist/index.mjs",
39
+ "types": "./dist/index.d.mts",
38
40
  "exports": {
39
41
  ".": {
40
- "types": "./dist/index.d.ts",
41
- "import": "./dist/index.js",
42
- "default": "./dist/index.js"
42
+ "types": "./dist/index.d.mts",
43
+ "import": "./dist/index.mjs",
44
+ "default": "./dist/index.mjs"
43
45
  },
44
46
  "./rules": {
45
- "types": "./dist/rules/index.d.ts",
46
- "import": "./dist/rules/index.js",
47
- "default": "./dist/rules/index.js"
47
+ "types": "./dist/rules/index.d.mts",
48
+ "import": "./dist/rules/index.mjs",
49
+ "default": "./dist/rules/index.mjs"
48
50
  },
49
51
  "./package.json": "./package.json"
50
52
  },
@@ -54,7 +56,7 @@
54
56
  },
55
57
  "scripts": {
56
58
  "dev": "eslint-config-inspector --config src/eslint-inspector.config.ts",
57
- "build": "pnpm run typegen:check && tsup",
59
+ "build": "pnpm run typegen:check && tsdown",
58
60
  "build:inspector": "eslint-config-inspector build --config src/eslint-inspector.config.ts",
59
61
  "typegen": "tsx scripts/typegen.ts",
60
62
  "typegen:check": "tsx scripts/typegen.ts --check",
@@ -70,15 +72,20 @@
70
72
  },
71
73
  "peerDependencies": {
72
74
  "eslint": "^10.0.0",
73
- "typescript": ">=5.3.0 <6.1.0"
75
+ "typescript": ">=6.0.0 <6.1.0"
74
76
  },
75
77
  "dependencies": {
78
+ "@angular-eslint/eslint-plugin": "^22.1.0",
79
+ "@angular-eslint/eslint-plugin-template": "^22.1.0",
80
+ "@angular-eslint/template-parser": "^22.1.0",
81
+ "@eslint-react/eslint-plugin": "^5.18.0",
76
82
  "@eslint/js": "^10.0.0",
77
83
  "@eslint/markdown": "^8.0.3",
78
84
  "eslint-config-flat-gitignore": "^2.0.0",
79
85
  "eslint-config-prettier": "^10.0.0",
80
86
  "eslint-plugin-import-x": "^4.17.1",
81
87
  "eslint-plugin-jsonc": "^3.3.0",
88
+ "eslint-plugin-react-hooks": "^7.1.1",
82
89
  "eslint-plugin-regexp": "^3.1.1",
83
90
  "eslint-plugin-vue": "^10.10.0",
84
91
  "globals": "^17.7.0",
@@ -88,15 +95,15 @@
88
95
  "devDependencies": {
89
96
  "@eslint/config-inspector": "^3.1.0",
90
97
  "@types/node": "^24.13.3",
91
- "eslint": "^10.7.0",
98
+ "eslint": "^10.8.0",
92
99
  "eslint-typegen": "^2.3.1",
93
100
  "prettier": "^3.9.6",
94
- "tsup": "^8.0.0",
101
+ "tsdown": "^0.22.14",
95
102
  "tsx": "^4.23.1",
96
- "typescript": "^5.9.0"
103
+ "typescript": "^6.0.3"
97
104
  },
98
105
  "engines": {
99
- "node": "^22.13.0 || ^24.0.0",
106
+ "node": "^22.18.0 || >=24.11.0",
100
107
  "pnpm": "^11.0.0"
101
108
  }
102
109
  }
package/dist/index.d.ts DELETED
@@ -1,133 +0,0 @@
1
- import { R as RuleOptions } from './define-rules-CSwQ8C1q.js';
2
- export { d as defineRules } from './define-rules-CSwQ8C1q.js';
3
- import { Config } from 'eslint/config';
4
- import { Linter } from 'eslint';
5
-
6
- type RuntimeEnvironment = "browser" | "node" | "universal";
7
-
8
- /** 项目允许使用的 Lodash 导入来源。 */
9
- type LodashPreference = "lodash" | "lodash-unified";
10
-
11
- interface TypeScriptConfigOptions {
12
- /**
13
- * 是否启用依赖 TypeScript 类型信息的规则;开启后会增加启动和检查成本。
14
- * @default false
15
- */
16
- typeChecked?: boolean;
17
- /**
18
- * 查找 tsconfig.json 的根目录。
19
- *
20
- * typescript-eslint 通常可从 `eslint.config.*` 调用栈推断;复杂 monorepo 可显式传入
21
- * `import.meta.dirname`,避免从错误目录启动 Project Service。
22
- * @default undefined
23
- */
24
- tsconfigRootDir?: string;
25
- }
26
-
27
- interface FastConfigOptions {
28
- /**
29
- * 应用代码的运行环境;Vue/Vite 项目通常使用 `browser`。
30
- * @default "browser"
31
- */
32
- environment?: RuntimeEnvironment;
33
- /**
34
- * 项目额外提供的全局变量,例如测试运行器或宿主平台 API。
35
- * @default undefined
36
- */
37
- globals?: Linter.Globals;
38
- /**
39
- * 是否读取项目根目录的 .gitignore。
40
- * @default true
41
- */
42
- gitignore?: boolean;
43
- /**
44
- * 追加到内置集合的全局忽略模式。
45
- * @default []
46
- */
47
- ignores?: readonly string[];
48
- /**
49
- * 是否启用 import-x 规则。
50
- * @default true
51
- */
52
- imports?: boolean;
53
- /**
54
- * 是否处理 JavaScript 与 JSX 文件。
55
- * @default true
56
- */
57
- javascript?: boolean;
58
- /**
59
- * 是否启用 JSON、JSONC 与 JSON5 推荐规则;清单排序由独立选项控制。
60
- * @default true
61
- */
62
- json?: boolean;
63
- /**
64
- * 统一项目使用的 Lodash 包;`false` 表示不限制 `lodash`、`lodash-es` 或 `lodash-unified`。
65
- * @default false
66
- */
67
- lodash?: false | LodashPreference;
68
- /**
69
- * 是否启用 Markdown 规则。
70
- * @default true
71
- */
72
- markdown?: boolean;
73
- /**
74
- * 是否在末尾关闭与 Prettier 冲突的格式规则。
75
- * @default true
76
- */
77
- prettier?: boolean;
78
- /**
79
- * 是否启用正则表达式规则。
80
- * @default true
81
- */
82
- regexp?: boolean;
83
- /**
84
- * 应用于全部已启用代码文件的项目级规则,提供精确规则名与选项类型。
85
- * @default undefined
86
- */
87
- rules?: RuleOptions;
88
- /**
89
- * 是否按安全的固定顺序整理 package.json;启用后首次运行可能产生较大 diff。
90
- * @default false
91
- */
92
- sortPackageJson?: boolean;
93
- /**
94
- * 是否按 TypeScript 文档主题整理 tsconfig*.json。
95
- * @default false
96
- */
97
- sortTsconfig?: boolean;
98
- /**
99
- * TypeScript 支持;传入对象可开启类型感知规则。
100
- * @default true
101
- */
102
- typescript?: boolean | TypeScriptConfigOptions;
103
- /**
104
- * 是否启用 Vue 3 单文件组件支持。
105
- * @default true
106
- */
107
- vue?: boolean;
108
- }
109
- /** `fastConfig()` 使用的稳定默认值;对象被冻结,避免运行时被意外修改。 */
110
- declare const defaultConfigOptions: Readonly<{
111
- readonly environment: "browser";
112
- readonly gitignore: true;
113
- readonly imports: true;
114
- readonly javascript: true;
115
- readonly json: true;
116
- readonly lodash: false;
117
- readonly markdown: true;
118
- readonly prettier: true;
119
- readonly regexp: true;
120
- readonly sortPackageJson: false;
121
- readonly sortTsconfig: false;
122
- readonly typescript: true;
123
- readonly vue: true;
124
- }>;
125
- /**
126
- * 创建面向 Vue 3、Vite、TypeScript、JavaScript 与 Node.js 项目的 ESLint Flat Config。
127
- *
128
- * 默认导出就是此函数。额外配置参数会放在内置配置之后,因此项目可以按文件范围
129
- * 覆盖任何默认规则,而无需再次调用 ESLint 的 `defineConfig()`。
130
- */
131
- declare const fastConfig: (options?: FastConfigOptions, ...overrides: Config[]) => Config[];
132
-
133
- export { type FastConfigOptions, type LodashPreference, RuleOptions, type RuntimeEnvironment, type TypeScriptConfigOptions, fastConfig as default, defaultConfigOptions, fastConfig };