@fast-china/eslint-config 2.1.7 → 2.1.9

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 (88) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/README.md +103 -144
  4. package/README.zh.md +101 -144
  5. package/dist/configs/environment.mjs +2 -0
  6. package/dist/configs/environment.mjs.map +1 -1
  7. package/dist/configs/ignores.mjs +0 -1
  8. package/dist/configs/ignores.mjs.map +1 -1
  9. package/dist/configs/import.mjs +4 -1
  10. package/dist/configs/import.mjs.map +1 -1
  11. package/dist/configs/index.d.mts +2 -2
  12. package/dist/configs/index.mjs +2 -2
  13. package/dist/configs/javascript.mjs +3 -1
  14. package/dist/configs/javascript.mjs.map +1 -1
  15. package/dist/configs/json.mjs +3 -1
  16. package/dist/configs/json.mjs.map +1 -1
  17. package/dist/configs/markdown.d.mts +2 -1
  18. package/dist/configs/markdown.mjs +4 -2
  19. package/dist/configs/markdown.mjs.map +1 -1
  20. package/dist/configs/prettier.mjs +1 -1
  21. package/dist/configs/prettier.mjs.map +1 -1
  22. package/dist/configs/sort-package.d.mts +1 -1
  23. package/dist/configs/sort-package.mjs +1 -1
  24. package/dist/configs/sort-package.mjs.map +1 -1
  25. package/dist/configs/sort-tsconfig.d.mts +2 -2
  26. package/dist/configs/sort-tsconfig.mjs +2 -2
  27. package/dist/configs/sort-tsconfig.mjs.map +1 -1
  28. package/dist/configs/typescript.d.mts +11 -7
  29. package/dist/configs/typescript.mjs +25 -22
  30. package/dist/configs/typescript.mjs.map +1 -1
  31. package/dist/configs/uniapp.mjs +19 -13
  32. package/dist/configs/uniapp.mjs.map +1 -1
  33. package/dist/configs/vue.d.mts +18 -3
  34. package/dist/configs/vue.mjs +61 -9
  35. package/dist/configs/vue.mjs.map +1 -1
  36. package/dist/constants/index.d.mts +4 -0
  37. package/dist/constants/index.mjs +5 -1
  38. package/dist/constants/index.mjs.map +1 -1
  39. package/dist/index.d.mts +37 -58
  40. package/dist/index.mjs +43 -47
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/rules/angular.d.mts +28 -0
  43. package/dist/rules/angular.mjs +28 -0
  44. package/dist/rules/angular.mjs.map +1 -1
  45. package/dist/rules/common.d.mts +16 -6
  46. package/dist/rules/common.mjs +16 -13
  47. package/dist/rules/common.mjs.map +1 -1
  48. package/dist/rules/import.d.mts +9 -0
  49. package/dist/rules/import.mjs +24 -0
  50. package/dist/rules/import.mjs.map +1 -1
  51. package/dist/rules/index.d.mts +2 -2
  52. package/dist/rules/index.mjs +2 -2
  53. package/dist/rules/javascript.d.mts +18 -0
  54. package/dist/rules/javascript.mjs +18 -0
  55. package/dist/rules/javascript.mjs.map +1 -1
  56. package/dist/rules/lodash.d.mts +2 -0
  57. package/dist/rules/lodash.mjs +6 -2
  58. package/dist/rules/lodash.mjs.map +1 -1
  59. package/dist/rules/react.d.mts +13 -0
  60. package/dist/rules/react.mjs +13 -0
  61. package/dist/rules/react.mjs.map +1 -1
  62. package/dist/rules/regexp.d.mts +25 -0
  63. package/dist/rules/regexp.mjs +25 -0
  64. package/dist/rules/regexp.mjs.map +1 -1
  65. package/dist/rules/sort-package.d.mts +3 -1
  66. package/dist/rules/sort-package.mjs +3 -1
  67. package/dist/rules/sort-package.mjs.map +1 -1
  68. package/dist/rules/sort-tsconfig.d.mts +3 -1
  69. package/dist/rules/sort-tsconfig.mjs +3 -1
  70. package/dist/rules/sort-tsconfig.mjs.map +1 -1
  71. package/dist/rules/typescript.d.mts +81 -13
  72. package/dist/rules/typescript.mjs +83 -15
  73. package/dist/rules/typescript.mjs.map +1 -1
  74. package/dist/rules/vue.d.mts +65 -10
  75. package/dist/rules/vue.mjs +41 -14
  76. package/dist/rules/vue.mjs.map +1 -1
  77. package/docs/engineering-audit.zh.md +45 -49
  78. package/docs/rules/angular.zh.md +721 -0
  79. package/docs/rules/core.zh.md +3031 -0
  80. package/docs/rules/index.zh.md +38 -0
  81. package/docs/rules/json.zh.md +784 -0
  82. package/docs/rules/markdown.zh.md +449 -0
  83. package/docs/rules/react.zh.md +2091 -0
  84. package/docs/rules/typescript.zh.md +2052 -0
  85. package/docs/rules/vue.zh.md +3016 -0
  86. package/docs/rules-risk.md +85 -91
  87. package/docs/rules-risk.zh.md +76 -82
  88. package/package.json +4 -2
