@fast-china/eslint-config 2.0.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/CONTRIBUTING.md +8 -7
  3. package/README.md +108 -236
  4. package/README.zh.md +105 -231
  5. package/SECURITY.md +4 -4
  6. package/dist/configs/angular.d.mts +6 -6
  7. package/dist/configs/angular.mjs +1 -1
  8. package/dist/configs/angular.mjs.map +1 -1
  9. package/dist/configs/common.d.mts +2 -1
  10. package/dist/configs/common.mjs.map +1 -1
  11. package/dist/configs/environment.d.mts +21 -11
  12. package/dist/configs/environment.mjs +25 -5
  13. package/dist/configs/environment.mjs.map +1 -1
  14. package/dist/configs/ignores.d.mts +3 -2
  15. package/dist/configs/ignores.mjs +4 -3
  16. package/dist/configs/ignores.mjs.map +1 -1
  17. package/dist/configs/import.d.mts +2 -1
  18. package/dist/configs/import.mjs.map +1 -1
  19. package/dist/configs/index.d.mts +5 -4
  20. package/dist/configs/index.mjs +3 -2
  21. package/dist/configs/javascript.d.mts +2 -1
  22. package/dist/configs/javascript.mjs.map +1 -1
  23. package/dist/configs/json.d.mts +5 -3
  24. package/dist/configs/json.mjs +5 -4
  25. package/dist/configs/json.mjs.map +1 -1
  26. package/dist/configs/lodash.d.mts +2 -1
  27. package/dist/configs/lodash.mjs.map +1 -1
  28. package/dist/configs/markdown.d.mts +2 -1
  29. package/dist/configs/markdown.mjs.map +1 -1
  30. package/dist/configs/prettier.d.mts +2 -1
  31. package/dist/configs/prettier.mjs +4 -1
  32. package/dist/configs/prettier.mjs.map +1 -1
  33. package/dist/configs/react.d.mts +7 -44
  34. package/dist/configs/react.mjs +7 -8
  35. package/dist/configs/react.mjs.map +1 -1
  36. package/dist/configs/regexp.d.mts +4 -4
  37. package/dist/configs/regexp.mjs +5 -4
  38. package/dist/configs/regexp.mjs.map +1 -1
  39. package/dist/configs/sort-package.d.mts +4 -3
  40. package/dist/configs/sort-package.mjs +2 -2
  41. package/dist/configs/sort-package.mjs.map +1 -1
  42. package/dist/configs/sort-tsconfig.d.mts +4 -2
  43. package/dist/configs/sort-tsconfig.mjs +2 -1
  44. package/dist/configs/sort-tsconfig.mjs.map +1 -1
  45. package/dist/configs/typescript.d.mts +9 -56
  46. package/dist/configs/typescript.mjs +20 -29
  47. package/dist/configs/typescript.mjs.map +1 -1
  48. package/dist/configs/uniapp.d.mts +17 -0
  49. package/dist/configs/uniapp.mjs +30 -0
  50. package/dist/configs/uniapp.mjs.map +1 -0
  51. package/dist/configs/vue.d.mts +5 -38
  52. package/dist/configs/vue.mjs +25 -35
  53. package/dist/configs/vue.mjs.map +1 -1
  54. package/dist/constants/index.d.mts +33 -1
  55. package/dist/constants/index.mjs +33 -1
  56. package/dist/constants/index.mjs.map +1 -1
  57. package/dist/index.d.mts +41 -208
  58. package/dist/index.mjs +58 -100
  59. package/dist/index.mjs.map +1 -1
  60. package/dist/rules/angular.d.mts +1 -1
  61. package/dist/rules/angular.mjs +1 -1
  62. package/dist/rules/angular.mjs.map +1 -1
  63. package/dist/rules/common.d.mts +2 -2
  64. package/dist/rules/common.mjs +2 -2
  65. package/dist/rules/common.mjs.map +1 -1
  66. package/dist/rules/import.mjs.map +1 -1
  67. package/dist/rules/index.d.mts +2 -1
  68. package/dist/rules/index.mjs +2 -1
  69. package/dist/rules/javascript.d.mts +10 -6
  70. package/dist/rules/javascript.mjs +12 -6
  71. package/dist/rules/javascript.mjs.map +1 -1
  72. package/dist/rules/react.d.mts +2 -3
  73. package/dist/rules/react.mjs +2 -3
  74. package/dist/rules/react.mjs.map +1 -1
  75. package/dist/rules/regexp.d.mts +38 -0
  76. package/dist/rules/regexp.mjs +39 -0
  77. package/dist/rules/regexp.mjs.map +1 -0
  78. package/dist/rules/sort-package.d.mts +1 -1
  79. package/dist/rules/sort-package.mjs +1 -1
  80. package/dist/rules/sort-package.mjs.map +1 -1
  81. package/dist/rules/sort-tsconfig.d.mts +1 -1
  82. package/dist/rules/sort-tsconfig.mjs +1 -1
  83. package/dist/rules/sort-tsconfig.mjs.map +1 -1
  84. package/dist/rules/typescript.d.mts +11 -3
  85. package/dist/rules/typescript.mjs +10 -4
  86. package/dist/rules/typescript.mjs.map +1 -1
  87. package/dist/rules/vue.d.mts +8 -2
  88. package/dist/rules/vue.mjs +8 -2
  89. package/dist/rules/vue.mjs.map +1 -1
  90. package/docs/engineering-audit.zh.md +53 -77
  91. package/docs/rules-risk.md +104 -101
  92. package/docs/rules-risk.zh.md +104 -105
  93. package/package.json +3 -2
