@houheaven/eslint-config-helper 2.1.2 → 2.1.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.
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_deprecated.js +16 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +0 -17
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/stylistic.js +14 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/_deprecated.js +29 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/class-component.js +170 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/dom.js +140 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/fixable.js +239 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/jsx.js +147 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/prop-types.js +128 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/suggestion.js +42 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/_deprecated.js +19 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/fixable.js +228 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/other.js +19 -0
- package/node_modules/@houheaven/eslint-config-helper-core/summary.js +9 -1
- package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +28 -0
- package/package.json +4 -4
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// eslint-plugin-react-hooks - fixable
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// 支持 --fix 或提供 code action 建议的规则,一律 "warn":
|
|
6
|
+
// 编辑器/CI 一跑 --fix 就能自动纠正,不必阻断开发。
|
|
7
|
+
// ==========================================================
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
rules: {
|
|
11
|
+
// useEffect / useMemo / useCallback 等 Hook 依赖项穷尽性校验
|
|
12
|
+
// ----------------------------------------------------------
|
|
13
|
+
// 官方推荐:recommended(默认 warn)
|
|
14
|
+
// options: { additionalHooks?: string, enableDangerousAutofixThisMayCauseInfiniteLoops?: boolean,
|
|
15
|
+
// experimental_autoDependenciesHooks?: string[], requireExplicitEffectDeps?: boolean }
|
|
16
|
+
// 社区最佳:保持 recommended 默认;如有自定义 hook 如 useDeepCompareEffect,可通过 additionalHooks 正则接入
|
|
17
|
+
// - 官方文档:https://github.com/facebook/react/issues/14920
|
|
18
|
+
"react-hooks/exhaustive-deps": "warn",
|
|
19
|
+
|
|
20
|
+
// Validates the rules of hooks(新版可自动修复的 Rules of Hooks 检查器)
|
|
21
|
+
// ----------------------------------------------------------
|
|
22
|
+
// 官方推荐:无(recommended-latest 未启用,rules-of-hooks 仍是主入口)
|
|
23
|
+
// options: 无
|
|
24
|
+
// 社区最佳:可与 rules-of-hooks 并存作为渐进式迁移开关;正式项目通常保持默认关闭
|
|
25
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/hooks
|
|
26
|
+
"react-hooks/hooks": "off",
|
|
27
|
+
|
|
28
|
+
// 禁止把首字母大写的函数当作普通函数调用(应写为 JSX)
|
|
29
|
+
// ----------------------------------------------------------
|
|
30
|
+
// 官方推荐:无
|
|
31
|
+
// options: 无
|
|
32
|
+
// 社区最佳:React Compiler 场景推荐启用,避免误把组件当普通函数
|
|
33
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/capitalized-calls
|
|
34
|
+
"react-hooks/capitalized-calls": "warn",
|
|
35
|
+
|
|
36
|
+
// 组件必须是静态定义,禁止在渲染过程中动态创建
|
|
37
|
+
// ----------------------------------------------------------
|
|
38
|
+
// 官方推荐:recommended(默认 error)
|
|
39
|
+
// options: 无
|
|
40
|
+
// 社区最佳:一律启用,避免 state 被意外重置或引发过量 re-render
|
|
41
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/static-components
|
|
42
|
+
"react-hooks/static-components": "warn",
|
|
43
|
+
|
|
44
|
+
// useMemo 常见误用检查(如缺失依赖、错误 return)
|
|
45
|
+
// ----------------------------------------------------------
|
|
46
|
+
// 官方推荐:recommended(默认 error)
|
|
47
|
+
// options: 无
|
|
48
|
+
// 社区最佳:保持启用
|
|
49
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/use-memo
|
|
50
|
+
"react-hooks/use-memo": "warn",
|
|
51
|
+
|
|
52
|
+
// useMemo 必须返回值且返回值必须被使用
|
|
53
|
+
// ----------------------------------------------------------
|
|
54
|
+
// 官方推荐:无(recommended-latest 启用为 error)
|
|
55
|
+
// options: 无
|
|
56
|
+
// 社区最佳:新项目直接启用,避免退化为副作用函数
|
|
57
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/void-use-memo
|
|
58
|
+
"react-hooks/void-use-memo": "warn",
|
|
59
|
+
|
|
60
|
+
// React Compiler 场景下保留手工 memo(useMemo / useCallback / React.memo)
|
|
61
|
+
// ----------------------------------------------------------
|
|
62
|
+
// 官方推荐:recommended(默认 error)
|
|
63
|
+
// options: 无
|
|
64
|
+
// 社区最佳:接入 React Compiler 时必开
|
|
65
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/preserve-manual-memoization
|
|
66
|
+
"react-hooks/preserve-manual-memoization": "warn",
|
|
67
|
+
|
|
68
|
+
// useMemo / useCallback 的依赖项穷尽性 & 冗余校验
|
|
69
|
+
// ----------------------------------------------------------
|
|
70
|
+
// 官方推荐:无(未进入 recommended)
|
|
71
|
+
// options: 无
|
|
72
|
+
// 社区最佳:与 exhaustive-deps 覆盖面重叠,通常挑选一个即可
|
|
73
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/memo-dependencies
|
|
74
|
+
"react-hooks/memo-dependencies": "off",
|
|
75
|
+
|
|
76
|
+
// 阻止使用与 memoization 不兼容的第三方库 API
|
|
77
|
+
// ----------------------------------------------------------
|
|
78
|
+
// 官方推荐:recommended(默认 warn)
|
|
79
|
+
// options: 无
|
|
80
|
+
// 社区最佳:保持默认 warn,让开发者感知不兼容 API
|
|
81
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/incompatible-library
|
|
82
|
+
"react-hooks/incompatible-library": "warn",
|
|
83
|
+
|
|
84
|
+
// 禁止修改 props / state 等不可变值
|
|
85
|
+
// ----------------------------------------------------------
|
|
86
|
+
// 官方推荐:recommended(默认 error)
|
|
87
|
+
// options: 无
|
|
88
|
+
// 社区最佳:一律启用;React 官方明确 props/state 不可变
|
|
89
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/immutability
|
|
90
|
+
"react-hooks/immutability": "warn",
|
|
91
|
+
|
|
92
|
+
// 禁止在 render 期间写全局变量
|
|
93
|
+
// ----------------------------------------------------------
|
|
94
|
+
// 官方推荐:recommended(默认 error)
|
|
95
|
+
// options: 无
|
|
96
|
+
// 社区最佳:一律启用;render 必须无副作用
|
|
97
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/globals
|
|
98
|
+
"react-hooks/globals": "warn",
|
|
99
|
+
|
|
100
|
+
// 禁止在 render 期间读/写 ref
|
|
101
|
+
// ----------------------------------------------------------
|
|
102
|
+
// 官方推荐:recommended(默认 error)
|
|
103
|
+
// options: 无
|
|
104
|
+
// 社区最佳:一律启用,避免踩到 useRef 官方警告的 pitfall
|
|
105
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/refs
|
|
106
|
+
"react-hooks/refs": "warn",
|
|
107
|
+
|
|
108
|
+
// effect 依赖项必须是被 memoize 过的引用
|
|
109
|
+
// ----------------------------------------------------------
|
|
110
|
+
// 官方推荐:无
|
|
111
|
+
// options: 无
|
|
112
|
+
// 社区最佳:与 exhaustive-effect-dependencies 组合可换掉 exhaustive-deps;分歧较大,默认关
|
|
113
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/memoized-effect-dependencies
|
|
114
|
+
"react-hooks/memoized-effect-dependencies": "off",
|
|
115
|
+
|
|
116
|
+
// effect 依赖项穷尽 & 无冗余校验(新一代实现,替代 exhaustive-deps)
|
|
117
|
+
// ----------------------------------------------------------
|
|
118
|
+
// 官方推荐:无(尚在实验期)
|
|
119
|
+
// options: 无
|
|
120
|
+
// 社区最佳:与 exhaustive-deps 二选一即可,暂保持关闭
|
|
121
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/exhaustive-effect-dependencies
|
|
122
|
+
"react-hooks/exhaustive-effect-dependencies": "off",
|
|
123
|
+
|
|
124
|
+
// 禁止在 useEffect 中同步 setState
|
|
125
|
+
// ----------------------------------------------------------
|
|
126
|
+
// 官方推荐:recommended(默认 error)
|
|
127
|
+
// options: 无
|
|
128
|
+
// 社区最佳:启用;同步 setState 一般意味着可以下沉到 render 或事件
|
|
129
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-effect
|
|
130
|
+
"react-hooks/set-state-in-effect": "warn",
|
|
131
|
+
|
|
132
|
+
// 禁止在 effect 里从 state 派生 state
|
|
133
|
+
// ----------------------------------------------------------
|
|
134
|
+
// 官方推荐:无
|
|
135
|
+
// options: 无
|
|
136
|
+
// 社区最佳:默认关,推荐用 useMemo 或 render 内派生
|
|
137
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/no-deriving-state-in-effects
|
|
138
|
+
"react-hooks/no-deriving-state-in-effects": "off",
|
|
139
|
+
|
|
140
|
+
// 应使用 error boundary 而非 try/catch 捕获子组件错误
|
|
141
|
+
// ----------------------------------------------------------
|
|
142
|
+
// 官方推荐:recommended(默认 error)
|
|
143
|
+
// options: 无
|
|
144
|
+
// 社区最佳:启用;React 官方推荐 error boundary
|
|
145
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/error-boundaries
|
|
146
|
+
"react-hooks/error-boundaries": "warn",
|
|
147
|
+
|
|
148
|
+
// 校验组件 / Hook 的纯度,禁止调用已知有副作用的函数
|
|
149
|
+
// ----------------------------------------------------------
|
|
150
|
+
// 官方推荐:recommended(默认 error)
|
|
151
|
+
// options: 无
|
|
152
|
+
// 社区最佳:启用;React 官方 "Components and Hooks must be pure" 规范
|
|
153
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/purity
|
|
154
|
+
"react-hooks/purity": "warn",
|
|
155
|
+
|
|
156
|
+
// 禁止在 render 阶段同步 setState
|
|
157
|
+
// ----------------------------------------------------------
|
|
158
|
+
// 官方推荐:recommended(默认 error)
|
|
159
|
+
// options: 无
|
|
160
|
+
// 社区最佳:启用;避免额外的 render 与死循环风险
|
|
161
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/set-state-in-render
|
|
162
|
+
"react-hooks/set-state-in-render": "warn",
|
|
163
|
+
|
|
164
|
+
// 内部不变量校验(Compiler 内部规则)
|
|
165
|
+
// ----------------------------------------------------------
|
|
166
|
+
// 官方推荐:无
|
|
167
|
+
// options: 无
|
|
168
|
+
// 社区最佳:非用户业务规则,保持默认关闭
|
|
169
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/invariant
|
|
170
|
+
"react-hooks/invariant": "off",
|
|
171
|
+
|
|
172
|
+
// 未实现的功能占位规则
|
|
173
|
+
// ----------------------------------------------------------
|
|
174
|
+
// 官方推荐:无
|
|
175
|
+
// options: 无
|
|
176
|
+
// 社区最佳:占位规则,保持默认关闭
|
|
177
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/todo
|
|
178
|
+
"react-hooks/todo": "off",
|
|
179
|
+
|
|
180
|
+
// 校验源码是否包含 React Compiler 无法解析的语法
|
|
181
|
+
// ----------------------------------------------------------
|
|
182
|
+
// 官方推荐:无(Compiler 内部规则)
|
|
183
|
+
// options: 无
|
|
184
|
+
// 社区最佳:仅在启用 React Compiler 时开启
|
|
185
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/syntax
|
|
186
|
+
"react-hooks/syntax": "off",
|
|
187
|
+
|
|
188
|
+
// 校验源码是否使用 React Compiler 明确不支持的语法
|
|
189
|
+
// ----------------------------------------------------------
|
|
190
|
+
// 官方推荐:recommended(默认 warn)
|
|
191
|
+
// options: 无
|
|
192
|
+
// 社区最佳:启用 React Compiler 项目保持 warn
|
|
193
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/unsupported-syntax
|
|
194
|
+
"react-hooks/unsupported-syntax": "warn",
|
|
195
|
+
|
|
196
|
+
// 校验 React Compiler 配置项合法
|
|
197
|
+
// ----------------------------------------------------------
|
|
198
|
+
// 官方推荐:recommended(默认 error)
|
|
199
|
+
// options: 无
|
|
200
|
+
// 社区最佳:启用 React Compiler 时必开
|
|
201
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/config
|
|
202
|
+
"react-hooks/config": "warn",
|
|
203
|
+
|
|
204
|
+
// 校验 React Compiler 的 gating 配置
|
|
205
|
+
// ----------------------------------------------------------
|
|
206
|
+
// 官方推荐:recommended(默认 error)
|
|
207
|
+
// options: 无
|
|
208
|
+
// 社区最佳:启用 React Compiler + gating 时必开
|
|
209
|
+
// - 官方文档:https://react.dev/reference/react-compiler/gating
|
|
210
|
+
"react-hooks/gating": "warn",
|
|
211
|
+
|
|
212
|
+
// 禁止用 eslint-disable 抑制本插件其它规则
|
|
213
|
+
// ----------------------------------------------------------
|
|
214
|
+
// 官方推荐:无(未进入 recommended)
|
|
215
|
+
// options: 无
|
|
216
|
+
// 社区最佳:谨慎启用,业务里可能有临时豁免场景
|
|
217
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/rule-suppression
|
|
218
|
+
"react-hooks/rule-suppression": "off",
|
|
219
|
+
|
|
220
|
+
// 校验 fbt 国际化组件使用(Facebook 内部约定)
|
|
221
|
+
// ----------------------------------------------------------
|
|
222
|
+
// 官方推荐:无
|
|
223
|
+
// options: 无
|
|
224
|
+
// 社区最佳:仅 Facebook / Meta 内部生态启用,其它项目一律关闭
|
|
225
|
+
// - 官方文档:https://react.dev/reference/eslint-plugin-react-hooks/lints/fbt
|
|
226
|
+
"react-hooks/fbt": "off",
|
|
227
|
+
},
|
|
228
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// eslint-plugin-react-hooks - other
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// 未匹配到「deprecated / fixable / suggestion」维度的规则;
|
|
6
|
+
// 启用一律 "error"(不可自动修复,必须人工介入)。
|
|
7
|
+
// ==========================================================
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
rules: {
|
|
11
|
+
// Rules of Hooks(顶层 Hook / 仅在函数组件或自定义 Hook 内调用)
|
|
12
|
+
// ----------------------------------------------------------
|
|
13
|
+
// 官方推荐:recommended(默认 error)
|
|
14
|
+
// options: 无
|
|
15
|
+
// 社区最佳:一律 error;React 官方 "Rules of Hooks" 硬性约束,一旦违反会引发 bug
|
|
16
|
+
// - 官方文档:https://react.dev/reference/rules/rules-of-hooks
|
|
17
|
+
"react-hooks/rules-of-hooks": "error",
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
// 统计数据
|
|
3
3
|
// 使用方式:node summary.js
|
|
4
4
|
|
|
5
|
-
const allRules =
|
|
5
|
+
const allRules = {
|
|
6
|
+
...require("./rules/react/_deprecated.js").rules,
|
|
7
|
+
...require("./rules/react/class-component.js").rules,
|
|
8
|
+
...require("./rules/react/dom.js").rules,
|
|
9
|
+
...require("./rules/react/fixable.js").rules,
|
|
10
|
+
...require("./rules/react/jsx.js").rules,
|
|
11
|
+
...require("./rules/react/prop-types.js").rules,
|
|
12
|
+
...require("./rules/react/suggestion.js").rules,
|
|
13
|
+
};
|
|
6
14
|
|
|
7
15
|
// 统计函数
|
|
8
16
|
function countRulesByLevel(rulesObj) {
|
|
@@ -53,6 +53,20 @@ const EslintRules = {
|
|
|
53
53
|
...require("../rules/vue/vue3-strongly-recommended.js").rules,
|
|
54
54
|
...require("../rules/vue/vue3-uncategorized.js").rules,
|
|
55
55
|
},
|
|
56
|
+
react: {
|
|
57
|
+
// ...require("../rules/react/_deprecated.js").rules,
|
|
58
|
+
...require("../rules/react/fixable.js").rules,
|
|
59
|
+
...require("../rules/react/suggestion.js").rules,
|
|
60
|
+
...require("../rules/react/jsx.js").rules,
|
|
61
|
+
...require("../rules/react/class-component.js").rules,
|
|
62
|
+
...require("../rules/react/prop-types.js").rules,
|
|
63
|
+
...require("../rules/react/dom.js").rules,
|
|
64
|
+
},
|
|
65
|
+
reactHooks: {
|
|
66
|
+
// ...require("../rules/react-hooks/_deprecated.js").rules,
|
|
67
|
+
...require("../rules/react-hooks/fixable.js").rules,
|
|
68
|
+
...require("../rules/react-hooks/other.js").rules,
|
|
69
|
+
},
|
|
56
70
|
};
|
|
57
71
|
|
|
58
72
|
|
|
@@ -73,6 +87,10 @@ function getRules(rules) {
|
|
|
73
87
|
...EslintRules.vue,
|
|
74
88
|
...EslintRules.vue2,
|
|
75
89
|
...EslintRules.vue3,
|
|
90
|
+
// react 规则
|
|
91
|
+
...EslintRules.react,
|
|
92
|
+
// react-hooks 规则
|
|
93
|
+
...EslintRules.reactHooks,
|
|
76
94
|
};
|
|
77
95
|
const ValidRules = {};
|
|
78
96
|
const InvalidRules = {};
|
|
@@ -138,6 +156,16 @@ function getWarnRules(type) {
|
|
|
138
156
|
...EslintRules.vue3,
|
|
139
157
|
};
|
|
140
158
|
break;
|
|
159
|
+
case "react":
|
|
160
|
+
rules = {
|
|
161
|
+
...EslintRules.react,
|
|
162
|
+
};
|
|
163
|
+
break;
|
|
164
|
+
case "react-hooks":
|
|
165
|
+
rules = {
|
|
166
|
+
...EslintRules.reactHooks,
|
|
167
|
+
};
|
|
168
|
+
break;
|
|
141
169
|
}
|
|
142
170
|
|
|
143
171
|
// 筛选规则
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@houheaven/eslint-config-helper",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Eslint 规则助手",
|
|
5
5
|
"author": "立树",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
|
43
|
-
"url": "https://
|
|
43
|
+
"url": "https://github.com/houheaven/eslint-config-helper.git"
|
|
44
44
|
},
|
|
45
45
|
"bugs": {
|
|
46
|
-
"url": "https://
|
|
46
|
+
"url": "https://github.com/houheaven/eslint-config-helper/issues"
|
|
47
47
|
},
|
|
48
|
-
"homepage": "https://
|
|
48
|
+
"homepage": "https://github.com/houheaven/eslint-config-helper",
|
|
49
49
|
"scripts": {
|
|
50
50
|
"lint": "eslint ."
|
|
51
51
|
},
|