@@ -0,0 +1,3031 @@
1
+ <!-- 此文件由 scripts/rules-docs.ts 生成,请勿手工编辑。 -->
2
+
3
+ # ESLint 核心、Import 与 RegExp
4
+
5
+ 本页记录当前依赖版本和仓库配置最终产生的 123 条规则。每条规则均列出实际严重级别、生效范围、上游说明、常见报告以及错误/正确示例。
6
+
7
+ ## 仓库显式规则(69 条)
8
+
9
+ ### `array-callback-return`
10
+
11
+ 要求数组回调在所有可到达分支返回值,避免 `map`、`filter` 等调用静默产生 `undefined`。
12
+
13
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
14
+ - 自动修复:不支持或上游未声明
15
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/array-callback-return)
16
+ - 常见报告:`{{arrayMethodName}}() expects a value to be returned at the end of {{name}}.`;`{{arrayMethodName}}() expects a return value from {{name}}.`;`{{arrayMethodName}}() expects no useless return value from {{name}}.`
17
+ - 示例类型:仓库显式规则的直接代码示例
18
+
19
+ 错误示例:
20
+
21
+ <!-- prettier-ignore -->
22
+ ````js
23
+ items.map((item) => { item.id; });
24
+ ````
25
+
26
+ 正确示例:
27
+
28
+ <!-- prettier-ignore -->
29
+ ````js
30
+ items.map((item) => item.id);
31
+ ````
32
+
33
+ ### `camelcase`
34
+
35
+ 变量和类型使用 camelCase;对象属性允许沿用外部协议字段名。
36
+
37
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
38
+ - 自动修复:不支持或上游未声明
39
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/camelcase)
40
+ - 常见报告:`Identifier '{{name}}' is not in camel case.`;`#{{name}} is not in camel case.`
41
+ - 示例类型:仓库显式规则的直接代码示例
42
+
43
+ 错误示例:
44
+
45
+ <!-- prettier-ignore -->
46
+ ````js
47
+ const user_name = "Fast";
48
+ ````
49
+
50
+ 正确示例:
51
+
52
+ <!-- prettier-ignore -->
53
+ ````js
54
+ const userName = "Fast";
55
+ const payload = { user_name: userName };
56
+ ````
57
+
58
+ ### `curly`
59
+
60
+ 简单单行分支允许省略花括号;多行分支必须使用花括号,同一条件链保持一致。
61
+
62
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
63
+ - 自动修复:支持;执行前仍应检查语义和差异
64
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/curly)
65
+ - 常见报告:`Expected { after '{{name}}'.`;`Expected { after '{{name}}' condition.`;`Unnecessary { after '{{name}}'.`
66
+ - 示例类型:仓库显式规则的直接代码示例
67
+
68
+ 错误示例:
69
+
70
+ <!-- prettier-ignore -->
71
+ ````js
72
+ if (ready)
73
+ start();
74
+ log();
75
+ ````
76
+
77
+ 正确示例:
78
+
79
+ <!-- prettier-ignore -->
80
+ ````js
81
+ if (ready) {
82
+ start();
83
+ log();
84
+ }
85
+ ````
86
+
87
+ ### `default-case-last`
88
+
89
+ `default` 分支不是强制项,但存在时统一位于其他 `case` 之后。
90
+
91
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
92
+ - 自动修复:不支持或上游未声明
93
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/default-case-last)
94
+ - 常见报告:`Default clause should be the last clause.`
95
+ - 示例类型:仓库显式规则的直接代码示例
96
+
97
+ 错误示例:
98
+
99
+ <!-- prettier-ignore -->
100
+ ````js
101
+ switch (status) { default: reset(); break; case "ready": start(); }
102
+ ````
103
+
104
+ 正确示例:
105
+
106
+ <!-- prettier-ignore -->
107
+ ````js
108
+ switch (status) { case "ready": start(); break; default: reset(); }
109
+ ````
110
+
111
+ ### `eqeqeq`
112
+
113
+ 要求严格相等;保留 `value == null` 同时判断 `null` 与 `undefined` 的常用写法。
114
+
115
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
116
+ - 自动修复:支持;执行前仍应检查语义和差异
117
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/eqeqeq)
118
+ - 常见报告:`Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'.`;`Use '{{expectedOperator}}' instead of '{{actualOperator}}'.`
119
+ - 示例类型:仓库显式规则的直接代码示例
120
+
121
+ 错误示例:
122
+
123
+ <!-- prettier-ignore -->
124
+ ````js
125
+ if (count == 0) reset();
126
+ ````
127
+
128
+ 正确示例:
129
+
130
+ <!-- prettier-ignore -->
131
+ ````js
132
+ if (count === 0) reset();
133
+ if (value == null) useFallback();
134
+ ````
135
+
136
+ ### `import-x/default`
137
+
138
+ 未配置 resolver 时,默认导出的静态分析容易产生误报。
139
+
140
+ - 生效级别与范围:默认关闭(本地显式覆写)
141
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
142
+ - 自动修复:不支持或上游未声明
143
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/default.md)
144
+ - 常见报告:`No default export found in imported module "{{module}}".`
145
+ - 示例类型:仓库显式规则的直接代码示例
146
+
147
+ 错误示例:
148
+
149
+ <!-- prettier-ignore -->
150
+ ````js
151
+ import api from "./named-only.js";
152
+ ````
153
+
154
+ 正确示例:
155
+
156
+ <!-- prettier-ignore -->
157
+ ````js
158
+ import { api } from "./named-only.js";
159
+ ````
160
+
161
+ ### `import-x/first`
162
+
163
+ `import` 必须位于其他语句之前,避免模块依赖散落在执行逻辑中。
164
+
165
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
166
+ - 自动修复:支持;执行前仍应检查语义和差异
167
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/first.md)
168
+ - 常见报告:`Absolute imports should come before relative imports.`;`Import in body of module; reorder to top.`
169
+ - 示例类型:仓库显式规则的直接代码示例
170
+
171
+ 错误示例:
172
+
173
+ <!-- prettier-ignore -->
174
+ ````js
175
+ initialize();
176
+ import { api } from "./api";
177
+ ````
178
+
179
+ 正确示例:
180
+
181
+ <!-- prettier-ignore -->
182
+ ````js
183
+ import { api } from "./api";
184
+ initialize(api);
185
+ ````
186
+
187
+ ### `import-x/named`
188
+
189
+ 未配置 resolver 时,命名导出的静态分析容易产生误报。
190
+
191
+ - 生效级别与范围:默认关闭(本地显式覆写)
192
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
193
+ - 自动修复:不支持或上游未声明
194
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/named.md)
195
+ - 常见报告:`{{name}} not found in '{{path}}'`;`{{name}} not found via {{deepPath}}`
196
+ - 示例类型:仓库显式规则的直接代码示例
197
+
198
+ 错误示例:
199
+
200
+ <!-- prettier-ignore -->
201
+ ````js
202
+ import { missing } from "./api.js";
203
+ ````
204
+
205
+ 正确示例:
206
+
207
+ <!-- prettier-ignore -->
208
+ ````js
209
+ import { request } from "./api.js";
210
+ ````
211
+
212
+ ### `import-x/namespace`
213
+
214
+ 未配置 resolver 时,namespace 导出的静态分析容易产生误报。
215
+
216
+ - 生效级别与范围:默认关闭(本地显式覆写)
217
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
218
+ - 自动修复:不支持或上游未声明
219
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/namespace.md)
220
+ - 常见报告:`No exported names found in module '{{module}}'.`;`Unable to validate computed reference to imported namespace '{{namespace}}'.`;`Assignment to member of namespace '{{namespace}}'.`
221
+ - 示例类型:仓库显式规则的直接代码示例
222
+
223
+ 错误示例:
224
+
225
+ <!-- prettier-ignore -->
226
+ ````js
227
+ import * as api from "./api.js";
228
+ api.missing();
229
+ ````
230
+
231
+ 正确示例:
232
+
233
+ <!-- prettier-ignore -->
234
+ ````js
235
+ import * as api from "./api.js";
236
+ api.request();
237
+ ````
238
+
239
+ ### `import-x/no-duplicates`
240
+
241
+ 合并同一模块的重复 `import`,避免绑定分散或副作用被误读。
242
+
243
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
244
+ - 自动修复:支持;执行前仍应检查语义和差异
245
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/no-duplicates.md)
246
+ - 常见报告:`'{{module}}' imported multiple times.`
247
+ - 示例类型:仓库显式规则的直接代码示例
248
+
249
+ 错误示例:
250
+
251
+ <!-- prettier-ignore -->
252
+ ````js
253
+ import { readFile } from "node:fs";
254
+ import { writeFile } from "node:fs";
255
+ ````
256
+
257
+ 正确示例:
258
+
259
+ <!-- prettier-ignore -->
260
+ ````js
261
+ import { readFile, writeFile } from "node:fs";
262
+ ````
263
+
264
+ ### `import-x/no-named-as-default`
265
+
266
+ 不限制同时存在默认导出与相近命名导出的模块 API 风格。
267
+
268
+ - 生效级别与范围:默认关闭(本地显式覆写)
269
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
270
+ - 自动修复:不支持或上游未声明
271
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/no-named-as-default.md)
272
+ - 常见报告:`Using exported name '{{name}}' as identifier for default export.`
273
+ - 示例类型:仓库显式规则的直接代码示例
274
+
275
+ 错误示例:
276
+
277
+ <!-- prettier-ignore -->
278
+ ````js
279
+ import request from "./request.js";
280
+ request();
281
+ ````
282
+
283
+ 正确示例:
284
+
285
+ <!-- prettier-ignore -->
286
+ ````js
287
+ import { request } from "./request.js";
288
+ request();
289
+ ````
290
+
291
+ ### `import-x/no-named-as-default-member`
292
+
293
+ 不限制通过默认导入对象访问同名属性的项目 API 风格。
294
+
295
+ - 生效级别与范围:默认关闭(本地显式覆写)
296
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
297
+ - 自动修复:不支持或上游未声明
298
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/no-named-as-default-member.md)
299
+ - 常见报告:`Caution: '{{objectName}}' also has a named export '{{propName}}'. Check if you meant to write 'import {{{propName}}} from '{{sourcePath}}'' instead.`
300
+ - 示例类型:仓库显式规则的直接代码示例
301
+
302
+ 错误示例:
303
+
304
+ <!-- prettier-ignore -->
305
+ ````js
306
+ import api from "./api.js";
307
+ api.request();
308
+ ````
309
+
310
+ 正确示例:
311
+
312
+ <!-- prettier-ignore -->
313
+ ````js
314
+ import { request } from "./api.js";
315
+ request();
316
+ ````
317
+
318
+ ### `import-x/no-unresolved`
319
+
320
+ Vite 与 TypeScript 别名由项目解析器校验,避免共享配置绑定特定 resolver。
321
+
322
+ - 生效级别与范围:默认关闭(本地显式覆写)
323
+ - 关闭范围:JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
324
+ - 自动修复:不支持或上游未声明
325
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/no-unresolved.md)
326
+ - 常见报告:`Unable to resolve path to module '{{module}}'.`;`Casing of {{module}} does not match the underlying filesystem.`
327
+ - 示例类型:仓库显式规则的直接代码示例
328
+
329
+ 错误示例:
330
+
331
+ <!-- prettier-ignore -->
332
+ ````js
333
+ import value from "./missing.js";
334
+ ````
335
+
336
+ 正确示例:
337
+
338
+ <!-- prettier-ignore -->
339
+ ````js
340
+ import value from "./value.js";
341
+ ````
342
+
343
+ ### `import-x/order`
344
+
345
+ `import` 按来源分组并排序,错误顺序可由 ESLint 自动修复。
346
+
347
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
348
+ - 自动修复:支持;执行前仍应检查语义和差异
349
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/order.md)
350
+ - 常见报告:`{{error}}`;`There should be no empty line within import group`;`There should be no empty line between import groups`
351
+ - 示例类型:仓库显式规则的直接代码示例
352
+
353
+ 错误示例:
354
+
355
+ <!-- prettier-ignore -->
356
+ ````ts
357
+ import { local } from "./local";
358
+ import path from "node:path";
359
+ import { ref } from "vue";
360
+ ````
361
+
362
+ 正确示例:
363
+
364
+ <!-- prettier-ignore -->
365
+ ````ts
366
+ import path from "node:path";
367
+ import { ref } from "vue";
368
+ import { local } from "./local";
369
+ ````
370
+
371
+ ### `import-x/style-imports-last`
372
+
373
+ 样式导入必须形成最后一个连续分组;规则不提供修复,避免改变 CSS 层叠顺序。
374
+
375
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
376
+ - 自动修复:不支持或上游未声明
377
+ - 规则来源:未提供
378
+ - 常见报告:`Style import '{{source}}' must occur after all non-style imports.`
379
+ - 示例类型:仓库显式规则的直接代码示例
380
+
381
+ 错误示例:
382
+
383
+ <!-- prettier-ignore -->
384
+ ````ts
385
+ import "./app.css";
386
+ import { createApp } from "vue";
387
+ ````
388
+
389
+ 正确示例:
390
+
391
+ <!-- prettier-ignore -->
392
+ ````ts
393
+ import { createApp } from "vue";
394
+ import "./app.css";
395
+ ````
396
+
397
+ ### `logical-assignment-operators`
398
+
399
+ 将可等价改写的逻辑赋值统一为 `||=`、`&&=`、`??=`,并覆盖对应的 `if` 赋值写法。
400
+
401
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
402
+ - 自动修复:支持;执行前仍应检查语义和差异
403
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/logical-assignment-operators)
404
+ - 常见报告:`Assignment (=) can be replaced with operator assignment ({{operator}}).`;`Convert this assignment to use the operator {{ operator }}.`;`Logical expression can be replaced with an assignment ({{ operator }}).`
405
+ - 示例类型:仓库显式规则的直接代码示例
406
+
407
+ 错误示例:
408
+
409
+ <!-- prettier-ignore -->
410
+ ````js
411
+ options.timeout = options.timeout || 3000;
412
+ ````
413
+
414
+ 正确示例:
415
+
416
+ <!-- prettier-ignore -->
417
+ ````js
418
+ options.timeout ||= 3000;
419
+ ````
420
+
421
+ ### `no-alert`
422
+
423
+ 浏览器弹窗通常不适合生产代码;使用警告允许原型调试,同时确保发布前能够被发现。
424
+
425
+ - 生效级别与范围:warn: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
426
+ - 自动修复:不支持或上游未声明
427
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-alert)
428
+ - 常见报告:`Unexpected {{name}}.`
429
+ - 示例类型:仓库显式规则的直接代码示例
430
+
431
+ 错误示例:
432
+
433
+ <!-- prettier-ignore -->
434
+ ````js
435
+ alert("Saved");
436
+ ````
437
+
438
+ 正确示例:
439
+
440
+ <!-- prettier-ignore -->
441
+ ````js
442
+ showMessage("Saved");
443
+ ````
444
+
445
+ ### `no-case-declarations`
446
+
447
+ `switch` 的 `case` 不创建词法作用域;要求用花括号包裹声明,避免跨分支冲突。
448
+
449
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
450
+ - 自动修复:不支持或上游未声明
451
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-case-declarations)
452
+ - 常见报告:`Add {} brackets around the case block.`;`Unexpected lexical declaration in case block.`
453
+ - 示例类型:仓库显式规则的直接代码示例
454
+
455
+ 错误示例:
456
+
457
+ <!-- prettier-ignore -->
458
+ ````js
459
+ switch (kind) { case "user": const name = getName(); use(name); break; }
460
+ ````
461
+
462
+ 正确示例:
463
+
464
+ <!-- prettier-ignore -->
465
+ ````js
466
+ switch (kind) { case "user": { const name = getName(); use(name); break; } }
467
+ ````
468
+
469
+ ### `no-console`
470
+
471
+ 构建、测试和 CLI 脚本允许把执行进度与诊断信息输出到终端。
472
+
473
+ - 生效级别与范围:warn: JavaScript 基础、Vue SFC、Vue JSX、UniApp NVue、React JSX、Angular TypeScript、Lodash、Lodash Unified
474
+ - 关闭范围:TypeScript 基础、框架无关 TSX、Vue TSX、UniApp TSX、React TSX
475
+ - 自动修复:不支持或上游未声明
476
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-console)
477
+ - 常见报告:`Unexpected console statement.`;`Unexpected console statement. Only these console methods are allowed: {{ allowed }}.`;`Remove the console.{{ propertyName }}().`
478
+ - 示例类型:仓库显式规则的直接代码示例
479
+
480
+ 错误示例:
481
+
482
+ <!-- prettier-ignore -->
483
+ ````js
484
+ console.log("debug");
485
+ ````
486
+
487
+ 正确示例:
488
+
489
+ <!-- prettier-ignore -->
490
+ ````js
491
+ console.warn("retrying");
492
+ console.error(error);
493
+ ````
494
+
495
+ ### `no-constant-condition`
496
+
497
+ 禁止意外的恒定条件,但允许 `while (true)` 等有明确退出逻辑的循环。
498
+
499
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
500
+ - 自动修复:不支持或上游未声明
501
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-constant-condition)
502
+ - 常见报告:`Unexpected constant condition.`
503
+ - 示例类型:仓库显式规则的直接代码示例
504
+
505
+ 错误示例:
506
+
507
+ <!-- prettier-ignore -->
508
+ ````js
509
+ if (true) start();
510
+ ````
511
+
512
+ 正确示例:
513
+
514
+ <!-- prettier-ignore -->
515
+ ````js
516
+ if (ready) start();
517
+ ````
518
+
519
+ ### `no-control-regex`
520
+
521
+ 控制字符通常来自复制或编码错误,要求使用可识别的转义写法。
522
+
523
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
524
+ - 自动修复:不支持或上游未声明
525
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-control-regex)
526
+ - 常见报告:`Unexpected control character(s) in regular expression: {{controlChars}}.`
527
+ - 示例类型:仓库显式规则的直接代码示例
528
+
529
+ 错误示例:
530
+
531
+ <!-- prettier-ignore -->
532
+ ````js
533
+ const separator = /\x00/;
534
+ ````
535
+
536
+ 正确示例:
537
+
538
+ <!-- prettier-ignore -->
539
+ ````js
540
+ const separator = String.fromCharCode(0);
541
+ ````
542
+
543
+ ### `no-debugger`
544
+
545
+ 防止调试断点进入发布代码并中断运行。
546
+
547
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
548
+ - 自动修复:不支持或上游未声明
549
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-debugger)
550
+ - 常见报告:`Unexpected 'debugger' statement.`
551
+ - 示例类型:仓库显式规则的直接代码示例
552
+
553
+ 错误示例:
554
+
555
+ <!-- prettier-ignore -->
556
+ ````js
557
+ debugger;
558
+ start();
559
+ ````
560
+
561
+ 正确示例:
562
+
563
+ <!-- prettier-ignore -->
564
+ ````js
565
+ start();
566
+ ````
567
+
568
+ ### `no-empty`
569
+
570
+ 允许明确表示忽略失败的空 `catch`,其他空代码块视为遗漏。
571
+
572
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
573
+ - 自动修复:不支持或上游未声明
574
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-empty)
575
+ - 常见报告:`Empty {{type}} statement.`;`Add comment inside empty {{type}} statement.`
576
+ - 示例类型:仓库显式规则的直接代码示例
577
+
578
+ 错误示例:
579
+
580
+ <!-- prettier-ignore -->
581
+ ````js
582
+ if (ready) {}
583
+ ````
584
+
585
+ 正确示例:
586
+
587
+ <!-- prettier-ignore -->
588
+ ````js
589
+ try { connect(); } catch {}
590
+ ````
591
+
592
+ ### `no-eval`
593
+
594
+ 禁止动态执行字符串代码,避免代码注入和静态分析失效。
595
+
596
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
597
+ - 自动修复:不支持或上游未声明
598
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-eval)
599
+ - 常见报告:`'eval' can be harmful.`
600
+ - 示例类型:仓库显式规则的直接代码示例
601
+
602
+ 错误示例:
603
+
604
+ <!-- prettier-ignore -->
605
+ ````js
606
+ eval("run()")
607
+ ````
608
+
609
+ 正确示例:
610
+
611
+ <!-- prettier-ignore -->
612
+ ````js
613
+ run()
614
+ ````
615
+
616
+ ### `no-implied-eval`
617
+
618
+ 禁止 `setTimeout`、`setInterval` 等 API 通过字符串间接执行代码。
619
+
620
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
621
+ - 关闭范围:TypeScript 基础、框架无关 TSX、Vue SFC、Vue TSX、UniApp NVue、UniApp TSX、React TSX、Angular TypeScript
622
+ - 自动修复:不支持或上游未声明
623
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-implied-eval)
624
+ - 常见报告:`Implied eval. Consider passing a function instead of a string.`;`Implied eval. Do not use execScript().`
625
+ - 示例类型:仓库显式规则的直接代码示例
626
+
627
+ 错误示例:
628
+
629
+ <!-- prettier-ignore -->
630
+ ````js
631
+ setTimeout("refresh()", 1000);
632
+ ````
633
+
634
+ 正确示例:
635
+
636
+ <!-- prettier-ignore -->
637
+ ````js
638
+ setTimeout(() => refresh(), 1000);
639
+ ````
640
+
641
+ ### `no-irregular-whitespace`
642
+
643
+ 禁止肉眼难以识别、可能导致解析差异的非常规空白字符。
644
+
645
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
646
+ - 自动修复:不支持或上游未声明
647
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-irregular-whitespace)
648
+ - 常见报告:`Irregular whitespace not allowed.`
649
+ - 示例类型:仓库显式规则的直接代码示例
650
+
651
+ 错误示例:
652
+
653
+ <!-- prettier-ignore -->
654
+ ````js
655
+ const value = 1;
656
+ ````
657
+
658
+ 正确示例:
659
+
660
+ <!-- prettier-ignore -->
661
+ ````js
662
+ const value = 1;
663
+ ````
664
+
665
+ ### `no-misleading-character-class`
666
+
667
+ Unicode 组合字符可能让字符类匹配结果与视觉含义不一致。
668
+
669
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
670
+ - 自动修复:不支持或上游未声明
671
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-misleading-character-class)
672
+ - 常见报告:`Unexpected surrogate pair in character class. Use 'u' flag.`;`Unexpected surrogate pair in character class.`;`Unexpected combined character in character class.`
673
+ - 示例类型:仓库显式规则的直接代码示例
674
+
675
+ 错误示例:
676
+
677
+ <!-- prettier-ignore -->
678
+ ````js
679
+ const emoji = /[👍]/;
680
+ ````
681
+
682
+ 正确示例:
683
+
684
+ <!-- prettier-ignore -->
685
+ ````js
686
+ const emoji = /[👍]/u;
687
+ ````
688
+
689
+ ### `no-multi-str`
690
+
691
+ 禁止反斜杠续行字符串,优先使用可读性更好的模板字符串。
692
+
693
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
694
+ - 自动修复:不支持或上游未声明
695
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-multi-str)
696
+ - 常见报告:`Multiline support is limited to browsers supporting ES5 only.`
697
+ - 示例类型:仓库显式规则的直接代码示例
698
+
699
+ 错误示例:
700
+
701
+ <!-- prettier-ignore -->
702
+ ````js
703
+ const message = "first\
704
+ second";
705
+ ````
706
+
707
+ 正确示例:
708
+
709
+ <!-- prettier-ignore -->
710
+ ````js
711
+ const message = "first" +
712
+ "second";
713
+ ````
714
+
715
+ ### `no-new-func`
716
+
717
+ 禁止使用 `Function` 构造器动态编译字符串代码,避免绕过静态分析和安全策略。
718
+
719
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
720
+ - 自动修复:不支持或上游未声明
721
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-new-func)
722
+ - 常见报告:`The Function constructor is eval.`
723
+ - 示例类型:仓库显式规则的直接代码示例
724
+
725
+ 错误示例:
726
+
727
+ <!-- prettier-ignore -->
728
+ ````js
729
+ const add = new Function("left", "right", "return left + right");
730
+ ````
731
+
732
+ 正确示例:
733
+
734
+ <!-- prettier-ignore -->
735
+ ````js
736
+ const add = (left, right) => left + right;
737
+ ````
738
+
739
+ ### `no-promise-executor-return`
740
+
741
+ Promise executor 的返回值会被忽略,禁止误把 `return` 当作 Promise 的解析结果。
742
+
743
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
744
+ - 自动修复:不支持或上游未声明
745
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-promise-executor-return)
746
+ - 常见报告:`Return values from promise executor functions cannot be read.`;`Prepend 'void' to the expression.`;`Wrap the expression in '{}'.`
747
+ - 示例类型:仓库显式规则的直接代码示例
748
+
749
+ 错误示例:
750
+
751
+ <!-- prettier-ignore -->
752
+ ````js
753
+ const value = new Promise((resolve) => resolve(1));
754
+ ````
755
+
756
+ 正确示例:
757
+
758
+ <!-- prettier-ignore -->
759
+ ````js
760
+ const value = new Promise((resolve) => { resolve(1); });
761
+ ````
762
+
763
+ ### `no-redeclare`
764
+
765
+ TypeScript 重载与声明合并由扩展规则识别,关闭会把合法重载误判为重复声明的核心规则。
766
+
767
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
768
+ - 关闭范围:TypeScript 基础、框架无关 TSX、Vue SFC、Vue TSX、UniApp NVue、UniApp TSX、React TSX、Angular TypeScript
769
+ - 自动修复:不支持或上游未声明
770
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-redeclare)
771
+ - 常见报告:`'{{id}}' is already defined.`;`'{{id}}' is already defined as a built-in global variable.`;`'{{id}}' is already defined by a variable declaration.`
772
+ - 示例类型:仓库显式规则的直接代码示例
773
+
774
+ 错误示例:
775
+
776
+ <!-- prettier-ignore -->
777
+ ````js
778
+ var value = 1;
779
+ var value = 2;
780
+ ````
781
+
782
+ 正确示例:
783
+
784
+ <!-- prettier-ignore -->
785
+ ````js
786
+ let value = 1;
787
+ value = 2;
788
+ ````
789
+
790
+ ### `no-regex-spaces`
791
+
792
+ 正则中的连续普通空格容易漏看,使用量词或明确转义更清晰。
793
+
794
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
795
+ - 自动修复:支持;执行前仍应检查语义和差异
796
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-regex-spaces)
797
+ - 常见报告:`Spaces are hard to count. Use {{{length}}}.`
798
+ - 示例类型:仓库显式规则的直接代码示例
799
+
800
+ 错误示例:
801
+
802
+ <!-- prettier-ignore -->
803
+ ````js
804
+ const words = /fast china/;
805
+ ````
806
+
807
+ 正确示例:
808
+
809
+ <!-- prettier-ignore -->
810
+ ````js
811
+ const words = /fast {2}china/;
812
+ ````
813
+
814
+ ### `no-restricted-imports`
815
+
816
+ 禁止混用 `lodash-es` 与 `lodash-unified`,保持运行时和类型来源一致。
817
+
818
+ - 生效级别与范围:error: Lodash、Lodash Unified
819
+ - 自动修复:不支持或上游未声明
820
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-restricted-imports)
821
+ - 常见报告:`'{{importSource}}' import is restricted from being used.`;`'{{importSource}}' import is restricted from being used. {{customMessage}}`;`'{{importSource}}' import is restricted from being used by a pattern.`
822
+ - 示例类型:仓库显式规则的直接代码示例
823
+
824
+ 错误示例:
825
+
826
+ <!-- prettier-ignore -->
827
+ ````js
828
+ import debounce from "lodash-es/debounce";
829
+ ````
830
+
831
+ 正确示例:
832
+
833
+ <!-- prettier-ignore -->
834
+ ````js
835
+ import debounce from "lodash/debounce";
836
+ ````
837
+
838
+ ### `no-restricted-syntax`
839
+
840
+ 禁止标签语句和 `with`,避免难以追踪的跳转与动态标识符解析。
841
+
842
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
843
+ - 自动修复:不支持或上游未声明
844
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-restricted-syntax)
845
+ - 常见报告:`{{message}}`
846
+ - 示例类型:仓库显式规则的直接代码示例
847
+
848
+ 错误示例:
849
+
850
+ <!-- prettier-ignore -->
851
+ ````js
852
+ retryLoop: while (ready) { break retryLoop; }
853
+ ````
854
+
855
+ 正确示例:
856
+
857
+ <!-- prettier-ignore -->
858
+ ````js
859
+ while (ready) { break; }
860
+ ````
861
+
862
+ ### `no-use-before-define`
863
+
864
+ 变量和类先声明后使用;函数声明允许使用 JavaScript 提升语义。
865
+
866
+ - 生效级别与范围:warn: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
867
+ - 自动修复:不支持或上游未声明
868
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-use-before-define)
869
+ - 常见报告:`'{{name}}' was used before it was defined.`
870
+ - 示例类型:仓库显式规则的直接代码示例
871
+
872
+ 错误示例:
873
+
874
+ <!-- prettier-ignore -->
875
+ ````js
876
+ const value = load();
877
+ const load = () => 1;
878
+ ````
879
+
880
+ 正确示例:
881
+
882
+ <!-- prettier-ignore -->
883
+ ````js
884
+ const load = () => 1;
885
+ const value = load();
886
+ ````
887
+
888
+ ### `no-var`
889
+
890
+ 现代项目使用 `let` 或 `const` 替代 `var`,避免函数作用域和循环闭包陷阱。
891
+
892
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
893
+ - 自动修复:支持;执行前仍应检查语义和差异
894
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-var)
895
+ - 常见报告:`Unexpected var, use let or const instead.`
896
+ - 示例类型:仓库显式规则的直接代码示例
897
+
898
+ 错误示例:
899
+
900
+ <!-- prettier-ignore -->
901
+ ````js
902
+ var count = 1;
903
+ ````
904
+
905
+ 正确示例:
906
+
907
+ <!-- prettier-ignore -->
908
+ ````js
909
+ let count = 1;
910
+ const limit = 10;
911
+ ````
912
+
913
+ ### `no-void`
914
+
915
+ 单独组合 `createTypeScriptConfigs()` 时也禁止用 `void` 操作符标记被忽略的 Promise。
916
+
917
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
918
+ - 自动修复:不支持或上游未声明
919
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-void)
920
+ - 常见报告:`Expected 'undefined' and instead saw 'void'.`
921
+ - 示例类型:仓库显式规则的直接代码示例
922
+
923
+ 错误示例:
924
+
925
+ <!-- prettier-ignore -->
926
+ ````ts
927
+ void save();
928
+ ````
929
+
930
+ 正确示例:
931
+
932
+ <!-- prettier-ignore -->
933
+ ````ts
934
+ save();
935
+ ````
936
+
937
+ ### `no-with`
938
+
939
+ `with` 会让标识符解析不可预测,并且在严格模式和 ESM 中不可用。
940
+
941
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
942
+ - 关闭范围:TypeScript 基础、框架无关 TSX、Vue SFC、Vue TSX、UniApp NVue、UniApp TSX、React TSX、Angular TypeScript
943
+ - 自动修复:不支持或上游未声明
944
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-with)
945
+ - 常见报告:`Unexpected use of 'with' statement.`
946
+ - 示例类型:仓库显式规则的直接代码示例
947
+
948
+ 错误示例:
949
+
950
+ <!-- prettier-ignore -->
951
+ ````js
952
+ with (settings) { apply(theme); }
953
+ ````
954
+
955
+ 正确示例:
956
+
957
+ <!-- prettier-ignore -->
958
+ ````js
959
+ apply(settings.theme);
960
+ ````
961
+
962
+ ### `object-shorthand`
963
+
964
+ 属性和值同名时强制使用对象简写,带引号键名不强制改写。
965
+
966
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
967
+ - 自动修复:支持;执行前仍应检查语义和差异
968
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/object-shorthand)
969
+ - 常见报告:`Expected shorthand for all properties.`;`Expected longform method syntax for string literal keys.`;`Expected property shorthand.`
970
+ - 示例类型:仓库显式规则的直接代码示例
971
+
972
+ 错误示例:
973
+
974
+ <!-- prettier-ignore -->
975
+ ````js
976
+ const timeout = 1000;
977
+ const options = { timeout: timeout };
978
+ ````
979
+
980
+ 正确示例:
981
+
982
+ <!-- prettier-ignore -->
983
+ ````js
984
+ const timeout = 1000;
985
+ const options = { timeout };
986
+ ````
987
+
988
+ ### `prefer-arrow-callback`
989
+
990
+ 不依赖动态 `this` 的回调使用箭头函数;允许确实需要调用方绑定 `this` 的普通函数。
991
+
992
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
993
+ - 自动修复:支持;执行前仍应检查语义和差异
994
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-arrow-callback)
995
+ - 常见报告:`Unexpected function expression.`
996
+ - 示例类型:仓库显式规则的直接代码示例
997
+
998
+ 错误示例:
999
+
1000
+ <!-- prettier-ignore -->
1001
+ ````js
1002
+ items.map(function (item) { return item.id; });
1003
+ ````
1004
+
1005
+ 正确示例:
1006
+
1007
+ <!-- prettier-ignore -->
1008
+ ````js
1009
+ items.map((item) => item.id);
1010
+ ````
1011
+
1012
+ ### `prefer-const`
1013
+
1014
+ 能保持引用不变的变量优先使用 `const`;读取发生在赋值前时不做不可靠判断。
1015
+
1016
+ - 生效级别与范围:warn: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1017
+ - 自动修复:支持;执行前仍应检查语义和差异
1018
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-const)
1019
+ - 常见报告:`'{{name}}' is never reassigned. Use 'const' instead.`
1020
+ - 示例类型:仓库显式规则的直接代码示例
1021
+
1022
+ 错误示例:
1023
+
1024
+ <!-- prettier-ignore -->
1025
+ ````js
1026
+ let timeout = 3000;
1027
+ ````
1028
+
1029
+ 正确示例:
1030
+
1031
+ <!-- prettier-ignore -->
1032
+ ````js
1033
+ const timeout = 3000;
1034
+ ````
1035
+
1036
+ ### `prefer-exponentiation-operator`
1037
+
1038
+ 使用幂运算符代替 `Math.pow`,使数学表达式更直接。
1039
+
1040
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1041
+ - 自动修复:支持;执行前仍应检查语义和差异
1042
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-exponentiation-operator)
1043
+ - 常见报告:`Use the '**' operator instead of 'Math.pow'.`
1044
+ - 示例类型:仓库显式规则的直接代码示例
1045
+
1046
+ 错误示例:
1047
+
1048
+ <!-- prettier-ignore -->
1049
+ ````js
1050
+ const area = Math.pow(size, 2);
1051
+ ````
1052
+
1053
+ 正确示例:
1054
+
1055
+ <!-- prettier-ignore -->
1056
+ ````js
1057
+ const area = size ** 2;
1058
+ ````
1059
+
1060
+ ### `prefer-object-spread`
1061
+
1062
+ 创建新对象时用对象展开代替 `Object.assign({}, source)`,不改写会修改既有目标对象的调用。
1063
+
1064
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1065
+ - 自动修复:支持;执行前仍应检查语义和差异
1066
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-object-spread)
1067
+ - 常见报告:`Use an object spread instead of 'Object.assign' eg: '{ ...foo }'.`;`Use an object literal instead of 'Object.assign'. eg: '{ foo: bar }'.`
1068
+ - 示例类型:仓库显式规则的直接代码示例
1069
+
1070
+ 错误示例:
1071
+
1072
+ <!-- prettier-ignore -->
1073
+ ````js
1074
+ const next = Object.assign({}, current, patch);
1075
+ ````
1076
+
1077
+ 正确示例:
1078
+
1079
+ <!-- prettier-ignore -->
1080
+ ````js
1081
+ const next = { ...current, ...patch };
1082
+ ````
1083
+
1084
+ ### `prefer-rest-params`
1085
+
1086
+ 使用具名 rest 参数代替 `arguments`,使参数范围明确并获得真实数组和类型推断能力。
1087
+
1088
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1089
+ - 自动修复:不支持或上游未声明
1090
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-rest-params)
1091
+ - 常见报告:`Use the rest parameters instead of 'arguments'.`
1092
+ - 示例类型:仓库显式规则的直接代码示例
1093
+
1094
+ 错误示例:
1095
+
1096
+ <!-- prettier-ignore -->
1097
+ ````js
1098
+ function join() { return Array.from(arguments).join(","); }
1099
+ ````
1100
+
1101
+ 正确示例:
1102
+
1103
+ <!-- prettier-ignore -->
1104
+ ````js
1105
+ function join(...values) { return values.join(","); }
1106
+ ````
1107
+
1108
+ ### `prefer-spread`
1109
+
1110
+ 参数数组展开调用时使用 `fn(...args)` 代替 `fn.apply(thisArg, args)`,使调用目标和参数更直观。
1111
+
1112
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1113
+ - 自动修复:不支持或上游未声明
1114
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-spread)
1115
+ - 常见报告:`Use the spread operator instead of '.apply()'.`
1116
+ - 示例类型:仓库显式规则的直接代码示例
1117
+
1118
+ 错误示例:
1119
+
1120
+ <!-- prettier-ignore -->
1121
+ ````js
1122
+ items.push.apply(items, nextItems);
1123
+ ````
1124
+
1125
+ 正确示例:
1126
+
1127
+ <!-- prettier-ignore -->
1128
+ ````js
1129
+ items.push(...nextItems);
1130
+ ````
1131
+
1132
+ ### `prefer-template`
1133
+
1134
+ 字符串中包含变量时使用模板字符串,减少多段 `+` 拼接和隐式类型转换造成的歧义。
1135
+
1136
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1137
+ - 自动修复:支持;执行前仍应检查语义和差异
1138
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/prefer-template)
1139
+ - 常见报告:`Unexpected string concatenation.`
1140
+ - 示例类型:仓库显式规则的直接代码示例
1141
+
1142
+ 错误示例:
1143
+
1144
+ <!-- prettier-ignore -->
1145
+ ````js
1146
+ const name = "Fast";
1147
+ const message = "Hello, " + name + "!";
1148
+ ````
1149
+
1150
+ 正确示例:
1151
+
1152
+ <!-- prettier-ignore -->
1153
+ ````js
1154
+ const name = "Fast";
1155
+ const message = `Hello, ${name}!`;
1156
+ ````
1157
+
1158
+ ### `regexp/confusing-quantifier`
1159
+
1160
+ 相邻量词的作用范围容易被误读,保留警告供人工复核。
1161
+
1162
+ - 生效级别与范围:warn: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1163
+ - 自动修复:不支持或上游未声明
1164
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/confusing-quantifier.html)
1165
+ - 常见报告:`This quantifier is confusing because its minimum is {{min}} but it can match the empty string. Maybe replace it with '{{proposal}}' to reflect that it can match the empty string?`
1166
+ - 示例类型:仓库显式规则的直接代码示例
1167
+
1168
+ 错误示例:
1169
+
1170
+ <!-- prettier-ignore -->
1171
+ ````js
1172
+ const pattern = /(?:a*)+/;
1173
+ ````
1174
+
1175
+ 正确示例:
1176
+
1177
+ <!-- prettier-ignore -->
1178
+ ````js
1179
+ const pattern = /a*/;
1180
+ ````
1181
+
1182
+ ### `regexp/no-contradiction-with-assertion`
1183
+
1184
+ 断言与其内部条件矛盾时表达式永远无法按预期匹配。
1185
+
1186
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1187
+ - 自动修复:不支持或上游未声明
1188
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-contradiction-with-assertion.html)
1189
+ - 常见报告:`The alternative {{ alt }} can never be entered because it contradicts with the assertion {{ assertion }}. Either change the alternative or assertion to resolve the contradiction.`;`The quantifier {{ quant }} can never be entered because its element contradicts with the assertion {{ assertion }}. Change or remove the quantifier or change the assertion to resolve the contradiction.`;`The quantifier {{ quant }} is always entered despite having a minimum of 0. This is because the assertion {{ assertion }} contradicts with the element(s) after the quantifier. Either set the minimum to 1 ({{ newQuant }}) or change the assertion.`
1190
+ - 示例类型:仓库显式规则的直接代码示例
1191
+
1192
+ 错误示例:
1193
+
1194
+ <!-- prettier-ignore -->
1195
+ ````js
1196
+ const pattern = /(?=a)b*/;
1197
+ ````
1198
+
1199
+ 正确示例:
1200
+
1201
+ <!-- prettier-ignore -->
1202
+ ````js
1203
+ const pattern = /(?=a)a+/;
1204
+ ````
1205
+
1206
+ ### `regexp/no-dupe-characters-character-class`
1207
+
1208
+ 字符类中的重复字符通常表示拼写或范围设计错误。
1209
+
1210
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1211
+ - 自动修复:支持;执行前仍应检查语义和差异
1212
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-dupe-characters-character-class.html)
1213
+ - 常见报告:`Unexpected duplicate {{duplicate}}.`;`Unexpected duplicate. {{duplicate}} is a duplicate of {{element}}.`;`{{subsetElement}} is already included in {{element}}.`
1214
+ - 示例类型:仓库显式规则的直接代码示例
1215
+
1216
+ 错误示例:
1217
+
1218
+ <!-- prettier-ignore -->
1219
+ ````js
1220
+ const pattern = /[aa-z]/;
1221
+ ````
1222
+
1223
+ 正确示例:
1224
+
1225
+ <!-- prettier-ignore -->
1226
+ ````js
1227
+ const pattern = /[a-z]/;
1228
+ ````
1229
+
1230
+ ### `regexp/no-dupe-disjunctions`
1231
+
1232
+ 重复或被完全覆盖的分支通常表示条件遗漏。
1233
+
1234
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1235
+ - 自动修复:不支持或上游未声明
1236
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-dupe-disjunctions.html)
1237
+ - 常见报告:`Unexpected duplicate alternative. This alternative can be removed.{{cap}}{{exp}}`;`Unexpected useless alternative. This alternative is a strict subset of {{others}} and can be removed.{{cap}}{{exp}}`;`Unexpected useless element. All paths of {{root}} that go through {{nested}} are a strict subset of {{others}}. This element can be removed.{{cap}}{{exp}}`
1238
+ - 示例类型:仓库显式规则的直接代码示例
1239
+
1240
+ 错误示例:
1241
+
1242
+ <!-- prettier-ignore -->
1243
+ ````js
1244
+ const pattern = /(?:fast|fast)/;
1245
+ ````
1246
+
1247
+ 正确示例:
1248
+
1249
+ <!-- prettier-ignore -->
1250
+ ````js
1251
+ const pattern = /(?:fast|slow)/;
1252
+ ````
1253
+
1254
+ ### `regexp/no-empty-alternative`
1255
+
1256
+ 空分支可能是有意匹配空字符串,也可能是遗漏,因此只警告。
1257
+
1258
+ - 生效级别与范围:warn: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1259
+ - 自动修复:不支持或上游未声明
1260
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-alternative.html)
1261
+ - 常见报告:`This empty alternative might be a mistake. If not, use a quantifier instead.`;`Use a quantifier instead.`
1262
+ - 示例类型:仓库显式规则的直接代码示例
1263
+
1264
+ 错误示例:
1265
+
1266
+ <!-- prettier-ignore -->
1267
+ ````js
1268
+ const pattern = /(?:fast|)/;
1269
+ ````
1270
+
1271
+ 正确示例:
1272
+
1273
+ <!-- prettier-ignore -->
1274
+ ````js
1275
+ const pattern = /(?:fast|slow)/;
1276
+ ````
1277
+
1278
+ ### `regexp/no-empty-capturing-group`
1279
+
1280
+ 空捕获组不会捕获有效内容,通常属于表达式残留。
1281
+
1282
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1283
+ - 自动修复:不支持或上游未声明
1284
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-capturing-group.html)
1285
+ - 常见报告:`Unexpected capture empty.`
1286
+ - 示例类型:仓库显式规则的直接代码示例
1287
+
1288
+ 错误示例:
1289
+
1290
+ <!-- prettier-ignore -->
1291
+ ````js
1292
+ const pattern = /()/;
1293
+ ````
1294
+
1295
+ 正确示例:
1296
+
1297
+ <!-- prettier-ignore -->
1298
+ ````js
1299
+ const pattern = /(fast)/;
1300
+ ````
1301
+
1302
+ ### `regexp/no-empty-character-class`
1303
+
1304
+ 空字符类永远无法匹配字符。
1305
+
1306
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1307
+ - 自动修复:不支持或上游未声明
1308
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-character-class.html)
1309
+ - 常见报告:`This character class matches no characters because it is empty.`;`This character class cannot match any characters.`
1310
+ - 示例类型:仓库显式规则的直接代码示例
1311
+
1312
+ 错误示例:
1313
+
1314
+ <!-- prettier-ignore -->
1315
+ ````js
1316
+ const pattern = /[]/;
1317
+ ````
1318
+
1319
+ 正确示例:
1320
+
1321
+ <!-- prettier-ignore -->
1322
+ ````js
1323
+ const pattern = /[a-z]/;
1324
+ ````
1325
+
1326
+ ### `regexp/no-empty-group`
1327
+
1328
+ 空分组通常表示编辑遗漏。
1329
+
1330
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1331
+ - 自动修复:不支持或上游未声明
1332
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-group.html)
1333
+ - 常见报告:`Unexpected empty group.`
1334
+ - 示例类型:仓库显式规则的直接代码示例
1335
+
1336
+ 错误示例:
1337
+
1338
+ <!-- prettier-ignore -->
1339
+ ````js
1340
+ const pattern = /(?:)/;
1341
+ ````
1342
+
1343
+ 正确示例:
1344
+
1345
+ <!-- prettier-ignore -->
1346
+ ````js
1347
+ const pattern = /(?:fast)/;
1348
+ ````
1349
+
1350
+ ### `regexp/no-empty-lookarounds-assertion`
1351
+
1352
+ 空前后查找不会表达有效约束。
1353
+
1354
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1355
+ - 自动修复:不支持或上游未声明
1356
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-empty-lookarounds-assertion.html)
1357
+ - 常见报告:`Unexpected empty {{kind}}. It will trivially {{result}} all inputs.`
1358
+ - 示例类型:仓库显式规则的直接代码示例
1359
+
1360
+ 错误示例:
1361
+
1362
+ <!-- prettier-ignore -->
1363
+ ````js
1364
+ const pattern = /(?=)fast/;
1365
+ ````
1366
+
1367
+ 正确示例:
1368
+
1369
+ <!-- prettier-ignore -->
1370
+ ````js
1371
+ const pattern = /(?=fast)fast/;
1372
+ ````
1373
+
1374
+ ### `regexp/no-extra-lookaround-assertions`
1375
+
1376
+ 多余嵌套断言可能改变捕获或回溯边界,应视为结构错误。
1377
+
1378
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1379
+ - 自动修复:支持;执行前仍应检查语义和差异
1380
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-extra-lookaround-assertions.html)
1381
+ - 常见报告:`This {{kind}} assertion is useless and can be inlined.`;`This {{kind}} assertion is useless and can be converted into a group.`
1382
+ - 示例类型:仓库显式规则的直接代码示例
1383
+
1384
+ 错误示例:
1385
+
1386
+ <!-- prettier-ignore -->
1387
+ ````js
1388
+ const pattern = /(?=(?=fast))fast/;
1389
+ ````
1390
+
1391
+ 正确示例:
1392
+
1393
+ <!-- prettier-ignore -->
1394
+ ````js
1395
+ const pattern = /(?=fast)fast/;
1396
+ ````
1397
+
1398
+ ### `regexp/no-invalid-regexp`
1399
+
1400
+ 检查 `RegExp` 构造器字符串和字面量中的无效语法及标志。
1401
+
1402
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1403
+ - 自动修复:不支持或上游未声明
1404
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invalid-regexp.html)
1405
+ - 常见报告:`{{message}}`;`Duplicate {{flag}} flag.`;`Regex 'u' and 'v' flags cannot be used together.`
1406
+ - 示例类型:仓库显式规则的直接代码示例
1407
+
1408
+ 错误示例:
1409
+
1410
+ <!-- prettier-ignore -->
1411
+ ````js
1412
+ const pattern = new RegExp("[");
1413
+ ````
1414
+
1415
+ 正确示例:
1416
+
1417
+ <!-- prettier-ignore -->
1418
+ ````js
1419
+ const pattern = new RegExp("[a-z]");
1420
+ ````
1421
+
1422
+ ### `regexp/no-invisible-character`
1423
+
1424
+ 不可见字符容易造成审查遗漏和匹配异常。
1425
+
1426
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1427
+ - 自动修复:支持;执行前仍应检查语义和差异
1428
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-invisible-character.html)
1429
+ - 常见报告:`Unexpected invisible character. Use '{{instead}}' instead.`
1430
+ - 示例类型:仓库显式规则的直接代码示例
1431
+
1432
+ 错误示例:
1433
+
1434
+ <!-- prettier-ignore -->
1435
+ ````js
1436
+ const pattern = /​/u;
1437
+ ````
1438
+
1439
+ 正确示例:
1440
+
1441
+ <!-- prettier-ignore -->
1442
+ ````js
1443
+ const pattern = /\u200B/u;
1444
+ ````
1445
+
1446
+ ### `regexp/no-misleading-capturing-group`
1447
+
1448
+ 捕获组边界具有误导性时,反向引用和替换结果可能不符合预期。
1449
+
1450
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1451
+ - 自动修复:不支持或上游未声明
1452
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-misleading-capturing-group.html)
1453
+ - 常见报告:`{{quant}} can be removed because it is already included by {{cause}}. This makes the capturing group misleading, because it actually captures less text than its pattern suggests.`;`{{quant}} can be replaced with {{fix}} because of {{cause}}. This makes the capturing group misleading, because it actually captures less text than its pattern suggests.`;`Remove {{quant}}.`
1454
+ - 示例类型:仓库显式规则的直接代码示例
1455
+
1456
+ 错误示例:
1457
+
1458
+ <!-- prettier-ignore -->
1459
+ ````js
1460
+ const pattern = /(a+)+/;
1461
+ ````
1462
+
1463
+ 正确示例:
1464
+
1465
+ <!-- prettier-ignore -->
1466
+ ````js
1467
+ const pattern = /a+/;
1468
+ ````
1469
+
1470
+ ### `regexp/no-misleading-unicode-character`
1471
+
1472
+ Unicode 字符的视觉形式与代码点不一致时容易产生错误匹配。
1473
+
1474
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1475
+ - 自动修复:支持;执行前仍应检查语义和差异
1476
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-misleading-unicode-character.html)
1477
+ - 常见报告:`The character(s) {{ graphemes }} are all represented using multiple {{ unit }}.{{ uFlag }}`;`The character {{ grapheme }} is represented using multiple Unicode code points. The quantifier only applies to the last code point {{ last }} and not to the whole character.`;`The character {{ grapheme }} is represented using a surrogate pair. The quantifier only applies to the tailing surrogate {{ last }} and not to the whole character.`
1478
+ - 示例类型:仓库显式规则的直接代码示例
1479
+
1480
+ 错误示例:
1481
+
1482
+ <!-- prettier-ignore -->
1483
+ ````js
1484
+ const pattern = /[👍]/;
1485
+ ````
1486
+
1487
+ 正确示例:
1488
+
1489
+ <!-- prettier-ignore -->
1490
+ ````js
1491
+ const pattern = /[👍]/u;
1492
+ ````
1493
+
1494
+ ### `regexp/no-missing-g-flag`
1495
+
1496
+ `replaceAll` 等全局操作缺少 `g` 标志时会在运行时失败或行为不一致。
1497
+
1498
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1499
+ - 自动修复:支持;执行前仍应检查语义和差异
1500
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-missing-g-flag.html)
1501
+ - 常见报告:`The pattern given to the argument of 'String#{{method}}()' requires the 'g' flag, but is missing it.`
1502
+ - 示例类型:仓库显式规则的直接代码示例
1503
+
1504
+ 错误示例:
1505
+
1506
+ <!-- prettier-ignore -->
1507
+ ````js
1508
+ const text = "item item";
1509
+ const matches = text.matchAll(/item/);
1510
+ ````
1511
+
1512
+ 正确示例:
1513
+
1514
+ <!-- prettier-ignore -->
1515
+ ````js
1516
+ const text = "item item";
1517
+ const matches = text.matchAll(/item/g);
1518
+ ````
1519
+
1520
+ ### `regexp/no-non-standard-flag`
1521
+
1522
+ 禁止 JavaScript 不支持的非标准正则标志。
1523
+
1524
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1525
+ - 自动修复:不支持或上游未声明
1526
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-non-standard-flag.html)
1527
+ - 常见报告:`Unexpected non-standard flag '{{flag}}'.`
1528
+ - 示例类型:仓库显式规则的直接代码示例
1529
+
1530
+ 错误示例:
1531
+
1532
+ <!-- prettier-ignore -->
1533
+ ````js
1534
+ const pattern = new RegExp("item", "x");
1535
+ ````
1536
+
1537
+ 正确示例:
1538
+
1539
+ <!-- prettier-ignore -->
1540
+ ````js
1541
+ const pattern = new RegExp("item", "u");
1542
+ ````
1543
+
1544
+ ### `regexp/no-optional-assertion`
1545
+
1546
+ 可选断言几乎总能通过,通常无法表达预期约束。
1547
+
1548
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1549
+ - 自动修复:不支持或上游未声明
1550
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-optional-assertion.html)
1551
+ - 常见报告:`This assertion effectively optional and does not change the pattern. Either remove the assertion or change the parent quantifier '{{quantifier}}'.`
1552
+ - 示例类型:仓库显式规则的直接代码示例
1553
+
1554
+ 错误示例:
1555
+
1556
+ <!-- prettier-ignore -->
1557
+ ````js
1558
+ const pattern = /(?:^)?item/;
1559
+ ````
1560
+
1561
+ 正确示例:
1562
+
1563
+ <!-- prettier-ignore -->
1564
+ ````js
1565
+ const pattern = /^item/;
1566
+ ````
1567
+
1568
+ ### `regexp/no-super-linear-backtracking`
1569
+
1570
+ 阻止可被构造输入触发的超线性回溯,降低拒绝服务风险。
1571
+
1572
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1573
+ - 自动修复:支持;执行前仍应检查语义和差异
1574
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-super-linear-backtracking.html)
1575
+ - 常见报告:`This quantifier can reach itself via the loop {{parent}}. Using any string accepted by {{attack}}, this can be exploited to cause at least polynomial backtracking.{{exp}}`;`The quantifier {{start}} can exchange characters with {{end}}. Using any string accepted by {{attack}}, this can be exploited to cause at least polynomial backtracking.{{exp}}`
1576
+ - 示例类型:仓库显式规则的直接代码示例
1577
+
1578
+ 错误示例:
1579
+
1580
+ <!-- prettier-ignore -->
1581
+ ````js
1582
+ const pattern = /(a+)+$/;
1583
+ ````
1584
+
1585
+ 正确示例:
1586
+
1587
+ <!-- prettier-ignore -->
1588
+ ````js
1589
+ const pattern = /^a+$/;
1590
+ ````
1591
+
1592
+ ### `regexp/no-useless-backreference`
1593
+
1594
+ 无效反向引用无法引用预期捕获内容。
1595
+
1596
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1597
+ - 自动修复:不支持或上游未声明
1598
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-backreference.html)
1599
+ - 常见报告:`Backreference {{ bref }} will be ignored. It references group {{ group }}{{ otherGroups }} from within that group.`;`Backreference {{ bref }} will be ignored. It references group {{ group }}{{ otherGroups }} which appears later in the pattern.`;`Backreference {{ bref }} will be ignored. It references group {{ group }}{{ otherGroups }} which appears before in the same lookbehind.`
1600
+ - 示例类型:仓库显式规则的直接代码示例
1601
+
1602
+ 错误示例:
1603
+
1604
+ <!-- prettier-ignore -->
1605
+ ````js
1606
+ const pattern = /\1(a)/;
1607
+ ````
1608
+
1609
+ 正确示例:
1610
+
1611
+ <!-- prettier-ignore -->
1612
+ ````js
1613
+ const pattern = /(a)\1/;
1614
+ ````
1615
+
1616
+ ### `regexp/no-useless-dollar-replacements`
1617
+
1618
+ 替换字符串引用不存在的捕获组时不会得到预期结果。
1619
+
1620
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1621
+ - 自动修复:不支持或上游未声明
1622
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-useless-dollar-replacements.html)
1623
+ - 常见报告:`'${{ refText }}' replacement will insert '${{ refText }}' because there are less than {{ num }} capturing groups. Use '$$' if you want to escape '$'.`;`'${{ refText }}' replacement will insert '${{ refText }}' because capturing group is not found. Use '$$' if you want to escape '$'.`;`'$<{{ refText }}>' replacement will be ignored because the named capturing group is not found. Use '$$' if you want to escape '$'.`
1624
+ - 示例类型:仓库显式规则的直接代码示例
1625
+
1626
+ 错误示例:
1627
+
1628
+ <!-- prettier-ignore -->
1629
+ ````js
1630
+ const text = "item";
1631
+ const value = text.replace(/item/g, "$1");
1632
+ ````
1633
+
1634
+ 正确示例:
1635
+
1636
+ <!-- prettier-ignore -->
1637
+ ````js
1638
+ const text = "item";
1639
+ const value = text.replace(/(item)/g, "$1");
1640
+ ````
1641
+
1642
+ ### `regexp/no-zero-quantifier`
1643
+
1644
+ 零次量词会让对应模式永远不参与匹配,通常是边界笔误。
1645
+
1646
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1647
+ - 自动修复:不支持或上游未声明
1648
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/no-zero-quantifier.html)
1649
+ - 常见报告:`Unexpected zero quantifier. The quantifier and its quantified element can be removed without affecting the pattern.`;`Unexpected zero quantifier. The quantifier and its quantified element do not affecting the pattern. Try to remove the elements but be careful because it contains at least one capturing group.`;`Remove this zero quantifier.`
1650
+ - 示例类型:仓库显式规则的直接代码示例
1651
+
1652
+ 错误示例:
1653
+
1654
+ <!-- prettier-ignore -->
1655
+ ````js
1656
+ const pattern = /item{0}/;
1657
+ ````
1658
+
1659
+ 正确示例:
1660
+
1661
+ <!-- prettier-ignore -->
1662
+ ````js
1663
+ const pattern = /item/;
1664
+ ````
1665
+
1666
+ ### `regexp/strict`
1667
+
1668
+ 使用严格模式检查容易产生歧义或跨引擎差异的正则结构。
1669
+
1670
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1671
+ - 自动修复:支持;执行前仍应检查语义和差异
1672
+ - 规则来源:[官方文档](https://ota-meshi.github.io/eslint-plugin-regexp/rules/strict.html)
1673
+ - 常见报告:`Invalid or incomplete control escape sequence. Either use a valid control escape sequence or escaping the standalone backslash.`;`Incomplete escape sequence {{expr}}. Either use a valid escape sequence or remove the useless escaping.`;`Invalid property escape sequence {{expr}}. Either use a valid property escape sequence or remove the useless escaping.`
1674
+ - 示例类型:仓库显式规则的直接代码示例
1675
+
1676
+ 错误示例:
1677
+
1678
+ <!-- prettier-ignore -->
1679
+ ````js
1680
+ const pattern = /\q/;
1681
+ ````
1682
+
1683
+ 正确示例:
1684
+
1685
+ <!-- prettier-ignore -->
1686
+ ````js
1687
+ const pattern = /q/;
1688
+ ````
1689
+
1690
+ ### `sort-imports`
1691
+
1692
+ `import` 声明内部的成员按名称排序;声明之间的分组和顺序交给 `import-x/order`。
1693
+
1694
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1695
+ - 自动修复:支持;执行前仍应检查语义和差异
1696
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/sort-imports)
1697
+ - 常见报告:`Imports should be sorted alphabetically.`;`Member '{{memberName}}' of the import declaration should be sorted alphabetically.`;`Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax.`
1698
+ - 示例类型:仓库显式规则的直接代码示例
1699
+
1700
+ 错误示例:
1701
+
1702
+ <!-- prettier-ignore -->
1703
+ ````ts
1704
+ import { zebra, alpha } from "./names";
1705
+ ````
1706
+
1707
+ 正确示例:
1708
+
1709
+ <!-- prettier-ignore -->
1710
+ ````ts
1711
+ import { alpha, zebra } from "./names";
1712
+ ````
1713
+
1714
+ ## 第三方预置规则(54 条)
1715
+
1716
+ ### `constructor-super`
1717
+
1718
+ 检查该规则对应的代码约束。上游说明:Require `super()` calls in constructors
1719
+
1720
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
1721
+ - 自动修复:不支持或上游未声明
1722
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/constructor-super)
1723
+ - 常见报告:`Lacked a call of 'super()' in some code paths.`;`Expected to call 'super()'.`;`Unexpected duplicate 'super()'.`
1724
+ - 示例类型:第三方预置规则的直接代码示例
1725
+
1726
+ 错误示例:
1727
+
1728
+ <!-- prettier-ignore -->
1729
+ ````js
1730
+ class User extends Entity { constructor() {} }
1731
+ ````
1732
+
1733
+ 正确示例:
1734
+
1735
+ <!-- prettier-ignore -->
1736
+ ````js
1737
+ class User extends Entity { constructor() { super(); } }
1738
+ ````
1739
+
1740
+ ### `for-direction`
1741
+
1742
+ 检查该规则对应的代码约束。上游说明:Enforce `for` loop update clause moving the counter in the right direction
1743
+
1744
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1745
+ - 自动修复:不支持或上游未声明
1746
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/for-direction)
1747
+ - 常见报告:`The update clause in this loop moves the variable in the wrong direction.`
1748
+ - 示例类型:第三方预置规则的直接代码示例
1749
+
1750
+ 错误示例:
1751
+
1752
+ <!-- prettier-ignore -->
1753
+ ````js
1754
+ for (let index = 0; index < 10; index--) process(index);
1755
+ ````
1756
+
1757
+ 正确示例:
1758
+
1759
+ <!-- prettier-ignore -->
1760
+ ````js
1761
+ for (let index = 0; index < 10; index++) process(index);
1762
+ ````
1763
+
1764
+ ### `getter-return`
1765
+
1766
+ 检查该规则对应的代码约束。上游说明:Enforce `return` statements in getters
1767
+
1768
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
1769
+ - 自动修复:不支持或上游未声明
1770
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/getter-return)
1771
+ - 常见报告:`Expected to return a value in {{name}}.`;`Expected {{name}} to always return a value.`
1772
+ - 示例类型:第三方预置规则的直接代码示例
1773
+
1774
+ 错误示例:
1775
+
1776
+ <!-- prettier-ignore -->
1777
+ ````js
1778
+ const user = { get name() { logAccess(); } };
1779
+ ````
1780
+
1781
+ 正确示例:
1782
+
1783
+ <!-- prettier-ignore -->
1784
+ ````js
1785
+ const user = { get name() { return "Fast"; } };
1786
+ ````
1787
+
1788
+ ### `import-x/export`
1789
+
1790
+ 检查该规则对应的代码约束。上游说明:Forbid any invalid exports, i.e. re-export of the same name.
1791
+
1792
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1793
+ - 自动修复:不支持或上游未声明
1794
+ - 规则来源:[官方文档](https://github.com/un-ts/eslint-plugin-import-x/blob/v4.17.1/docs/rules/export.md)
1795
+ - 常见报告:`No named exports found in module '{{module}}'.`;`Multiple default exports.`;`Multiple exports of name '{{name}}'.`
1796
+ - 示例类型:第三方预置规则的直接代码示例
1797
+
1798
+ 错误示例:
1799
+
1800
+ <!-- prettier-ignore -->
1801
+ ````js
1802
+ export const value = 1;
1803
+ export { value };
1804
+ ````
1805
+
1806
+ 正确示例:
1807
+
1808
+ <!-- prettier-ignore -->
1809
+ ````js
1810
+ export const value = 1;
1811
+ ````
1812
+
1813
+ ### `no-async-promise-executor`
1814
+
1815
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow using an async function as a Promise executor
1816
+
1817
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1818
+ - 自动修复:不支持或上游未声明
1819
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-async-promise-executor)
1820
+ - 常见报告:`Promise executor functions should not be async.`
1821
+ - 示例类型:第三方预置规则的直接代码示例
1822
+
1823
+ 错误示例:
1824
+
1825
+ <!-- prettier-ignore -->
1826
+ ````js
1827
+ const value = new Promise(async (resolve) => resolve(await load()));
1828
+ ````
1829
+
1830
+ 正确示例:
1831
+
1832
+ <!-- prettier-ignore -->
1833
+ ````js
1834
+ const value = Promise.resolve(load());
1835
+ ````
1836
+
1837
+ ### `no-class-assign`
1838
+
1839
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow reassigning class members
1840
+
1841
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
1842
+ - 自动修复:不支持或上游未声明
1843
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-class-assign)
1844
+ - 常见报告:`'{{name}}' is a class.`
1845
+ - 示例类型:第三方预置规则的直接代码示例
1846
+
1847
+ 错误示例:
1848
+
1849
+ <!-- prettier-ignore -->
1850
+ ````js
1851
+ class User {}
1852
+ User = class Admin {};
1853
+ ````
1854
+
1855
+ 正确示例:
1856
+
1857
+ <!-- prettier-ignore -->
1858
+ ````js
1859
+ class User {}
1860
+ const Admin = class extends User {};
1861
+ ````
1862
+
1863
+ ### `no-compare-neg-zero`
1864
+
1865
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow comparing against `-0`
1866
+
1867
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1868
+ - 自动修复:不支持或上游未声明
1869
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-compare-neg-zero)
1870
+ - 常见报告:`Do not use the '{{operator}}' operator to compare against -0.`;`Replace '-0' with '0' (keeps the current comparison behavior).`;`Replace with 'Object.is()' (changes the comparison to distinguish -0 from +0).`
1871
+ - 示例类型:第三方预置规则的直接代码示例
1872
+
1873
+ 错误示例:
1874
+
1875
+ <!-- prettier-ignore -->
1876
+ ````js
1877
+ if (value === -0) handle();
1878
+ ````
1879
+
1880
+ 正确示例:
1881
+
1882
+ <!-- prettier-ignore -->
1883
+ ````js
1884
+ if (Object.is(value, -0)) handle();
1885
+ ````
1886
+
1887
+ ### `no-cond-assign`
1888
+
1889
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow assignment operators in conditional expressions
1890
+
1891
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1892
+ - 自动修复:不支持或上游未声明
1893
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-cond-assign)
1894
+ - 常见报告:`Unexpected assignment within {{type}}.`;`Expected a conditional expression and instead saw an assignment.`
1895
+ - 示例类型:第三方预置规则的直接代码示例
1896
+
1897
+ 错误示例:
1898
+
1899
+ <!-- prettier-ignore -->
1900
+ ````js
1901
+ if (user = findUser()) render(user);
1902
+ ````
1903
+
1904
+ 正确示例:
1905
+
1906
+ <!-- prettier-ignore -->
1907
+ ````js
1908
+ const user = findUser();
1909
+ if (user) render(user);
1910
+ ````
1911
+
1912
+ ### `no-const-assign`
1913
+
1914
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow reassigning `const`, `using`, and `await using` variables
1915
+
1916
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
1917
+ - 自动修复:不支持或上游未声明
1918
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-const-assign)
1919
+ - 常见报告:`'{{name}}' is constant.`
1920
+ - 示例类型:第三方预置规则的直接代码示例
1921
+
1922
+ 错误示例:
1923
+
1924
+ <!-- prettier-ignore -->
1925
+ ````js
1926
+ const timeout = 1000;
1927
+ timeout = 2000;
1928
+ ````
1929
+
1930
+ 正确示例:
1931
+
1932
+ <!-- prettier-ignore -->
1933
+ ````js
1934
+ let timeout = 1000;
1935
+ timeout = 2000;
1936
+ ````
1937
+
1938
+ ### `no-constant-binary-expression`
1939
+
1940
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow expressions where the operation doesn't affect the value
1941
+
1942
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1943
+ - 自动修复:不支持或上游未声明
1944
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-constant-binary-expression)
1945
+ - 常见报告:`Unexpected constant binary expression. Compares constantly with the {{otherSide}}-hand side of the '{{operator}}'.`;`Unexpected constant {{property}} on the left-hand side of a '{{operator}}' expression.`;`Unexpected comparison to newly constructed object. These two values can never be equal.`
1946
+ - 示例类型:第三方预置规则的直接代码示例
1947
+
1948
+ 错误示例:
1949
+
1950
+ <!-- prettier-ignore -->
1951
+ ````js
1952
+ const allowed = true || ready;
1953
+ ````
1954
+
1955
+ 正确示例:
1956
+
1957
+ <!-- prettier-ignore -->
1958
+ ````js
1959
+ const allowed = ready || fallbackAllowed;
1960
+ ````
1961
+
1962
+ ### `no-delete-var`
1963
+
1964
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow deleting variables
1965
+
1966
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
1967
+ - 自动修复:不支持或上游未声明
1968
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-delete-var)
1969
+ - 常见报告:`Variables should not be deleted.`
1970
+ - 示例类型:第三方预置规则的直接代码示例
1971
+
1972
+ 错误示例:
1973
+
1974
+ <!-- prettier-ignore -->
1975
+ ````js
1976
+ var token;
1977
+ delete token;
1978
+ ````
1979
+
1980
+ 正确示例:
1981
+
1982
+ <!-- prettier-ignore -->
1983
+ ````js
1984
+ let token;
1985
+ token = undefined;
1986
+ ````
1987
+
1988
+ ### `no-dupe-args`
1989
+
1990
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow duplicate arguments in `function` definitions
1991
+
1992
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
1993
+ - 自动修复:不支持或上游未声明
1994
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-dupe-args)
1995
+ - 常见报告:`Duplicate param '{{name}}'.`
1996
+ - 示例类型:第三方预置规则的直接代码示例
1997
+
1998
+ 错误示例:
1999
+
2000
+ <!-- prettier-ignore -->
2001
+ ````js
2002
+ function add(value, value) { return value; }
2003
+ ````
2004
+
2005
+ 正确示例:
2006
+
2007
+ <!-- prettier-ignore -->
2008
+ ````js
2009
+ function add(left, right) { return left + right; }
2010
+ ````
2011
+
2012
+ ### `no-dupe-class-members`
2013
+
2014
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow duplicate class members
2015
+
2016
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2017
+ - 自动修复:不支持或上游未声明
2018
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-dupe-class-members)
2019
+ - 常见报告:`Duplicate name '{{name}}'.`
2020
+ - 示例类型:第三方预置规则的直接代码示例
2021
+
2022
+ 错误示例:
2023
+
2024
+ <!-- prettier-ignore -->
2025
+ ````js
2026
+ class User { save() {} save() {} }
2027
+ ````
2028
+
2029
+ 正确示例:
2030
+
2031
+ <!-- prettier-ignore -->
2032
+ ````js
2033
+ class User { save() {} cancel() {} }
2034
+ ````
2035
+
2036
+ ### `no-dupe-else-if`
2037
+
2038
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow duplicate conditions in if-else-if chains
2039
+
2040
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2041
+ - 自动修复:不支持或上游未声明
2042
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-dupe-else-if)
2043
+ - 常见报告:`This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain.`
2044
+ - 示例类型:第三方预置规则的直接代码示例
2045
+
2046
+ 错误示例:
2047
+
2048
+ <!-- prettier-ignore -->
2049
+ ````js
2050
+ if (ready) start(); else if (ready) retry();
2051
+ ````
2052
+
2053
+ 正确示例:
2054
+
2055
+ <!-- prettier-ignore -->
2056
+ ````js
2057
+ if (ready) start(); else if (retryable) retry();
2058
+ ````
2059
+
2060
+ ### `no-dupe-keys`
2061
+
2062
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow duplicate keys in object literals
2063
+
2064
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2065
+ - 自动修复:不支持或上游未声明
2066
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-dupe-keys)
2067
+ - 常见报告:`Duplicate key '{{name}}'.`
2068
+ - 示例类型:第三方预置规则的直接代码示例
2069
+
2070
+ 错误示例:
2071
+
2072
+ <!-- prettier-ignore -->
2073
+ ````js
2074
+ const user = { name: "A", name: "B" };
2075
+ ````
2076
+
2077
+ 正确示例:
2078
+
2079
+ <!-- prettier-ignore -->
2080
+ ````js
2081
+ const user = { firstName: "A", lastName: "B" };
2082
+ ````
2083
+
2084
+ ### `no-duplicate-case`
2085
+
2086
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow duplicate case labels
2087
+
2088
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2089
+ - 自动修复:不支持或上游未声明
2090
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-duplicate-case)
2091
+ - 常见报告:`Duplicate case label.`
2092
+ - 示例类型:第三方预置规则的直接代码示例
2093
+
2094
+ 错误示例:
2095
+
2096
+ <!-- prettier-ignore -->
2097
+ ````js
2098
+ switch (status) { case "ready": start(); break; case "ready": retry(); }
2099
+ ````
2100
+
2101
+ 正确示例:
2102
+
2103
+ <!-- prettier-ignore -->
2104
+ ````js
2105
+ switch (status) { case "ready": start(); break; case "failed": retry(); }
2106
+ ````
2107
+
2108
+ ### `no-empty-character-class`
2109
+
2110
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow empty character classes in regular expressions
2111
+
2112
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2113
+ - 自动修复:不支持或上游未声明
2114
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-empty-character-class)
2115
+ - 常见报告:`Empty class.`
2116
+ - 示例类型:第三方预置规则的直接代码示例
2117
+
2118
+ 错误示例:
2119
+
2120
+ <!-- prettier-ignore -->
2121
+ ````js
2122
+ const pattern = /[]/;
2123
+ ````
2124
+
2125
+ 正确示例:
2126
+
2127
+ <!-- prettier-ignore -->
2128
+ ````js
2129
+ const pattern = /[a-z]/;
2130
+ ````
2131
+
2132
+ ### `no-empty-pattern`
2133
+
2134
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow empty destructuring patterns
2135
+
2136
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2137
+ - 自动修复:不支持或上游未声明
2138
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-empty-pattern)
2139
+ - 常见报告:`Unexpected empty {{type}} pattern.`
2140
+ - 示例类型:第三方预置规则的直接代码示例
2141
+
2142
+ 错误示例:
2143
+
2144
+ <!-- prettier-ignore -->
2145
+ ````js
2146
+ const {} = user;
2147
+ ````
2148
+
2149
+ 正确示例:
2150
+
2151
+ <!-- prettier-ignore -->
2152
+ ````js
2153
+ const { id } = user;
2154
+ use(id);
2155
+ ````
2156
+
2157
+ ### `no-empty-static-block`
2158
+
2159
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow empty static blocks
2160
+
2161
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2162
+ - 自动修复:不支持或上游未声明
2163
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-empty-static-block)
2164
+ - 常见报告:`Unexpected empty static block.`;`Add comment inside empty static block.`
2165
+ - 示例类型:第三方预置规则的直接代码示例
2166
+
2167
+ 错误示例:
2168
+
2169
+ <!-- prettier-ignore -->
2170
+ ````js
2171
+ class Cache { static {} }
2172
+ ````
2173
+
2174
+ 正确示例:
2175
+
2176
+ <!-- prettier-ignore -->
2177
+ ````js
2178
+ class Cache { static { Cache.initialize(); } }
2179
+ ````
2180
+
2181
+ ### `no-ex-assign`
2182
+
2183
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow reassigning exceptions in `catch` clauses
2184
+
2185
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2186
+ - 自动修复:不支持或上游未声明
2187
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-ex-assign)
2188
+ - 常见报告:`Do not assign to the exception parameter.`
2189
+ - 示例类型:第三方预置规则的直接代码示例
2190
+
2191
+ 错误示例:
2192
+
2193
+ <!-- prettier-ignore -->
2194
+ ````js
2195
+ try { run(); } catch (error) { error = normalize(error); throw error; }
2196
+ ````
2197
+
2198
+ 正确示例:
2199
+
2200
+ <!-- prettier-ignore -->
2201
+ ````js
2202
+ try { run(); } catch (error) { throw normalize(error); }
2203
+ ````
2204
+
2205
+ ### `no-extra-boolean-cast`
2206
+
2207
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unnecessary boolean casts
2208
+
2209
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2210
+ - 自动修复:支持;执行前仍应检查语义和差异
2211
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-extra-boolean-cast)
2212
+ - 常见报告:`Redundant Boolean call.`;`Redundant double negation.`
2213
+ - 示例类型:第三方预置规则的直接代码示例
2214
+
2215
+ 错误示例:
2216
+
2217
+ <!-- prettier-ignore -->
2218
+ ````js
2219
+ if (!!ready) start();
2220
+ ````
2221
+
2222
+ 正确示例:
2223
+
2224
+ <!-- prettier-ignore -->
2225
+ ````js
2226
+ if (ready) start();
2227
+ ````
2228
+
2229
+ ### `no-fallthrough`
2230
+
2231
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow fallthrough of `case` statements
2232
+
2233
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2234
+ - 自动修复:不支持或上游未声明
2235
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-fallthrough)
2236
+ - 常见报告:`Found a comment that would permit fallthrough, but case cannot fall through.`;`Expected a 'break' statement before 'case'.`;`Expected a 'break' statement before 'default'.`
2237
+ - 示例类型:第三方预置规则的直接代码示例
2238
+
2239
+ 错误示例:
2240
+
2241
+ <!-- prettier-ignore -->
2242
+ ````js
2243
+ switch (status) { case "ready": start(); case "done": finish(); }
2244
+ ````
2245
+
2246
+ 正确示例:
2247
+
2248
+ <!-- prettier-ignore -->
2249
+ ````js
2250
+ switch (status) { case "ready": start(); break; case "done": finish(); }
2251
+ ````
2252
+
2253
+ ### `no-func-assign`
2254
+
2255
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow reassigning `function` declarations
2256
+
2257
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2258
+ - 自动修复:不支持或上游未声明
2259
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-func-assign)
2260
+ - 常见报告:`'{{name}}' is a function.`
2261
+ - 示例类型:第三方预置规则的直接代码示例
2262
+
2263
+ 错误示例:
2264
+
2265
+ <!-- prettier-ignore -->
2266
+ ````js
2267
+ function load() {}
2268
+ load = createLoader();
2269
+ ````
2270
+
2271
+ 正确示例:
2272
+
2273
+ <!-- prettier-ignore -->
2274
+ ````js
2275
+ let load = createLoader();
2276
+ load = createCachedLoader();
2277
+ ````
2278
+
2279
+ ### `no-global-assign`
2280
+
2281
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow assignments to native objects or read-only global variables
2282
+
2283
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2284
+ - 自动修复:不支持或上游未声明
2285
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-global-assign)
2286
+ - 常见报告:`Read-only global '{{name}}' should not be modified.`
2287
+ - 示例类型:第三方预置规则的直接代码示例
2288
+
2289
+ 错误示例:
2290
+
2291
+ <!-- prettier-ignore -->
2292
+ ````js
2293
+ undefined = 1;
2294
+ ````
2295
+
2296
+ 正确示例:
2297
+
2298
+ <!-- prettier-ignore -->
2299
+ ````js
2300
+ const missingValue = undefined;
2301
+ ````
2302
+
2303
+ ### `no-import-assign`
2304
+
2305
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow assigning to imported bindings
2306
+
2307
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2308
+ - 自动修复:不支持或上游未声明
2309
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-import-assign)
2310
+ - 常见报告:`'{{name}}' is read-only.`;`The members of '{{name}}' are read-only.`
2311
+ - 示例类型:第三方预置规则的直接代码示例
2312
+
2313
+ 错误示例:
2314
+
2315
+ <!-- prettier-ignore -->
2316
+ ````js
2317
+ import * as api from "./api.js";
2318
+ api = {};
2319
+ ````
2320
+
2321
+ 正确示例:
2322
+
2323
+ <!-- prettier-ignore -->
2324
+ ````js
2325
+ import * as api from "./api.js";
2326
+ api.request();
2327
+ ````
2328
+
2329
+ ### `no-invalid-regexp`
2330
+
2331
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow invalid regular expression strings in `RegExp` constructors
2332
+
2333
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2334
+ - 自动修复:不支持或上游未声明
2335
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-invalid-regexp)
2336
+ - 常见报告:`{{message}}.`
2337
+ - 示例类型:第三方预置规则的直接代码示例
2338
+
2339
+ 错误示例:
2340
+
2341
+ <!-- prettier-ignore -->
2342
+ ````js
2343
+ const pattern = new RegExp("[");
2344
+ ````
2345
+
2346
+ 正确示例:
2347
+
2348
+ <!-- prettier-ignore -->
2349
+ ````js
2350
+ const pattern = new RegExp("[a-z]");
2351
+ ````
2352
+
2353
+ ### `no-loss-of-precision`
2354
+
2355
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow literal numbers that lose precision
2356
+
2357
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2358
+ - 自动修复:不支持或上游未声明
2359
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-loss-of-precision)
2360
+ - 常见报告:`This number literal will lose precision at runtime.`
2361
+ - 示例类型:第三方预置规则的直接代码示例
2362
+
2363
+ 错误示例:
2364
+
2365
+ <!-- prettier-ignore -->
2366
+ ````js
2367
+ const id = 9007199254740993;
2368
+ ````
2369
+
2370
+ 正确示例:
2371
+
2372
+ <!-- prettier-ignore -->
2373
+ ````js
2374
+ const id = 9007199254740993n;
2375
+ ````
2376
+
2377
+ ### `no-new-native-nonconstructor`
2378
+
2379
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow `new` operators with global non-constructor functions
2380
+
2381
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2382
+ - 自动修复:不支持或上游未声明
2383
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-new-native-nonconstructor)
2384
+ - 常见报告:`'{{name}}' cannot be called as a constructor.`
2385
+ - 示例类型:第三方预置规则的直接代码示例
2386
+
2387
+ 错误示例:
2388
+
2389
+ <!-- prettier-ignore -->
2390
+ ````js
2391
+ const token = new Symbol();
2392
+ ````
2393
+
2394
+ 正确示例:
2395
+
2396
+ <!-- prettier-ignore -->
2397
+ ````js
2398
+ const token = Symbol();
2399
+ ````
2400
+
2401
+ ### `no-nonoctal-decimal-escape`
2402
+
2403
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow `\8` and `\9` escape sequences in string literals
2404
+
2405
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2406
+ - 自动修复:不支持或上游未声明
2407
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-nonoctal-decimal-escape)
2408
+ - 常见报告:`Don't use '{{decimalEscape}}' escape sequence.`;`Replace '{{original}}' with '{{replacement}}'. This maintains the current functionality.`;`Replace '{{original}}' with '{{replacement}}' to include the actual backslash character.`
2409
+ - 示例类型:第三方预置规则的直接代码示例
2410
+
2411
+ 错误示例:
2412
+
2413
+ <!-- prettier-ignore -->
2414
+ ````js
2415
+ const digit = "\8";
2416
+ ````
2417
+
2418
+ 正确示例:
2419
+
2420
+ <!-- prettier-ignore -->
2421
+ ````js
2422
+ const digit = "8";
2423
+ ````
2424
+
2425
+ ### `no-obj-calls`
2426
+
2427
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow calling global object properties as functions
2428
+
2429
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2430
+ - 自动修复:不支持或上游未声明
2431
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-obj-calls)
2432
+ - 常见报告:`'{{name}}' is not a function.`;`'{{name}}' is reference to '{{ref}}', which is not a function.`
2433
+ - 示例类型:第三方预置规则的直接代码示例
2434
+
2435
+ 错误示例:
2436
+
2437
+ <!-- prettier-ignore -->
2438
+ ````js
2439
+ const value = Math();
2440
+ ````
2441
+
2442
+ 正确示例:
2443
+
2444
+ <!-- prettier-ignore -->
2445
+ ````js
2446
+ const value = Math.max(1, 2);
2447
+ ````
2448
+
2449
+ ### `no-octal`
2450
+
2451
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow octal literals
2452
+
2453
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2454
+ - 自动修复:不支持或上游未声明
2455
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-octal)
2456
+ - 常见报告:`Octal literals should not be used.`
2457
+ - 示例类型:第三方预置规则的直接代码示例
2458
+
2459
+ 错误示例:
2460
+
2461
+ <!-- prettier-ignore -->
2462
+ ````js
2463
+ const mode = 071;
2464
+ ````
2465
+
2466
+ 正确示例:
2467
+
2468
+ <!-- prettier-ignore -->
2469
+ ````js
2470
+ const mode = 0o71;
2471
+ ````
2472
+
2473
+ ### `no-prototype-builtins`
2474
+
2475
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow calling some `Object.prototype` methods directly on objects
2476
+
2477
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2478
+ - 自动修复:不支持或上游未声明
2479
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-prototype-builtins)
2480
+ - 常见报告:`Do not access Object.prototype method '{{prop}}' from target object.`;`Call Object.prototype.{{prop}} explicitly.`
2481
+ - 示例类型:第三方预置规则的直接代码示例
2482
+
2483
+ 错误示例:
2484
+
2485
+ <!-- prettier-ignore -->
2486
+ ````js
2487
+ if (payload.hasOwnProperty(key)) use(payload[key]);
2488
+ ````
2489
+
2490
+ 正确示例:
2491
+
2492
+ <!-- prettier-ignore -->
2493
+ ````js
2494
+ if (Object.hasOwn(payload, key)) use(payload[key]);
2495
+ ````
2496
+
2497
+ ### `no-self-assign`
2498
+
2499
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow assignments where both sides are exactly the same
2500
+
2501
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2502
+ - 自动修复:不支持或上游未声明
2503
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-self-assign)
2504
+ - 常见报告:`'{{name}}' is assigned to itself.`
2505
+ - 示例类型:第三方预置规则的直接代码示例
2506
+
2507
+ 错误示例:
2508
+
2509
+ <!-- prettier-ignore -->
2510
+ ````js
2511
+ user.name = user.name;
2512
+ ````
2513
+
2514
+ 正确示例:
2515
+
2516
+ <!-- prettier-ignore -->
2517
+ ````js
2518
+ user.name = nextName;
2519
+ ````
2520
+
2521
+ ### `no-setter-return`
2522
+
2523
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow returning values from setters
2524
+
2525
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2526
+ - 自动修复:不支持或上游未声明
2527
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-setter-return)
2528
+ - 常见报告:`Setter cannot return a value.`
2529
+ - 示例类型:第三方预置规则的直接代码示例
2530
+
2531
+ 错误示例:
2532
+
2533
+ <!-- prettier-ignore -->
2534
+ ````js
2535
+ const user = { set name(value) { return value; } };
2536
+ ````
2537
+
2538
+ 正确示例:
2539
+
2540
+ <!-- prettier-ignore -->
2541
+ ````js
2542
+ const user = { set name(value) { saveName(value); } };
2543
+ ````
2544
+
2545
+ ### `no-shadow-restricted-names`
2546
+
2547
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow identifiers from shadowing restricted names
2548
+
2549
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2550
+ - 自动修复:不支持或上游未声明
2551
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-shadow-restricted-names)
2552
+ - 常见报告:`Shadowing of global property '{{name}}'.`
2553
+ - 示例类型:第三方预置规则的直接代码示例
2554
+
2555
+ 错误示例:
2556
+
2557
+ <!-- prettier-ignore -->
2558
+ ````js
2559
+ const undefined = 1;
2560
+ ````
2561
+
2562
+ 正确示例:
2563
+
2564
+ <!-- prettier-ignore -->
2565
+ ````js
2566
+ const missingValue = undefined;
2567
+ ````
2568
+
2569
+ ### `no-sparse-arrays`
2570
+
2571
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow sparse arrays
2572
+
2573
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2574
+ - 自动修复:不支持或上游未声明
2575
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-sparse-arrays)
2576
+ - 常见报告:`Unexpected comma in middle of array.`
2577
+ - 示例类型:第三方预置规则的直接代码示例
2578
+
2579
+ 错误示例:
2580
+
2581
+ <!-- prettier-ignore -->
2582
+ ````js
2583
+ const values = [1, , 3];
2584
+ ````
2585
+
2586
+ 正确示例:
2587
+
2588
+ <!-- prettier-ignore -->
2589
+ ````js
2590
+ const values = [1, undefined, 3];
2591
+ ````
2592
+
2593
+ ### `no-this-before-super`
2594
+
2595
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow `this`/`super` before calling `super()` in constructors
2596
+
2597
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2598
+ - 自动修复:不支持或上游未声明
2599
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-this-before-super)
2600
+ - 常见报告:`'{{kind}}' is not allowed before 'super()'.`
2601
+ - 示例类型:第三方预置规则的直接代码示例
2602
+
2603
+ 错误示例:
2604
+
2605
+ <!-- prettier-ignore -->
2606
+ ````js
2607
+ class User extends Entity { constructor() { this.ready = true; super(); } }
2608
+ ````
2609
+
2610
+ 正确示例:
2611
+
2612
+ <!-- prettier-ignore -->
2613
+ ````js
2614
+ class User extends Entity { constructor() { super(); this.ready = true; } }
2615
+ ````
2616
+
2617
+ ### `no-unassigned-vars`
2618
+
2619
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow `let` or `var` variables that are read but never assigned
2620
+
2621
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2622
+ - 自动修复:不支持或上游未声明
2623
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unassigned-vars)
2624
+ - 常见报告:`'{{name}}' is always 'undefined' because it's never assigned.`
2625
+ - 示例类型:第三方预置规则的直接代码示例
2626
+
2627
+ 错误示例:
2628
+
2629
+ <!-- prettier-ignore -->
2630
+ ````js
2631
+ let result;
2632
+ render(result);
2633
+ ````
2634
+
2635
+ 正确示例:
2636
+
2637
+ <!-- prettier-ignore -->
2638
+ ````js
2639
+ const result = load();
2640
+ render(result);
2641
+ ````
2642
+
2643
+ ### `no-undef`
2644
+
2645
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow the use of undeclared variables unless mentioned in `/*global */` comments
2646
+
2647
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2648
+ - 自动修复:不支持或上游未声明
2649
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-undef)
2650
+ - 常见报告:`'{{name}}' is not defined.`
2651
+ - 示例类型:第三方预置规则的直接代码示例
2652
+
2653
+ 错误示例:
2654
+
2655
+ <!-- prettier-ignore -->
2656
+ ````js
2657
+ total = price * count;
2658
+ ````
2659
+
2660
+ 正确示例:
2661
+
2662
+ <!-- prettier-ignore -->
2663
+ ````js
2664
+ const price = 10;
2665
+ const count = 2;
2666
+ const total = price * count;
2667
+ ````
2668
+
2669
+ ### `no-unreachable`
2670
+
2671
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements
2672
+
2673
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2674
+ - 自动修复:不支持或上游未声明
2675
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unreachable)
2676
+ - 常见报告:`Unreachable code.`
2677
+ - 示例类型:第三方预置规则的直接代码示例
2678
+
2679
+ 错误示例:
2680
+
2681
+ <!-- prettier-ignore -->
2682
+ ````js
2683
+ function load() { return value; log(value); }
2684
+ ````
2685
+
2686
+ 正确示例:
2687
+
2688
+ <!-- prettier-ignore -->
2689
+ ````js
2690
+ function load() { log(value); return value; }
2691
+ ````
2692
+
2693
+ ### `no-unsafe-finally`
2694
+
2695
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow control flow statements in `finally` blocks
2696
+
2697
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2698
+ - 自动修复:不支持或上游未声明
2699
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unsafe-finally)
2700
+ - 常见报告:`Unsafe usage of {{nodeType}}.`
2701
+ - 示例类型:第三方预置规则的直接代码示例
2702
+
2703
+ 错误示例:
2704
+
2705
+ <!-- prettier-ignore -->
2706
+ ````js
2707
+ function load() { try { return fetchValue(); } finally { return fallback; } }
2708
+ ````
2709
+
2710
+ 正确示例:
2711
+
2712
+ <!-- prettier-ignore -->
2713
+ ````js
2714
+ function load() { try { return fetchValue(); } finally { release(); } }
2715
+ ````
2716
+
2717
+ ### `no-unsafe-negation`
2718
+
2719
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow negating the left operand of relational operators
2720
+
2721
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2722
+ - 自动修复:不支持或上游未声明
2723
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unsafe-negation)
2724
+ - 常见报告:`Unexpected negating the left operand of '{{operator}}' operator.`;`Negate '{{operator}}' expression instead of its left operand. This changes the current behavior.`;`Wrap negation in '()' to make the intention explicit. This preserves the current behavior.`
2725
+ - 示例类型:第三方预置规则的直接代码示例
2726
+
2727
+ 错误示例:
2728
+
2729
+ <!-- prettier-ignore -->
2730
+ ````js
2731
+ if (!key in object) handleMissing();
2732
+ ````
2733
+
2734
+ 正确示例:
2735
+
2736
+ <!-- prettier-ignore -->
2737
+ ````js
2738
+ if (!(key in object)) handleMissing();
2739
+ ````
2740
+
2741
+ ### `no-unsafe-optional-chaining`
2742
+
2743
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow use of optional chaining in contexts where the `undefined` value is not allowed
2744
+
2745
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2746
+ - 自动修复:不支持或上游未声明
2747
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining)
2748
+ - 常见报告:`Unsafe usage of optional chaining. If it short-circuits with 'undefined' the evaluation will throw TypeError.`;`Unsafe arithmetic operation on optional chaining. It can result in NaN.`
2749
+ - 示例类型:第三方预置规则的直接代码示例
2750
+
2751
+ 错误示例:
2752
+
2753
+ <!-- prettier-ignore -->
2754
+ ````js
2755
+ const { name } = user?.profile;
2756
+ ````
2757
+
2758
+ 正确示例:
2759
+
2760
+ <!-- prettier-ignore -->
2761
+ ````js
2762
+ const name = user?.profile?.name;
2763
+ ````
2764
+
2765
+ ### `no-unused-labels`
2766
+
2767
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unused labels
2768
+
2769
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2770
+ - 自动修复:支持;执行前仍应检查语义和差异
2771
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unused-labels)
2772
+ - 常见报告:`'{{name}}:' is defined but never used.`
2773
+ - 示例类型:第三方预置规则的直接代码示例
2774
+
2775
+ 错误示例:
2776
+
2777
+ <!-- prettier-ignore -->
2778
+ ````js
2779
+ retry: run();
2780
+ ````
2781
+
2782
+ 正确示例:
2783
+
2784
+ <!-- prettier-ignore -->
2785
+ ````js
2786
+ run();
2787
+ ````
2788
+
2789
+ ### `no-unused-private-class-members`
2790
+
2791
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unused private class members
2792
+
2793
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2794
+ - 自动修复:不支持或上游未声明
2795
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unused-private-class-members)
2796
+ - 常见报告:`'{{classMemberName}}' is defined but never used.`;`Remove unused private class member '{{classMemberName}}'.`
2797
+ - 示例类型:第三方预置规则的直接代码示例
2798
+
2799
+ 错误示例:
2800
+
2801
+ <!-- prettier-ignore -->
2802
+ ````js
2803
+ class User { #secret = 1; getName() { return "Fast"; } }
2804
+ ````
2805
+
2806
+ 正确示例:
2807
+
2808
+ <!-- prettier-ignore -->
2809
+ ````js
2810
+ class User { #name; constructor(name) { this.#name = name; } getName() { return this.#name; } }
2811
+ ````
2812
+
2813
+ ### `no-unused-vars`
2814
+
2815
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unused variables
2816
+
2817
+ - 生效级别与范围:error: JavaScript 基础、Vue JSX、React JSX、Lodash、Lodash Unified
2818
+ - 自动修复:不支持或上游未声明
2819
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-unused-vars)
2820
+ - 常见报告:`'{{varName}}' is {{action}} but never used{{additional}}.`;`'{{varName}}' is marked as ignored but is used{{additional}}.`;`Remove unused variable '{{varName}}'.`
2821
+ - 示例类型:第三方预置规则的直接代码示例
2822
+
2823
+ 错误示例:
2824
+
2825
+ <!-- prettier-ignore -->
2826
+ ````js
2827
+ const unusedValue = load();
2828
+ ````
2829
+
2830
+ 正确示例:
2831
+
2832
+ <!-- prettier-ignore -->
2833
+ ````js
2834
+ const value = load();
2835
+ render(value);
2836
+ ````
2837
+
2838
+ ### `no-useless-assignment`
2839
+
2840
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow variable assignments when the value is not used
2841
+
2842
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2843
+ - 自动修复:不支持或上游未声明
2844
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-useless-assignment)
2845
+ - 常见报告:`The value assigned to '{{name}}' is not used in subsequent statements.`
2846
+ - 示例类型:第三方预置规则的直接代码示例
2847
+
2848
+ 错误示例:
2849
+
2850
+ <!-- prettier-ignore -->
2851
+ ````js
2852
+ function getStatus() { let status = "idle";
2853
+ status = "ready";
2854
+ return status; }
2855
+ ````
2856
+
2857
+ 正确示例:
2858
+
2859
+ <!-- prettier-ignore -->
2860
+ ````js
2861
+ function getStatus() { const status = "ready";
2862
+ return status; }
2863
+ ````
2864
+
2865
+ ### `no-useless-backreference`
2866
+
2867
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow useless backreferences in regular expressions
2868
+
2869
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2870
+ - 自动修复:不支持或上游未声明
2871
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-useless-backreference)
2872
+ - 常见报告:`Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} from within that group.`;`Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears later in the pattern.`;`Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears before in the same lookbehind.`
2873
+ - 示例类型:第三方预置规则的直接代码示例
2874
+
2875
+ 错误示例:
2876
+
2877
+ <!-- prettier-ignore -->
2878
+ ````js
2879
+ const pattern = /\1(a)/;
2880
+ ````
2881
+
2882
+ 正确示例:
2883
+
2884
+ <!-- prettier-ignore -->
2885
+ ````js
2886
+ const pattern = /(a)\1/;
2887
+ ````
2888
+
2889
+ ### `no-useless-catch`
2890
+
2891
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unnecessary `catch` clauses
2892
+
2893
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2894
+ - 自动修复:不支持或上游未声明
2895
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-useless-catch)
2896
+ - 常见报告:`Unnecessary catch clause.`;`Unnecessary try/catch wrapper.`
2897
+ - 示例类型:第三方预置规则的直接代码示例
2898
+
2899
+ 错误示例:
2900
+
2901
+ <!-- prettier-ignore -->
2902
+ ````js
2903
+ try { run(); } catch (error) { throw error; }
2904
+ ````
2905
+
2906
+ 正确示例:
2907
+
2908
+ <!-- prettier-ignore -->
2909
+ ````js
2910
+ run();
2911
+ ````
2912
+
2913
+ ### `no-useless-escape`
2914
+
2915
+ 禁止出现该规则定义的不安全、无效或易误解结构。上游说明:Disallow unnecessary escape characters
2916
+
2917
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2918
+ - 自动修复:不支持或上游未声明
2919
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/no-useless-escape)
2920
+ - 常见报告:`Unnecessary escape character: \{{character}}.`;`Remove the '\'. This maintains the current functionality.`;`Remove the '\' if it was inserted by mistake.`
2921
+ - 示例类型:第三方预置规则的直接代码示例
2922
+
2923
+ 错误示例:
2924
+
2925
+ <!-- prettier-ignore -->
2926
+ ````js
2927
+ const name = "Fast\!";
2928
+ ````
2929
+
2930
+ 正确示例:
2931
+
2932
+ <!-- prettier-ignore -->
2933
+ ````js
2934
+ const name = "Fast!";
2935
+ ````
2936
+
2937
+ ### `preserve-caught-error`
2938
+
2939
+ 检查该规则对应的代码约束。上游说明:Disallow losing originally caught error when re-throwing custom errors
2940
+
2941
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2942
+ - 自动修复:不支持或上游未声明
2943
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/preserve-caught-error)
2944
+ - 常见报告:`There is no 'cause' attached to the symptom error being thrown.`;`The symptom error is being thrown with an incorrect 'cause'.`;`Include the original caught error as the 'cause' of the symptom error.`
2945
+ - 示例类型:第三方预置规则的直接代码示例
2946
+
2947
+ 错误示例:
2948
+
2949
+ <!-- prettier-ignore -->
2950
+ ````js
2951
+ try { connect(); } catch (error) { throw new Error("Connection failed"); }
2952
+ ````
2953
+
2954
+ 正确示例:
2955
+
2956
+ <!-- prettier-ignore -->
2957
+ ````js
2958
+ try { connect(); } catch (error) { throw new Error("Connection failed", { cause: error }); }
2959
+ ````
2960
+
2961
+ ### `require-yield`
2962
+
2963
+ 要求补齐该规则所需的声明、属性或结构。上游说明:Require generator functions to contain `yield`
2964
+
2965
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2966
+ - 自动修复:不支持或上游未声明
2967
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/require-yield)
2968
+ - 常见报告:`This generator function does not have 'yield'.`
2969
+ - 示例类型:第三方预置规则的直接代码示例
2970
+
2971
+ 错误示例:
2972
+
2973
+ <!-- prettier-ignore -->
2974
+ ````js
2975
+ function* values() { return 1; }
2976
+ ````
2977
+
2978
+ 正确示例:
2979
+
2980
+ <!-- prettier-ignore -->
2981
+ ````js
2982
+ function* values() { yield 1; }
2983
+ ````
2984
+
2985
+ ### `use-isnan`
2986
+
2987
+ 检查该规则对应的代码约束。上游说明:Require calls to `isNaN()` when checking for `NaN`
2988
+
2989
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
2990
+ - 自动修复:不支持或上游未声明
2991
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/use-isnan)
2992
+ - 常见报告:`Use the isNaN function to compare with NaN.`;`'switch(NaN)' can never match a case clause. Use Number.isNaN instead of the switch.`;`'case NaN' can never match. Use Number.isNaN before the switch.`
2993
+ - 示例类型:第三方预置规则的直接代码示例
2994
+
2995
+ 错误示例:
2996
+
2997
+ <!-- prettier-ignore -->
2998
+ ````js
2999
+ if (value === NaN) reset();
3000
+ ````
3001
+
3002
+ 正确示例:
3003
+
3004
+ <!-- prettier-ignore -->
3005
+ ````js
3006
+ if (Number.isNaN(value)) reset();
3007
+ ````
3008
+
3009
+ ### `valid-typeof`
3010
+
3011
+ 校验对应语法、属性或参数是否合法。上游说明:Enforce comparing `typeof` expressions against valid strings
3012
+
3013
+ - 生效级别与范围:error: JavaScript 基础、TypeScript 基础、框架无关 TSX、Vue SFC、Vue JSX、Vue TSX、UniApp NVue、UniApp TSX、React JSX、React TSX、Angular TypeScript、Lodash、Lodash Unified
3014
+ - 自动修复:不支持或上游未声明
3015
+ - 规则来源:[官方文档](https://eslint.org/docs/latest/rules/valid-typeof)
3016
+ - 常见报告:`Invalid typeof comparison value.`;`Typeof comparisons should be to string literals.`;`Use '"{{type}}"' instead of '{{type}}'.`
3017
+ - 示例类型:第三方预置规则的直接代码示例
3018
+
3019
+ 错误示例:
3020
+
3021
+ <!-- prettier-ignore -->
3022
+ ````js
3023
+ if (typeof value === "strnig") reset();
3024
+ ````
3025
+
3026
+ 正确示例:
3027
+
3028
+ <!-- prettier-ignore -->
3029
+ ````js
3030
+ if (typeof value === "string") reset();
3031
+ ````