@@ -1,104 +1,80 @@
1
1
  # 工程质量审查报告
2
2
 
3
- 审查日期:2026-08-02
3
+ 审查日期:2026-08-26
4
4
 
5
- 审查对象:`@fast-china/eslint-config` 2.0.6 工作区
5
+ 审查对象:`@fast-china/eslint-config` 2.1.0 工作区
6
6
 
7
7
  ## 结论
8
8
 
9
- 当前仓库已经具备完整 ESLint Flat Config 开源库所需的核心能力:稳定且精简的公共 API、明确的语言作用域、可选类型感知检查、精确规则类型、可重复构建、集成测试、CI、发布归档检查和中英文文档。
9
+ 仓库继续使用 ESLint 10 Flat Config、精确规则类型、可重复构建和发布包契约,并将根入口收敛为固定的 Vue 3 + TypeScript + UniApp 配置。SDK、React、Angular、Node.js 等其他项目通过不绑定框架的基础组合和对应框架片段接入,不继承 Vue 或 UniApp globals。
10
10
 
11
- 默认场景面向普通 Vue 3 + Vite + TypeScript 浏览器后台管理项目;React、Angular、Markdown 和清单排序按需启用,Lodash 策略通过 `configs` 子路径独立组合。配置仍支持 JavaScript、Node.js 工程文件、JSON 方言、正则表达式和模块导入检查,项目覆写始终位于内置配置之后。
11
+ ## 当前规则模型
12
12
 
13
- ## 审查范围
13
+ - JavaScript、TypeScript、Import 和 RegExp 只有一套共享规则。
14
+ - TypeScript、Vue 和 React TypeScript 始终使用 `recommendedTypeChecked` 与 Project Service。
15
+ - Vue 使用 `flat/recommended`,并叠加事件声明、kebab-case 属性、闭合标签和排序规则。
16
+ - RegExp 使用显式审查过的正确性与安全规则,不继承完整偏好型推荐集合。
17
+ - React 使用 `@eslint-react` 推荐预置和 React 官方 Hooks Recommended,并关闭重复实现。
18
+ - Angular 与官方 TypeScript、模板和无障碍推荐规则保持一致。
19
+ - 规则源码注释只说明当前意图;历史版本差异由更新日志维护。
14
20
 
15
- - npm 包元数据、ESM 入口、公开子路径与发布文件
16
- - TypeScript 6、tsdown、类型生成与声明文件
17
- - ESLint Flat Config 顺序、文件作用域、解析器和插件注册
18
- - JavaScript、TypeScript、Vue、React、Angular、JSON 方言、Markdown、RegExp 与 import 集成
19
- - 浏览器、Node.js、通用环境和项目自定义全局变量
20
- - Lodash 静态导入策略、清单排序与 Prettier 职责边界
21
- - README、规则风险说明、贡献流程、CI、测试和发布前检查
21
+ ## 公共 API
22
22
 
23
- ## 当前工程基线
23
+ 根入口公开:
24
24
 
25
- | 领域 | 状态 | 质量保障 |
26
- | -------------- | ---- | ---------------------------------------------------------------------- |
27
- | 公共 API | 通过 | 根入口保持精简,配置片段、glob 常量和原始规则由独立子路径提供 |
28
- | Flat Config | 通过 | 所有语言和插件配置限定到明确文件范围,项目覆写最后应用 |
29
- | Vue 3 | 通过 | `vue-eslint-parser` 处理 SFC,TypeScript 解析器正确嵌套 |
30
- | React | 通过 | 按需覆盖 JSX/TSX、组件、官方 Hooks、Compiler 诊断与 DOM 安全 |
31
- | Angular | 通过 | 按需覆盖框架 TypeScript、外部 HTML、内联模板与模板无障碍 |
32
- | TypeScript | 通过 | 默认使用推荐规则,可选 Project Service 类型感知模式 |
33
- | JavaScript | 通过 | 应用 `@eslint/js` 推荐规则并区分应用环境与 Node.js 工程文件 |
34
- | 数据与文档文件 | 通过 | JSON、JSONC、JSON5 和 Markdown 分别使用对应语言配置 |
35
- | 规则自动补全 | 通过 | 从 ESLint 核心和随包插件 schema 生成精确 `RuleOptions` |
36
- | Lodash 策略 | 通过 | 可选统一 `lodash` 或 `lodash-unified`,默认不限制项目依赖选择 |
37
- | 清单排序 | 通过 | 默认关闭;启用后不会重排 `package.json#exports` 条件键 |
38
- | Prettier | 通过 | 只关闭冲突规则,格式化由 Prettier CLI 或编辑器负责 |
39
- | 构建与发布 | 通过 | tsdown 生成 `.mjs`、`.d.mts` 和 source map,`prepack` 执行完整质量门禁 |
40
- | 自动化验证 | 通过 | 运行时测试、消费者类型测试、格式检查、静态检查和 Node.js 多版本 CI |
25
+ - 默认 Vue 3 + TypeScript + UniApp Flat Config。
26
+ - 只接收 `environment` `fastConfig()`。
27
+ - `defineRules()`、`FastConfigOptions` `RuleOptions`。
41
28
 
42
- ## 配置组合模型
29
+ `defaultConfigOptions`、语言和插件布尔开关、`typeChecked`、`tsconfigRootDir`、工厂级 rules/globals/ignores 已删除。项目覆写使用原生后置 Flat Config。
43
30
 
44
- `fastConfig()` 按以下顺序生成配置:
31
+ 根入口新增固定 `createBaseConfigs()`,供 React、Angular、Node.js 和 SDK 组合。框架、Markdown、Lodash 及其他低层片段仍从 `./configs` 显式引用。
45
32
 
46
- 1. 内置忽略项、项目附加忽略项和可选 `.gitignore`。
47
- 2. 应用运行环境、项目全局变量和 Node.js 工程文件全局变量。
48
- 3. JavaScript、import-x、RegExp、TypeScript、JSON 方言、Vue、React、Angular 和 Markdown 配置。
49
- 4. 可选 `package.json`、`tsconfig*.json` 排序配置。
50
- 5. Prettier 冲突关闭配置。
51
- 6. 工厂级 `rules` 与调用方传入的文件级覆写。
33
+ ## 工程能力
52
34
 
53
- 这一顺序保证调用方可以覆盖任何内置规则,同时避免语言规则进入不支持的文件类型。
35
+ | 领域 | 状态 | 质量保障 |
36
+ | ------------- | ---- | -------------------------------------------------- |
37
+ | 公共 API | 通过 | 根入口固定、其他能力由独立子路径组合 |
38
+ | JavaScript | 通过 | 核心 recommended + 统一现代语法规则 |
39
+ | TypeScript | 通过 | 固定 `recommendedTypeChecked` 与 Project Service |
40
+ | Vue 3 | 通过 | `vue-eslint-parser` + `flat/recommended` |
41
+ | UniApp | 通过 | 默认 `.nvue`、globals、清单注释和 `unpackage` 忽略 |
42
+ | React | 通过 | 显式组合 JSX/TSX、Hooks Recommended 与 DOM 安全 |
43
+ | Angular | 通过 | 显式组合源码、外部/内联模板和无障碍规则 |
44
+ | Import | 通过 | 正确性和排序为 error,副作用导入参与检查 |
45
+ | RegExp | 通过 | 显式正确性、安全和超线性回溯规则 |
46
+ | JSON | 通过 | 三种方言、VS Code 与 UniApp 注释例外 |
47
+ | 清单排序 | 通过 | 默认启用并保留 `exports` 条件顺序 |
48
+ | Markdown | 通过 | 作为独立片段显式组合 |
49
+ | Node 工具文件 | 通过 | Node globals、console 和 CommonJS 末尾覆写 |
50
+ | 类型生成 | 通过 | 插件 schema 生成精确 `RuleOptions` |
51
+ | 构建发布 | 通过 | TypeScript 6、tsdown、ESM 和根目录 `dist/` |
54
52
 
55
- ## 规则与类型维护
53
+ ## 根入口配置顺序
56
54
 
57
- - 每条本地规则旁必须说明作用、启用理由和重要风险。
58
- - 高影响、可自动修复、安全相关和按需启用规则使用统一标签。
59
- - 默认高影响规则同步记录在中英文风险指南中。
60
- - `src/typegen.d.ts` 由规则 schema 生成,不允许手工编辑。
61
- - ReactAngular 插件也参与类型生成,因此框架规则名与选项可获得同样的精确自动补全。
62
- - ESLint 或插件升级后必须运行 `pnpm typegen` 并审查类型差异。
63
- - `@fast-china/eslint-config/configs` 提供全部配置创建函数及其选项类型,支持高级调用方自行组合。
64
- - `@fast-china/eslint-config/constants` 集中提供配置片段使用的文件 glob,避免调用方复制字符串。
65
- - `@fast-china/eslint-config/rules` 提供有完整注释的原始规则记录,便于高级组合。
55
+ 1. 内置忽略项和 `.gitignore`。
56
+ 2. 应用运行环境与 Node.js 工程文件 globals。
57
+ 3. Common、JavaScript、Import、RegExp、TypeScript 与 JSON。
58
+ 4. `package.json` `tsconfig*.json` 排序。
59
+ 5. VueUniApp globals 与清单适配。
60
+ 6. Prettier 冲突关闭层。
61
+ 7. Node.js 工程文件末尾规则覆写。
62
+ 8. 调用方后置 Flat Config。
66
63
 
67
- `createLodashConfigs()` 使用 ESLint 核心 `no-restricted-imports`,因此无需增加插件依赖。它通过 `configs` 子路径按需组合,负责防止静态 import/export 混用包入口,不负责安装目标包,也不检查动态 `import()` 或 CommonJS `require()`。
68
-
69
- ## 质量门禁
70
-
71
- 发布前必须全部通过:
64
+ ## 发布前验证
72
65
 
73
66
  ```sh
67
+ pnpm typegen
74
68
  pnpm check
75
69
  pnpm pack --dry-run
76
70
  ```
77
71
 
78
- `pnpm check` 包含:
79
-
80
- 1. 生成类型漂移检查。
81
- 2. 正式 ESM 与声明文件构建。
82
- 3. TypeScript 源码类型检查。
83
- 4. ESLint 全仓检查。
84
- 5. Prettier 格式检查。
85
- 6. 消费者类型契约测试。
86
- 7. 运行时配置集成测试。
87
- 8. 发布元数据、入口文件和声明文件契约测试。
88
-
89
- 发布归档必须包含根入口和 `./configs`、`./constants`、`./rules` 子入口的 JavaScript 与声明文件,以及生成的 JavaScript、声明 source map;且不得包含源码缓存、测试缓存或本地依赖目录。
90
-
91
- ## CI 与发布边界
92
-
93
- GitHub Actions 在 `master`、`main` 推送和 Pull Request 上运行,覆盖 Node.js 22.18 和 24.18。CI 使用 pnpm 11.x、冻结锁文件安装、完整质量门禁和发布归档预览。
94
-
95
- CI 只验证代码和发布包,不自动发布 npm。正式发布仍由维护者确认版本、Changelog、归档内容和 npm 身份后执行。
72
+ 发布归档必须包含根入口和 `./configs`、`./constants`、`./rules` 子入口,不得包含源码缓存或本地依赖目录。CI 只负责验证,不自动发布 npm。
96
73
 
97
74
  ## 剩余风险
98
75
 
99
- - ESLint 和插件推荐预置会随依赖升级变化,每次升级都要检查实际生效配置和生成类型差异。
100
- - React Angular 默认关闭;启用 Angular 时必须同时启用 TypeScript,并把现代组件、变更检测、控制流和无障碍规则作为框架接入成本审查。
101
- - 类型感知模式依赖项目 `tsconfig.json` 覆盖被检查文件,复杂 monorepo 应显式设置 `tsconfigRootDir`。
102
- - 自动修复可能调整 import、模板属性、正则表达式和清单字段,应在独立提交中审查结果。
103
- - Lodash 策略只覆盖静态模块语法;需要限制 CommonJS 或动态导入的项目应追加自己的文件级规则或代码审查约定。
104
- - npm 发布自动化尚未启用,后续应在可信发布、分支保护和维护者审批策略确定后单独设计。
76
+ - 上游 recommended 会随依赖升级变化,升级 ESLint 或插件后必须检查实际生效配置。
77
+ - 类型感知依赖 tsconfig 覆盖和 Project Service,复杂 monorepo 需要维护清晰的项目边界。
78
+ - Import、类型导入、Vue 属性和清单排序可能被 `eslint --fix` 修改,需要审查副作用顺序和纯排序差异。
79
+ - 根入口默认声明 UniApp 条件编译 globals,不能验证平台分支;普通 Vue 项目如需避免 globals 扩散应改用片段组合。
80
+ - `.uvue` `.uts` 仍不在支持范围。
@@ -1,105 +1,108 @@
1
- # Default Rules, Risk Levels, and Maintenance
2
-
3
- This document records what the default config inherits, which rules can have a large adoption or review cost, and what maintainers must update when changing rules.
4
-
5
- ## Risk labels
6
-
7
- - `[High impact]`: the rule can create a large diff, block existing patterns, or require a review of runtime or public API behavior.
8
- - `[Auto-fixable]`: the currently locked ESLint or plugin version declares the rule fixable by `eslint --fix`. It does not remove the need for review.
9
- - `[Security]`: the rule primarily protects a trust or injection boundary.
10
- - `[Disabled by default]` and `[Opt-in]`: the rule record exists but is not loaded by the default config.
11
-
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
-
14
- ## Bundled preset sources
15
-
16
- `fastConfig()` defaults to a conventional Vue 3 browser administration project with TypeScript, JavaScript, import, RegExp, JSON, and the Prettier compatibility layer. React, Angular, Markdown, type-aware TypeScript linting, and manifest sorting are opt-in. Lodash policies are separate fragments from the `configs` subpath.
17
-
18
- | Scope | Inherited preset | Notes |
19
- | ---------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
20
- | JavaScript | `@eslint/js` `recommended` | Core syntax and runtime correctness, including `no-undef` and `no-unused-vars`. |
21
- | TypeScript | typescript-eslint `recommended` + `stylistic` | Does not read type information by default; local overrides are applied afterward. |
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. |
25
- | Imports | `eslint-plugin-import-x` `recommended` | Local rules add import placement, deduplication, and ordering. Resolver-dependent checks stay disabled. |
26
- | RegExp | `eslint-plugin-regexp` `flat/recommended` | Some rules can rewrite regular expressions; run tests after bulk fixes. |
27
- | JSON dialects | The matching `eslint-plugin-jsonc` `flat/recommended-*` preset | JSON, JSONC, and JSON5 are scoped separately. |
28
- | Markdown (opt-in) | `@eslint/markdown` `recommended` | Checks Markdown structure and syntax. |
29
- | Prettier compatibility | `eslint-config-prettier/flat` | Disables conflicting rules only; it does not run Prettier through ESLint. |
30
-
31
- The exact upstream rule set is defined by the dependency versions in `pnpm-lock.yaml`. Review the effective config with the config inspector whenever ESLint or a plugin is upgraded instead of copying an upstream list that will become stale.
32
-
33
- ## High-impact defaults
34
-
35
- | Rule | Severity | Auto-fix | Main impact | Recommended review |
36
- | ------------------------------------------------------- | ---------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
37
- | `import-x/order` | error | Yes | Groups and reorders imports. Unassigned side-effect imports are reported but cannot be safely moved automatically. | Check entrypoints, polyfills, styles, and registration imports. |
38
- | `@typescript-eslint/no-unused-vars` | error | Yes in the locked plugin | Can remove unused imports, variables, or declarations. An underscore prefix is the explicit escape hatch. | Run type checking, builds, and tests after an isolated cleanup. |
39
- | `@typescript-eslint/consistent-type-imports` | error | Yes | Converts type-only dependencies to inline `type` imports; an import used only for side effects could disappear from emitted code. | Express side effects as a separate `import "module"` and inspect build output. |
40
- | `@typescript-eslint/no-require-imports` | error | No | Blocks CommonJS, conditional loading, and some toolchain interop patterns. | Disable only for configuration files that genuinely require it. |
41
- | `no-var` | error | Yes | Moves `var` declarations to block scope; hoisting and loop closures need attention. | Run behavior tests, especially around callbacks created in loops. |
42
- | `prefer-arrow-callback` | error | Yes | Rewrites callbacks; code relying on `this`, `arguments`, or named stack frames needs review. | Check event handlers, library callbacks, and stack traces. |
43
- | `logical-assignment-operators` | error | Yes | Rewrites conditional assignment; getter and Proxy access counts deserve review. | Test state containers and reactive objects. |
44
- | `no-restricted-syntax` (`LabeledStatement`) | error | No | Requires control-flow refactoring for labeled break or continue. | Downgrade only in affected files and restore after refactoring. |
45
- | `sort-imports` | warn | Yes | Sorts members inside one import declaration and usually creates text-only diffs. | Keep it in an isolated cleanup with `import-x/order`. |
46
- | `vue/require-explicit-emits` | error | No | Makes emitted events an explicit component API and can surface undeclared events. | Model the real event list instead of disabling it blindly. |
47
- | `vue/no-mutating-props` | error | No | Enforces one-way data flow and may require local state or event changes. | Review the fix as a component-design change. |
48
- | `vue/attributes-order` | error | Yes | Can reorder many template attributes on first use. | Keep template sorting separate from business changes. |
49
- | `no-unused-vars`, `no-undef` from the JavaScript preset | error | No | Can report many existing issues and expose missing runtime-global declarations. | Select the correct `environment` before cleanup. |
50
- | RegExp recommended preset | Upstream-defined | Some rules | May rewrite character classes, quantifiers, or assertions. | Exercise representative real-world inputs after fixing. |
51
-
52
- `vue/no-v-html` is also enabled as a warning. It is a security signal rather than an automatic rewrite: HTML must be trusted or reliably sanitized.
53
-
54
- ## High-impact features not enabled by default
55
-
56
- - Type-aware TypeScript and Vue presets require `typeChecked: true`. They add project-service cost and rules such as `no-floating-promises`. `prefer-promise-reject-errors` permits transparent forwarding of `unknown` rejection reasons while still reporting statically known non-`Error` values such as strings and numbers.
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.
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.
60
- - Lodash import restrictions require `createLodashConfigs("lodash")` or `createLodashConfigs("lodash-unified")` from the `configs` subpath. They use `no-restricted-imports` to prevent mixed static package entry points but do not inspect dynamic `import()` or CommonJS `require()`.
61
- - Resolver-dependent import checks such as `import-x/no-unresolved` and `import-x/named` stay disabled.
62
- - Keys inside `package.json#exports` are never sorted. Node conditional exports use key order during matching, so reordering can change the loaded file.
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
-
66
- ## Scoped overrides
67
-
68
- Overrides must follow the shared config and should target only the affected files:
69
-
70
- ```js
71
- import fastChina, { defineRules } from "@fast-china/eslint-config";
72
-
73
- export default fastChina(
74
- {},
75
- {
76
- name: "project/typescript-exceptions",
77
- files: ["**/*.{ts,tsx,mts,cts,vue}"],
78
- rules: defineRules({
79
- "@typescript-eslint/consistent-type-imports": "warn",
80
- "@typescript-eslint/no-require-imports": "off",
81
- "@typescript-eslint/no-unused-vars": "warn",
82
- }),
83
- },
84
- {
85
- name: "project/vue-exceptions",
86
- files: ["**/*.vue"],
87
- rules: defineRules({
88
- "vue/attributes-order": "warn",
89
- "vue/require-explicit-emits": "warn",
90
- }),
91
- }
92
- );
1
+ # Default Rules and Risk Guide
2
+
3
+ This document describes the current 2.1.0 configuration model, major rules, and migration risks. Source comments explain current intent only; historical changes belong in `CHANGELOG.md`.
4
+
5
+ ## Configuration model
6
+
7
+ SDKs, OA systems, administration apps, Vue web apps, and UniApp clients share one JavaScript, TypeScript, Import, and RegExp rule set. There are no strictness tiers.
8
+
9
+ The root entry is a fixed Vue 3 + TypeScript + UniApp preset:
10
+
11
+ - `environment: "browser"`
12
+ - `.gitignore`
13
+ - JavaScript and type-aware TypeScript
14
+ - Vue 3, `.nvue`, UniApp globals, and manifest handling
15
+ - Import, RegExp, JSON, JSONC, and JSON5
16
+ - `package.json` and `tsconfig*.json` sorting
17
+ - Prettier conflict handling
18
+ - Node.js tooling globals and trailing rule overrides
19
+
20
+ `fastConfig()` retains only `environment`. React, Angular, Markdown, and Lodash compose from `./configs`; rules, globals, ignores, and special parser settings use trailing Flat Config objects.
21
+
22
+ ## Preset sources
23
+
24
+ | Domain | Preset or implementation |
25
+ | ---------- | -------------------------------------------------------------------------- |
26
+ | JavaScript | `@eslint/js` recommended plus local rules |
27
+ | TypeScript | typescript-eslint `recommendedTypeChecked` plus Project Service |
28
+ | Vue | `eslint-plugin-vue` `flat/recommended` plus type-aware TypeScript |
29
+ | React | `@eslint-react` recommended/type-checked plus React Hooks Flat Recommended |
30
+ | Angular | Angular ESLint TypeScript, template, and accessibility recommended presets |
31
+ | JSON | `eslint-plugin-jsonc` recommended presets for three dialects |
32
+ | Import | `eslint-plugin-import-x` recommended plus a fixed ordering policy |
33
+ | RegExp | Explicit correctness, safety, and super-linear backtracking rules |
34
+ | Prettier | `eslint-config-prettier` conflict disabling |
35
+
36
+ ## Major rules
37
+
38
+ ### JavaScript
39
+
40
+ - `camelcase: ["error", { properties: "never" }]`
41
+ - `no-debugger: "error"`
42
+ - `no-use-before-define` warns; classes and variables must be declared first while function declarations may be hoisted.
43
+ - `prefer-arrow-callback`, `logical-assignment-operators`, and `prefer-object-spread` are errors.
44
+ - `prefer-exponentiation-operator` and `prefer-object-has-own` are errors.
45
+ - `sort-imports` warns and only sorts members within one import.
46
+ - `import-x/order` is an error with `warnOnUnassignedImports: true`.
47
+
48
+ ### TypeScript
49
+
50
+ - `recommendedTypeChecked` and `projectService: true` are always enabled.
51
+ - `explicit-module-boundary-types` is an error and does not allow explicitly typed `any` arguments as an escape hatch.
52
+ - `explicit-function-return-type` is not additionally enabled, so internal functions and callbacks can rely on inference.
53
+ - `no-explicit-any` warns.
54
+ - `no-unused-vars` is an error; an `_` prefix marks intentional omissions and rest siblings are ignored.
55
+ - `no-empty-function` only allows empty constructors and override methods.
56
+ - `consistent-type-imports` uses inline `type` fixes.
57
+ - `no-non-null-assertion` is an error.
58
+
59
+ ### Vue
60
+
61
+ - Uses `flat/recommended`.
62
+ - `attribute-hyphenation: ["error", "always"]`.
63
+ - `no-v-html` warns.
64
+ - `no-v-text-v-html-on-component` is an error.
65
+ - `require-explicit-emits`, `attributes-order`, and `no-mutating-props` are errors.
66
+ - `.vue` and `.nvue` share the TypeScript parser and Project Service.
67
+
68
+ ## Type-aware requirements
69
+
70
+ TypeScript, Vue, and React TSX always require type information. Linted files must belong to a discoverable `tsconfig.json`, or Project Service reports a configuration error.
71
+
72
+ The `typeChecked` and `tsconfigRootDir` wrapper options no longer exist. Complex monorepos can override `languageOptions.parserOptions` in trailing Flat Config, but should not disable type checking to hide project-boundary problems.
73
+
74
+ ## UniApp boundary
75
+
76
+ The root entry declares `uni`, `uniCloud`, page APIs, and conditional-platform objects, and permits comments in `pages.json` and `manifest.json`.
77
+
78
+ ESLint does not execute conditional compilation, so `wx`, `plus`, and similar objects are visible in every code file handled by the root entry. This prevents `no-undef` inside platform branches but cannot verify that objects occur under the correct `#ifdef`. Plain Vue projects that do not want these globals should compose focused fragments instead of using the root entry.
79
+
80
+ ## Auto-fix risks
81
+
82
+ Review these fixes carefully:
83
+
84
+ - Import groups, member order, and side-effect import placement.
85
+ - Inline TypeScript `type` imports.
86
+ - Vue attribute naming and ordering.
87
+ - `package.json` and `tsconfig*.json` key order.
88
+
89
+ `package.json` sorting does not enter conditional `exports` objects whose order has runtime meaning.
90
+
91
+ Run a check first:
92
+
93
+ ```sh
94
+ pnpm exec eslint .
93
95
  ```
94
96
 
95
- Run a read-only lint first, then apply `eslint --fix` on a separate branch or commit. Review imports, side-effect entrypoints, package exports, component events, and manifests before running the project's type checks, build, and tests.
97
+ Then apply fixes after reviewing the scope:
98
+
99
+ ```sh
100
+ pnpm exec eslint . --fix
101
+ ```
96
102
 
97
- ## Rule-change checklist
103
+ ## Maintenance policy
98
104
 
99
- 1. Every local rule in `src/rules/` must explain its purpose, rationale, and important exception or risk; translating the rule name is not enough.
100
- 2. Add `[High impact]` when appropriate. For fixable rules, verify `meta.fixable` in the installed version instead of relying on memory.
101
- 3. Update this file, `rules-risk.zh.md`, both READMEs, and `CHANGELOG.md` for default behavior changes.
102
- 4. Never sort maps whose key order has semantics, including conditional objects under `package.json#exports`.
103
- 5. Run `pnpm typegen` after changing ESLint or any bundled plugin; inspect and commit `src/typegen.d.ts` instead of editing it manually.
104
- 6. Add integration coverage for parser, plugin, scope, auto-fix, generated-type, and public-export changes.
105
- 7. Run `pnpm check` and `pnpm pack --dry-run`, then inspect the real fix diff.
105
+ 1. Rule comments explain current behavior, risk, and exceptions without referring to historical versions.
106
+ 2. After upgrading recommended presets, inspect the final effective rules to prevent silent severity changes.
107
+ 3. New frameworks add parsers, file scopes, and framework semantics without creating another language-rule tier.
108
+ 4. New public factories, parsers, or auto-fix behavior require type and runtime tests.