@purea/eslint-config 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +463 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +1118 -0
- package/eslint.config.ts +12 -0
- package/package.json +42 -0
- package/src/configs/ignores.ts +17 -0
- package/src/configs/imports.ts +104 -0
- package/src/configs/index.ts +7 -0
- package/src/configs/javascript.ts +268 -0
- package/src/configs/jsonc.ts +66 -0
- package/src/configs/stylistic.ts +278 -0
- package/src/configs/typescript.ts +263 -0
- package/src/configs/vue.ts +69 -0
- package/src/factory.ts +70 -0
- package/src/index.ts +9 -0
- package/src/types.ts +82 -0
- package/src/utils.ts +19 -0
- package/test/javascript-rules.test.ts +1134 -0
- package/tsconfig.json +14 -0
- package/tsdown.config.ts +7 -0
|
@@ -0,0 +1,1134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript ESLint 规则测试文件
|
|
3
|
+
*
|
|
4
|
+
* 本文件包含所有JavaScript规则的测试用例,用于验证每个规则的配置是否合理
|
|
5
|
+
*
|
|
6
|
+
* 使用方法:
|
|
7
|
+
* 1. 运行 eslint 检查此文件:eslint test/javascript-rules.test.js
|
|
8
|
+
* 2. 查看错误和警告,判断规则是否需要开启或关闭
|
|
9
|
+
* 3. 根据实际需求调整 src/configs/javascript.ts 中的规则配置
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Possible Errors - 可能的错误
|
|
14
|
+
// ============================================================================
|
|
15
|
+
|
|
16
|
+
// no-console - 禁用 console(当前:off)
|
|
17
|
+
// console.log('This will not trigger error because rule is off');
|
|
18
|
+
// console.error('Error message');
|
|
19
|
+
// console.warn('Warning message');
|
|
20
|
+
|
|
21
|
+
// no-debugger - 禁用 debugger 语句(当前:error)
|
|
22
|
+
// debugger; // ❌ ERROR: Unexpected 'debugger' statement
|
|
23
|
+
|
|
24
|
+
// no-alert - 禁用 alert(当前:warn)
|
|
25
|
+
// alert('Hello'); // ⚠️ WARN: Unexpected alert
|
|
26
|
+
|
|
27
|
+
// no-constant-condition - 禁用常量条件表达式(当前:warn,循环中除外)
|
|
28
|
+
// if (true) { // ⚠️ WARN: Unexpected constant condition
|
|
29
|
+
// console.log('always true');
|
|
30
|
+
// }
|
|
31
|
+
// while (false) { // ⚠️ WARN: Unexpected constant condition
|
|
32
|
+
// console.log('never runs');
|
|
33
|
+
// }
|
|
34
|
+
// for (let i = 0; true; i++) { // ✅ OK: checkLoops: false
|
|
35
|
+
// if (i > 5) break;
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
// no-constant-binary-expression - 禁止常量二元表达式(当前:error)
|
|
39
|
+
// const result = 1 + 2; // ❌ ERROR: Unexpected constant binary expression
|
|
40
|
+
|
|
41
|
+
// for-direction - 检查 for-in 循环的方向(当前:error)
|
|
42
|
+
// for (let i = 0; i < 10; i--) { // ❌ ERROR: The update clause in this loop moves the variable in the wrong direction
|
|
43
|
+
// console.log(i);
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
// no-async-promise-executor - 禁止在 Promise executor 函数中使用 async(当前:error)
|
|
47
|
+
// new Promise(async () => {}); // ❌ ERROR: Promise executor functions should not be async
|
|
48
|
+
|
|
49
|
+
// no-await-in-loop - 禁止在循环中使用 await(当前:warn)
|
|
50
|
+
// async function test() {
|
|
51
|
+
// for (const item of items) {
|
|
52
|
+
// await processItem(item); // ⚠️ WARN: Unexpected await in a loop
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
// no-cond-assign - 禁止在条件语句中使用赋值(当前:error)
|
|
57
|
+
// let x;
|
|
58
|
+
// if (x = 5) { // ❌ ERROR: Expected a conditional expression and instead saw an assignment
|
|
59
|
+
// console.log(x);
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
// no-control-regex - 禁止正则表达式中的控制字符(当前:error)
|
|
63
|
+
// const pattern = /\x1f/; // ❌ ERROR: Unexpected control character(s) in regular expression
|
|
64
|
+
|
|
65
|
+
// no-dupe-else-if - 禁止重复的 else-if 条件(当前:error)
|
|
66
|
+
// if (x === 1) {
|
|
67
|
+
// } else if (x === 1) { // ❌ ERROR: This branch can never execute
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
// no-empty-character-class - 禁止正则表达式中的空字符类(当前:error)
|
|
71
|
+
// const pattern = /^abc[]/; // ❌ ERROR: Empty character class
|
|
72
|
+
|
|
73
|
+
// no-extra-parens - 禁止不必要的括号(当前:off)
|
|
74
|
+
// const result = ((1 + 2)); // ✅ OK: rule is off
|
|
75
|
+
|
|
76
|
+
// no-extra-semi - 禁止多余的分号(当前:error)
|
|
77
|
+
// const x = 5;; // ❌ ERROR: Unnecessary semicolon
|
|
78
|
+
|
|
79
|
+
// no-dupe-args - 禁止函数参数重复(当前:error)
|
|
80
|
+
// function test(a, a) { // ❌ ERROR: Duplicate param 'a'
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
// no-dupe-keys - 禁止对象字面量中重复的键(当前:error)
|
|
84
|
+
// const obj = { a: 1, a: 2 }; // ❌ ERROR: Duplicate key 'a'
|
|
85
|
+
|
|
86
|
+
// no-duplicate-case - 禁止 switch 语句中重复的 case(当前:error)
|
|
87
|
+
// switch (x) {
|
|
88
|
+
// case 1:
|
|
89
|
+
// break;
|
|
90
|
+
// case 1: // ❌ ERROR: Duplicate case
|
|
91
|
+
// break;
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
// no-empty - 禁止空语句块(当前:warn,catch 除外)
|
|
95
|
+
// function test() { // ⚠️ WARN: Empty block statement
|
|
96
|
+
// }
|
|
97
|
+
// try {
|
|
98
|
+
// throw new Error();
|
|
99
|
+
// } catch (e) { // ✅ OK: allowEmptyCatch: true
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
// no-ex-assign - 禁止重新分配异常参数(当前:error)
|
|
103
|
+
// try {
|
|
104
|
+
// throw new Error();
|
|
105
|
+
// } catch (e) {
|
|
106
|
+
// e = new Error(); // ❌ ERROR: Do not assign to the exception parameter
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
// no-extra-boolean-cast - 禁止不必要的布尔类型转换(当前:error)
|
|
110
|
+
// const x = !!true; // ❌ ERROR: Redundant double negation
|
|
111
|
+
|
|
112
|
+
// no-func-assign - 禁止重新分配函数声明(当前:error)
|
|
113
|
+
// function test() {}
|
|
114
|
+
// test = function() {}; // ❌ ERROR: 'test' is a function
|
|
115
|
+
|
|
116
|
+
// no-inner-declarations - 禁止在嵌套块中声明函数(当前:error)
|
|
117
|
+
// if (true) {
|
|
118
|
+
// function test() {} // ❌ ERROR: Move function declaration to top of function scope
|
|
119
|
+
// }
|
|
120
|
+
|
|
121
|
+
// no-invalid-regexp - 禁止无效的正则表达式字符串(当前:error)
|
|
122
|
+
// const pattern = new RegExp('('); // ❌ ERROR: Invalid regular expression
|
|
123
|
+
|
|
124
|
+
// no-irregular-whitespace - 禁止不规则的空白字符(当前:error)
|
|
125
|
+
// const x = 1; // ❌ ERROR: Irregular whitespace not allowed
|
|
126
|
+
|
|
127
|
+
// no-obj-calls - 禁止将全局对象作为函数调用(当前:error)
|
|
128
|
+
// const math = Math(); // ❌ ERROR: 'Math' is not a function
|
|
129
|
+
|
|
130
|
+
// no-prototype-builtins - 禁止直接调用 Object.prototype 方法(当前:error)
|
|
131
|
+
// const obj = {};
|
|
132
|
+
// const hasOwn = obj.hasOwnProperty('key'); // ❌ ERROR: Do not access Object.prototype method 'hasOwnProperty' from target object
|
|
133
|
+
// ✅ Correct: Object.prototype.hasOwnProperty.call(obj, 'key');
|
|
134
|
+
|
|
135
|
+
// no-regex-spaces - 禁止正则表达式中的多个空格(当前:error)
|
|
136
|
+
// const pattern = /foo bar/; // ❌ ERROR: Multiple spaces found in regular expression
|
|
137
|
+
|
|
138
|
+
// no-sparse-arrays - 禁止稀疏数组(当前:error)
|
|
139
|
+
// const arr = [1, , 2]; // ❌ ERROR: Unexpected sparse array
|
|
140
|
+
|
|
141
|
+
// no-compare-neg-zero - 禁止与 -0 比较(当前:error)
|
|
142
|
+
// const x = -0;
|
|
143
|
+
// if (x === -0) { // ❌ ERROR: Do not compare against -0
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
// no-loss-of-precision - 禁止因精度丢失的数字字面量(当前:error)
|
|
147
|
+
// const x = 9007199254740993; // ❌ ERROR: Loss of precision
|
|
148
|
+
|
|
149
|
+
// no-new-native-nonconstructor - 禁止对非构造函数使用 new(当前:error)
|
|
150
|
+
// const symbol = new Symbol('test'); // ❌ ERROR: Symbol is not a constructor
|
|
151
|
+
|
|
152
|
+
// no-promise-executor-return - 禁止在 Promise executor 函数中返回值(当前:error)
|
|
153
|
+
// new Promise((resolve) => { return; }); // ❌ ERROR: Return statement is allowed only inside a function
|
|
154
|
+
|
|
155
|
+
// no-setter-return - 禁止 setter 函数返回值(当前:error)
|
|
156
|
+
// const obj = {
|
|
157
|
+
// set x(value) {
|
|
158
|
+
// return value; // ❌ ERROR: Setters cannot return values
|
|
159
|
+
// }
|
|
160
|
+
// };
|
|
161
|
+
|
|
162
|
+
// no-template-curly-in-string - 禁止在字符串中使用模板字面量占位符(当前:error)
|
|
163
|
+
// const str = 'Hello ${name}'; // ❌ ERROR: Unexpected template string expression
|
|
164
|
+
|
|
165
|
+
// no-unexpected-multiline - 禁止令人困惑的多行表达式(当前:error)
|
|
166
|
+
// const x = 1
|
|
167
|
+
// [1, 2, 3].forEach(n => console.log(n)); // ❌ ERROR: Unexpected newline between object and [...]
|
|
168
|
+
|
|
169
|
+
// no-unreachable - 禁止无法到达的代码(当前:error)
|
|
170
|
+
// function test() {
|
|
171
|
+
// return;
|
|
172
|
+
// console.log('unreachable'); // ❌ ERROR: Unreachable code
|
|
173
|
+
// }
|
|
174
|
+
|
|
175
|
+
// no-unreachable-loop - 禁止无法到达的循环(当前:error)
|
|
176
|
+
// function test() {
|
|
177
|
+
// return;
|
|
178
|
+
// for (let i = 0; i < 10; i++) { // ❌ ERROR: Unreachable loop
|
|
179
|
+
// }
|
|
180
|
+
// }
|
|
181
|
+
|
|
182
|
+
// no-unsafe-finally - 禁止 finally 块中的控制流语句(当前:error)
|
|
183
|
+
// try {
|
|
184
|
+
// return 1;
|
|
185
|
+
// } finally {
|
|
186
|
+
// return 2; // ❌ ERROR: Unsafe usage of ReturnStatement
|
|
187
|
+
// }
|
|
188
|
+
|
|
189
|
+
// no-unsafe-negation - 禁止关系运算符的否定操作符位置不正确(当前:error)
|
|
190
|
+
// if (!x === 1) { // ❌ ERROR: Negating the left operand of the in operator
|
|
191
|
+
// }
|
|
192
|
+
|
|
193
|
+
// use-isnan - 要求使用 isNaN() 检查 NaN(当前:error)
|
|
194
|
+
// if (x === NaN) { // ❌ ERROR: Use the isNaN function to compare with NaN
|
|
195
|
+
// }
|
|
196
|
+
// ✅ Correct: if (isNaN(x)) {}
|
|
197
|
+
|
|
198
|
+
// valid-typeof - 强制 typeof 表达式与有效字符串比较(当前:error)
|
|
199
|
+
// if (typeof x === 'strnig') { // ❌ ERROR: Invalid typeof comparison value
|
|
200
|
+
// }
|
|
201
|
+
|
|
202
|
+
// ============================================================================
|
|
203
|
+
// Best Practices - 最佳实践
|
|
204
|
+
// ============================================================================
|
|
205
|
+
|
|
206
|
+
// accessor-pairs - 强制 getter/setter 成对出现(当前:error)
|
|
207
|
+
// const obj = {
|
|
208
|
+
// get x() { return this._x; },
|
|
209
|
+
// // ❌ ERROR: Getter is not paired with a setter
|
|
210
|
+
// };
|
|
211
|
+
|
|
212
|
+
// array-callback-return - 强制数组方法的回调函数有返回值(当前:error)
|
|
213
|
+
// [1, 2, 3].map(n => { // ❌ ERROR: Array.prototype.map() expects a return value from callback function
|
|
214
|
+
// console.log(n);
|
|
215
|
+
// });
|
|
216
|
+
|
|
217
|
+
// block-scoped-var - 强制变量在块作用域内使用(当前:error)
|
|
218
|
+
// for (var i = 0; i < 10; i++) {}
|
|
219
|
+
// console.log(i); // ❌ ERROR: 'i' used outside of binding context
|
|
220
|
+
|
|
221
|
+
// class-methods-use-this - 强制类方法使用 this(当前:error)
|
|
222
|
+
// class Test {
|
|
223
|
+
// method() { // ❌ ERROR: Class method 'method' does not use 'this'
|
|
224
|
+
// console.log('test');
|
|
225
|
+
// }
|
|
226
|
+
// }
|
|
227
|
+
|
|
228
|
+
// complexity - 强制代码复杂度不超过 20(当前:error)
|
|
229
|
+
// function test(a, b, c, d, e, f, g, h, i, j) {
|
|
230
|
+
// if (a) {
|
|
231
|
+
// if (b) {
|
|
232
|
+
// if (c) {
|
|
233
|
+
// if (d) {
|
|
234
|
+
// if (e) {
|
|
235
|
+
// if (f) {
|
|
236
|
+
// if (g) {
|
|
237
|
+
// if (h) {
|
|
238
|
+
// if (i) {
|
|
239
|
+
// if (j) {
|
|
240
|
+
// console.log('complex');
|
|
241
|
+
// }
|
|
242
|
+
// }
|
|
243
|
+
// }
|
|
244
|
+
// }
|
|
245
|
+
// }
|
|
246
|
+
// }
|
|
247
|
+
// }
|
|
248
|
+
// }
|
|
249
|
+
// }
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
252
|
+
|
|
253
|
+
// consistent-return - 强制 return 语句始终返回或不返回(当前:error)
|
|
254
|
+
// function test(x) {
|
|
255
|
+
// if (x) {
|
|
256
|
+
// return 1;
|
|
257
|
+
// }
|
|
258
|
+
// // ❌ ERROR: Expected to return a value at the end of function
|
|
259
|
+
// }
|
|
260
|
+
|
|
261
|
+
// curly - 强制多行语句使用大括号(当前:multi-line)
|
|
262
|
+
// if (true)
|
|
263
|
+
// console.log('test'); // ❌ ERROR: Expected { after 'if' condition
|
|
264
|
+
|
|
265
|
+
// default-case - 强制 switch 语句有 default 分支(当前:warn)
|
|
266
|
+
// switch (x) {
|
|
267
|
+
// case 1:
|
|
268
|
+
// break;
|
|
269
|
+
// // ⚠️ WARN: Expected a default case
|
|
270
|
+
// }
|
|
271
|
+
|
|
272
|
+
// default-case-last - 强制 default 分支在 switch 语句的最后(当前:error)
|
|
273
|
+
// switch (x) {
|
|
274
|
+
// default: // ❌ ERROR: Default clause should be the last clause
|
|
275
|
+
// break;
|
|
276
|
+
// case 1:
|
|
277
|
+
// break;
|
|
278
|
+
// }
|
|
279
|
+
|
|
280
|
+
// default-param-last - 强制默认参数在最后(当前:error)
|
|
281
|
+
// function test(x = 1, y) { // ❌ ERROR: Default parameters should be last
|
|
282
|
+
// }
|
|
283
|
+
|
|
284
|
+
// dot-location - 强制点号在属性名称之前(当前:property)
|
|
285
|
+
// const obj = {};
|
|
286
|
+
// const x = obj. // ❌ ERROR: Expected dot to be on same line as property
|
|
287
|
+
// prop;
|
|
288
|
+
|
|
289
|
+
// dot-notation - 强制使用点号表示法访问属性(当前:error)
|
|
290
|
+
// const obj = {};
|
|
291
|
+
// const x = obj['prop']; // ❌ ERROR: ["prop"] is better written in dot notation
|
|
292
|
+
|
|
293
|
+
// eqeqeq - 强制使用 === 和 !==(当前:error)
|
|
294
|
+
// if (x == 1) { // ❌ ERROR: Expected '===' and instead saw '=='
|
|
295
|
+
// }
|
|
296
|
+
|
|
297
|
+
// grouped-accessor-pairs - 强制 getter/setter 分组在一起(当前:error)
|
|
298
|
+
// const obj = {
|
|
299
|
+
// get x() { return this._x; },
|
|
300
|
+
// y: 1,
|
|
301
|
+
// set x(value) { this._x = value; } // ❌ ERROR: Accessor properties should be grouped
|
|
302
|
+
// };
|
|
303
|
+
|
|
304
|
+
// guard-for-in - 强制 for-in 循环中包含 if 语句(当前:warn)
|
|
305
|
+
// for (const key in obj) { // ⚠️ WARN: The body of a for-in should be wrapped in an if statement
|
|
306
|
+
// console.log(key);
|
|
307
|
+
// }
|
|
308
|
+
|
|
309
|
+
// max-classes-per-file - 强制每个文件最多 1 个类(当前:warn)
|
|
310
|
+
// class Test1 {}
|
|
311
|
+
// class Test2 {} // ⚠️ WARN: Maximum number of classes per file exceeded
|
|
312
|
+
|
|
313
|
+
// no-caller - 禁用 arguments.caller 和 arguments.callee(当前:error)
|
|
314
|
+
// function test() {
|
|
315
|
+
// arguments.callee; // ❌ ERROR: Avoid arguments.callee
|
|
316
|
+
// }
|
|
317
|
+
|
|
318
|
+
// no-case-declarations - 禁止在 case 子句中声明变量(当前:error)
|
|
319
|
+
// switch (x) {
|
|
320
|
+
// case 1:
|
|
321
|
+
// const y = 1; // ❌ ERROR: Unexpected lexical declaration in case block
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
// no-constructor-return - 禁止在构造函数中返回值(当前:error)
|
|
325
|
+
// class Test {
|
|
326
|
+
// constructor() {
|
|
327
|
+
// return {}; // ❌ ERROR: Unexpected return statement in constructor
|
|
328
|
+
// }
|
|
329
|
+
// }
|
|
330
|
+
|
|
331
|
+
// no-div-regex - 禁止看起来像除法的正则表达式(当前:warn)
|
|
332
|
+
// const pattern = /=foo/; // ⚠️ WARN: A regular expression literal can be confused with '/='
|
|
333
|
+
|
|
334
|
+
// no-else-return - 禁止在 if 语句中的 return 后使用 else(当前:error)
|
|
335
|
+
// function test(x) {
|
|
336
|
+
// if (x) {
|
|
337
|
+
// return 1;
|
|
338
|
+
// } else { // ❌ ERROR: Unnecessary 'else' after 'return'
|
|
339
|
+
// return 2;
|
|
340
|
+
// }
|
|
341
|
+
// }
|
|
342
|
+
|
|
343
|
+
// no-empty-function - 禁止空函数(当前:warn)
|
|
344
|
+
// function test() {} // ⚠️ WARN: Unexpected empty function
|
|
345
|
+
|
|
346
|
+
// no-empty-pattern - 禁止空的解构模式(当前:error)
|
|
347
|
+
// const {} = obj; // ❌ ERROR: Unexpected empty destructuring pattern
|
|
348
|
+
|
|
349
|
+
// no-eq-null - 禁止与 null 进行比较(当前:error)
|
|
350
|
+
// if (x == null) { // ❌ ERROR: Use '===' to compare with null
|
|
351
|
+
// }
|
|
352
|
+
|
|
353
|
+
// no-eval - 禁用 eval()(当前:error)
|
|
354
|
+
// eval('console.log("test")'); // ❌ ERROR: eval can be harmful
|
|
355
|
+
|
|
356
|
+
// no-extend-native - 禁止扩展原生对象(当前:error)
|
|
357
|
+
// Array.prototype.test = function() {}; // ❌ ERROR: Do not extend native prototypes
|
|
358
|
+
|
|
359
|
+
// no-extra-bind - 禁止不必要的 bind()(当前:error)
|
|
360
|
+
// function test() {
|
|
361
|
+
// console.log(this);
|
|
362
|
+
// }
|
|
363
|
+
// test.bind(this)(); // ❌ ERROR: The function binding is unnecessary
|
|
364
|
+
|
|
365
|
+
// no-extra-label - 禁止不必要的标签(当前:error)
|
|
366
|
+
// loop: while (true) { // ❌ ERROR: Unused label
|
|
367
|
+
// break;
|
|
368
|
+
// }
|
|
369
|
+
|
|
370
|
+
// no-fallthrough - 禁止 switch 语句中的 fallthrough(当前:error)
|
|
371
|
+
// switch (x) {
|
|
372
|
+
// case 1:
|
|
373
|
+
// console.log(1);
|
|
374
|
+
// case 2: // ❌ ERROR: Expected a 'break' statement before 'case'
|
|
375
|
+
// console.log(2);
|
|
376
|
+
// }
|
|
377
|
+
|
|
378
|
+
// no-floating-decimal - 禁止浮点小数(当前:error)
|
|
379
|
+
// const x = .5; // ❌ ERROR: A leading decimal point can be confused with a dot
|
|
380
|
+
|
|
381
|
+
// no-global-assign - 禁止赋值给全局变量(当前:error)
|
|
382
|
+
// window = {}; // ❌ ERROR: Do not assign to read-only global variables
|
|
383
|
+
|
|
384
|
+
// no-implicit-coercion - 禁止隐式类型转换(当前:error)
|
|
385
|
+
// const x = '5'; // ❌ ERROR: Unexpected implicit coercion
|
|
386
|
+
// const y = +x; // ❌ ERROR: Unexpected implicit coercion
|
|
387
|
+
// const z = x - 0; // ❌ ERROR: Unexpected implicit coercion
|
|
388
|
+
|
|
389
|
+
// no-implied-eval - 禁止类似 eval 的方法(当前:error)
|
|
390
|
+
// setTimeout('console.log("test")', 100); // ❌ ERROR: Implied eval. Consider passing a function instead of a string
|
|
391
|
+
|
|
392
|
+
// no-invalid-this - 禁止在类之外使用 this(当前:warn)
|
|
393
|
+
// function test() { // ⚠️ WARN: Unexpected 'this'
|
|
394
|
+
// console.log(this);
|
|
395
|
+
// }
|
|
396
|
+
|
|
397
|
+
// no-iterator - 禁用 __iterator__ 属性(当前:error)
|
|
398
|
+
// const obj = {};
|
|
399
|
+
// obj.__iterator__ = function() {}; // ❌ ERROR: __iterator__ is a deprecated property
|
|
400
|
+
|
|
401
|
+
// no-labels - 禁用标签语句(当前:error)
|
|
402
|
+
// loop: for (let i = 0; i < 10; i++) { // ❌ ERROR: Label 'loop' is defined but never used
|
|
403
|
+
// if (i === 5) break loop;
|
|
404
|
+
// }
|
|
405
|
+
|
|
406
|
+
// no-lone-blocks - 禁止不必要的嵌套块(当前:error)
|
|
407
|
+
// {
|
|
408
|
+
// const x = 1; // ❌ ERROR: Block is nested inside another block
|
|
409
|
+
// }
|
|
410
|
+
|
|
411
|
+
// no-loop-func - 禁止在循环中声明函数(当前:error)
|
|
412
|
+
// for (let i = 0; i < 10; i++) {
|
|
413
|
+
// function test() { // ❌ ERROR: Function declared in a loop contains unsafe references to variable(s) 'i'
|
|
414
|
+
// console.log(i);
|
|
415
|
+
// }
|
|
416
|
+
// }
|
|
417
|
+
|
|
418
|
+
// no-magic-numbers - 禁止魔术数字(当前:off)
|
|
419
|
+
// const x = 42; // ✅ OK: rule is off
|
|
420
|
+
|
|
421
|
+
// no-multi-spaces - 禁止多个空格(当前:error)
|
|
422
|
+
// const x = 1; // ❌ ERROR: Multiple spaces found before '='
|
|
423
|
+
|
|
424
|
+
// no-multi-str - 禁止多行字符串(当前:error)
|
|
425
|
+
// const str = 'line1\
|
|
426
|
+
// line2'; // ❌ ERROR: Multiline support is limited
|
|
427
|
+
|
|
428
|
+
// no-new - 禁止使用 new 而不赋值(当前:error)
|
|
429
|
+
// new Date(); // ❌ ERROR: Do not use 'new' for side effects
|
|
430
|
+
|
|
431
|
+
// no-new-func - 禁止使用 new Function(当前:error)
|
|
432
|
+
// const fn = new Function('x', 'return x'); // ❌ ERROR: The Function constructor is eval
|
|
433
|
+
|
|
434
|
+
// no-new-wrappers - 禁止使用 new 包装基本类型(当前:error)
|
|
435
|
+
// const str = new String('test'); // ❌ ERROR: Do not use String as a constructor
|
|
436
|
+
|
|
437
|
+
// no-nonoctal-decimal-escape - 禁止八进制转义序列(当前:error)
|
|
438
|
+
// const str = '\50'; // ❌ ERROR: Don't use octal escape sequences
|
|
439
|
+
|
|
440
|
+
// no-octal-escape - 禁止八进制转义序列(当前:error)
|
|
441
|
+
// const str = '\1'; // ❌ ERROR: Don't use octal escape sequences
|
|
442
|
+
|
|
443
|
+
// no-param-reassign - 禁止重新分配函数参数(当前:error)
|
|
444
|
+
// function test(x) {
|
|
445
|
+
// x = 1; // ❌ ERROR: Assignment to function parameter 'x'
|
|
446
|
+
// }
|
|
447
|
+
|
|
448
|
+
// no-import-assign - 禁止重新分配导入(当前:error)
|
|
449
|
+
// import { test } from './test';
|
|
450
|
+
// test = function() {}; // ❌ ERROR: Read-only import
|
|
451
|
+
|
|
452
|
+
// no-proto - 禁用 __proto__ 属性(当前:error)
|
|
453
|
+
// const obj = {};
|
|
454
|
+
// obj.__proto__ = {}; // ❌ ERROR: The '__proto__' property is deprecated
|
|
455
|
+
|
|
456
|
+
// no-redeclare - 禁止变量重复声明(当前:error)
|
|
457
|
+
// let x;
|
|
458
|
+
// let x; // ❌ ERROR: 'x' is already defined
|
|
459
|
+
|
|
460
|
+
// no-restricted-properties - 禁止特定的对象属性(当前:error)
|
|
461
|
+
// function test() {
|
|
462
|
+
// arguments.callee; // ❌ ERROR: arguments.callee is deprecated
|
|
463
|
+
// }
|
|
464
|
+
// global.isNaN(1); // ❌ ERROR: Please use Number.isNaN instead
|
|
465
|
+
|
|
466
|
+
// no-return-assign - 禁止在 return 语句中赋值(当前:error)
|
|
467
|
+
// function test() {
|
|
468
|
+
// return x = 1; // ❌ ERROR: Return statement should not contain assignment
|
|
469
|
+
// }
|
|
470
|
+
|
|
471
|
+
// no-unsafe-optional-chaining - 禁止不安全的可选链(当前:error)
|
|
472
|
+
// const x = obj?.prop(); // ❌ ERROR: Can not perform 'prop()' on a possibly null value
|
|
473
|
+
|
|
474
|
+
// no-return-await - 禁止不必要的 return await(当前:error)
|
|
475
|
+
// async function test() {
|
|
476
|
+
// return await Promise.resolve(); // ❌ ERROR: Redundant use of 'await' on a return value
|
|
477
|
+
// }
|
|
478
|
+
|
|
479
|
+
// no-script-url - 禁止使用 javascript: url(当前:error)
|
|
480
|
+
// const url = 'javascript:void(0)'; // ❌ ERROR: Script URL is a form of eval
|
|
481
|
+
|
|
482
|
+
// no-self-compare - 禁止自身比较(当前:error)
|
|
483
|
+
// if (x === x) { // ❌ ERROR: Comparing 'x' to itself
|
|
484
|
+
// }
|
|
485
|
+
|
|
486
|
+
// no-sequences - 禁止逗号运算符(当前:error)
|
|
487
|
+
// const x = (1, 2); // ❌ ERROR: Unexpected use of comma operator
|
|
488
|
+
|
|
489
|
+
// no-throw-literal - 禁止抛出字面量异常(当前:error)
|
|
490
|
+
// throw 'error'; // ❌ ERROR: Expected an object to be thrown
|
|
491
|
+
|
|
492
|
+
// no-unmodified-loop-condition - 禁止未修改的循环条件(当前:warn)
|
|
493
|
+
// let x = true;
|
|
494
|
+
// while (x) { // ⚠️ WARN: 'x' is not modified in this loop
|
|
495
|
+
// console.log('test');
|
|
496
|
+
// }
|
|
497
|
+
|
|
498
|
+
// no-unused-expressions - 禁止未使用的表达式(当前:error)
|
|
499
|
+
// 1 + 2; // ❌ ERROR: Expected an assignment or function call
|
|
500
|
+
// x || y; // ✅ OK: allowShortCircuit: true
|
|
501
|
+
// x ? y : z; // ✅ OK: allowTernary: true
|
|
502
|
+
|
|
503
|
+
// no-useless-backreference - 禁止正则表达式中的无用反向引用(当前:error)
|
|
504
|
+
// const pattern = /(a)\1/; // ❌ ERROR: Useless backreference
|
|
505
|
+
|
|
506
|
+
// no-useless-call - 禁止不必要的 call() 和 apply()(当前:error)
|
|
507
|
+
// function test() {
|
|
508
|
+
// console.log(this);
|
|
509
|
+
// }
|
|
510
|
+
// test.call(this); // ❌ ERROR: Unnecessary use of .call()
|
|
511
|
+
|
|
512
|
+
// no-useless-catch - 禁止不必要的 catch(当前:error)
|
|
513
|
+
// try {
|
|
514
|
+
// throw new Error();
|
|
515
|
+
// } catch (e) { // ❌ ERROR: Unnecessary catch clause
|
|
516
|
+
// throw e;
|
|
517
|
+
// }
|
|
518
|
+
|
|
519
|
+
// no-useless-concat - 禁止不必要的字符串连接(当前:error)
|
|
520
|
+
// const str = 'a' + 'b'; // ❌ ERROR: Unexpected concatenation of literals
|
|
521
|
+
|
|
522
|
+
// no-useless-return - 禁止不必要的 return(当前:error)
|
|
523
|
+
// function test() {
|
|
524
|
+
// return; // ❌ ERROR: Unnecessary return statement
|
|
525
|
+
// }
|
|
526
|
+
|
|
527
|
+
// no-void - 禁用 void 运算符(当前:error)
|
|
528
|
+
// void 0; // ❌ ERROR: Unexpected 'void' expression
|
|
529
|
+
|
|
530
|
+
// no-warning-comments - 禁止特定的警告注释(当前:off)
|
|
531
|
+
// TODO: fix this // ✅ OK: rule is off
|
|
532
|
+
|
|
533
|
+
// prefer-promise-reject-errors - 要求在 Promise.reject 中使用 Error 对象(当前:error)
|
|
534
|
+
// Promise.reject('error'); // ❌ ERROR: Expected an error object to be rejected
|
|
535
|
+
// ✅ Correct: Promise.reject(new Error('error'));
|
|
536
|
+
|
|
537
|
+
// prefer-regex-literals - 要求使用正则字面量而不是 RegExp 构造函数(当前:error)
|
|
538
|
+
// const pattern = new RegExp('test'); // ❌ ERROR: Use a regular expression literal instead
|
|
539
|
+
// ✅ Correct: const pattern = /test/;
|
|
540
|
+
|
|
541
|
+
// require-await - 禁止使用 async 函数而没有 await(当前:error)
|
|
542
|
+
// async function test() { // ❌ ERROR: Async function 'test' has no 'await' expression
|
|
543
|
+
// return 1;
|
|
544
|
+
// }
|
|
545
|
+
|
|
546
|
+
// require-unicode-regexp - 要求正则表达式使用 u 标志(当前:warn)
|
|
547
|
+
// const pattern = /test/; // ⚠️ WARN: Please use the 'u' flag
|
|
548
|
+
|
|
549
|
+
// vars-on-top - 要求变量声明在顶部(当前:warn)
|
|
550
|
+
// function test() {
|
|
551
|
+
// console.log('test');
|
|
552
|
+
// let x = 1; // ⚠️ WARN: All 'var' declarations must be at the top of the function scope
|
|
553
|
+
// }
|
|
554
|
+
|
|
555
|
+
// wrap-iife - 要求 IIFE 使用括号包裹(当前:error)
|
|
556
|
+
// (function () { // ❌ ERROR: Wrap an immediate function invocation in parentheses
|
|
557
|
+
// console.log('test');
|
|
558
|
+
// })();
|
|
559
|
+
|
|
560
|
+
// yoda - 要求或禁止 Yoda 条件(当前:error)
|
|
561
|
+
// if (1 === x) { // ❌ ERROR: Expected literal to be on the right side of '==='
|
|
562
|
+
// }
|
|
563
|
+
|
|
564
|
+
// ============================================================================
|
|
565
|
+
// Variables - 变量
|
|
566
|
+
// ============================================================================
|
|
567
|
+
|
|
568
|
+
// init-declarations - 要求或禁止变量声明初始化(当前:off)
|
|
569
|
+
// let x; // ✅ OK: rule is off
|
|
570
|
+
|
|
571
|
+
// no-delete-var - 禁止删除变量(当前:error)
|
|
572
|
+
// let x = 1;
|
|
573
|
+
// delete x; // ❌ ERROR: Variables should not be deleted
|
|
574
|
+
|
|
575
|
+
// no-label-var - 禁止标签变量名与作用域内变量同名(当前:error)
|
|
576
|
+
// let x;
|
|
577
|
+
// x: for (let i = 0; i < 10; i++) { // ❌ ERROR: Label 'x' is already declared
|
|
578
|
+
// }
|
|
579
|
+
|
|
580
|
+
// no-restricted-globals - 禁止特定的全局变量(当前:error)
|
|
581
|
+
// isFinite(1); // ❌ ERROR: Use Number.isFinite instead
|
|
582
|
+
// isNaN(1); // ❌ ERROR: Use Number.isNaN instead
|
|
583
|
+
|
|
584
|
+
// no-shadow - 禁止变量声明与外层作用域变量同名(当前:error)
|
|
585
|
+
// let x = 1;
|
|
586
|
+
// function test() {
|
|
587
|
+
// let x = 2; // ❌ ERROR: 'x' is already declared in the upper scope
|
|
588
|
+
// }
|
|
589
|
+
|
|
590
|
+
// no-shadow-restricted-names - 禁止使用受限名称作为变量名(当前:error)
|
|
591
|
+
// let NaN = 1; // ❌ ERROR: Shadowing of global property 'NaN'
|
|
592
|
+
|
|
593
|
+
// no-undef - 禁止使用未声明的变量(当前:error)
|
|
594
|
+
// console.log(undefinedVar); // ❌ ERROR: 'undefinedVar' is not defined
|
|
595
|
+
|
|
596
|
+
// no-undef-init - 禁止初始化变量为 undefined(当前:warn)
|
|
597
|
+
// let x = undefined; // ⚠️ WARN: It's not necessary to initialize 'x' to undefined
|
|
598
|
+
|
|
599
|
+
// no-undefined - 禁止使用 undefined(当前:off)
|
|
600
|
+
// if (x === undefined) { // ✅ OK: rule is off
|
|
601
|
+
// }
|
|
602
|
+
|
|
603
|
+
// no-unused-vars - 禁止未使用的变量(当前:error)
|
|
604
|
+
// let x = 1; // ❌ ERROR: 'x' is assigned a value but never used
|
|
605
|
+
|
|
606
|
+
// no-use-before-define - 禁止在定义前使用变量(当前:error)
|
|
607
|
+
// console.log(x); // ❌ ERROR: 'x' was used before it was defined
|
|
608
|
+
// let x = 1;
|
|
609
|
+
|
|
610
|
+
// ============================================================================
|
|
611
|
+
// Node.js and CommonJS - Node.js 和 CommonJS
|
|
612
|
+
// ============================================================================
|
|
613
|
+
|
|
614
|
+
// no-buffer-constructor - 禁止使用 Buffer() 构造函数(当前:error)
|
|
615
|
+
// const buffer = new Buffer(10); // ❌ ERROR: Buffer() is deprecated
|
|
616
|
+
|
|
617
|
+
// no-mixed-requires - 禁止混合 require 声明(当前:error)
|
|
618
|
+
// const fs = require('fs');
|
|
619
|
+
// const path = require('path'); // ❌ ERROR: Do not mix core and module requires
|
|
620
|
+
|
|
621
|
+
// no-new-require - 禁止使用 new require(当前:error)
|
|
622
|
+
// const test = new require('test'); // ❌ ERROR: Do not use new with require
|
|
623
|
+
|
|
624
|
+
// no-path-concat - 禁止使用 __dirname 和 __filename 进行字符串连接(当前:error)
|
|
625
|
+
// const path = __dirname + '/test'; // ❌ ERROR: Use path.join() or path.resolve() instead of concatenation
|
|
626
|
+
|
|
627
|
+
// no-process-env - 禁止直接使用 process.env(当前:warn)
|
|
628
|
+
// const port = process.env.PORT; // ⚠️ WARN: Do not use process.env
|
|
629
|
+
|
|
630
|
+
// no-process-exit - 禁止使用 process.exit()(当前:warn)
|
|
631
|
+
// process.exit(1); // ⚠️ WARN: Don't use process.exit()
|
|
632
|
+
|
|
633
|
+
// no-restricted-modules - 禁止特定的模块(当前:off)
|
|
634
|
+
// const sys = require('sys'); // ✅ OK: rule is off
|
|
635
|
+
|
|
636
|
+
// no-sync - 禁止同步方法(当前:warn)
|
|
637
|
+
// const data = fs.readFileSync('test.txt'); // ⚠️ WARN: Unexpected sync method
|
|
638
|
+
|
|
639
|
+
// ============================================================================
|
|
640
|
+
// Stylistic Issues - 代码风格
|
|
641
|
+
// ============================================================================
|
|
642
|
+
|
|
643
|
+
// array-bracket-newline - 强制数组括号换行(当前:off)
|
|
644
|
+
// const arr = [
|
|
645
|
+
// 1,
|
|
646
|
+
// 2,
|
|
647
|
+
// ]; // ✅ OK: rule is off
|
|
648
|
+
|
|
649
|
+
// array-bracket-spacing - 强制数组括号内无空格(当前:error)
|
|
650
|
+
// const arr = [ 1, 2 ]; // ❌ ERROR: There should be no space after '['
|
|
651
|
+
|
|
652
|
+
// array-element-newline - 强制数组元素换行(当前:off)
|
|
653
|
+
// const arr = [1, 2, 3]; // ✅ OK: rule is off
|
|
654
|
+
|
|
655
|
+
// block-spacing - 强制块内空格(当前:error)
|
|
656
|
+
// if (true){console.log('test');} // ❌ ERROR: Expected a space before this brace
|
|
657
|
+
|
|
658
|
+
// brace-style - 强制大括号风格(当前:1TBS)
|
|
659
|
+
// if (true)
|
|
660
|
+
// {
|
|
661
|
+
// console.log('test');
|
|
662
|
+
// } // ❌ ERROR: Opening curly brace does not appear on the same line as controlling statement
|
|
663
|
+
|
|
664
|
+
// camelcase - 强制使用驼峰命名(当前:error)
|
|
665
|
+
// const my_var = 1; // ❌ ERROR: Identifier 'my_var' is not in camel case
|
|
666
|
+
|
|
667
|
+
// capitalized-comments - 强制注释首字母大写(当前:off)
|
|
668
|
+
// // this is a comment // ✅ OK: rule is off
|
|
669
|
+
|
|
670
|
+
// comma-dangle - 强制或禁止尾随逗号(当前:error)
|
|
671
|
+
// const obj = { a: 1, b: 2 }; // ❌ ERROR: Missing trailing comma
|
|
672
|
+
// ✅ Correct: const obj = { a: 1, b: 2, };
|
|
673
|
+
|
|
674
|
+
// comma-spacing - 强制逗号前后空格(当前:error)
|
|
675
|
+
// const arr = [1,2]; // ❌ ERROR: A space is required after ','
|
|
676
|
+
// const arr = [1 , 2]; // ❌ ERROR: There should be no space before ','
|
|
677
|
+
|
|
678
|
+
// comma-style - 强制逗号在行尾(当前:error)
|
|
679
|
+
// const arr = [
|
|
680
|
+
// 1
|
|
681
|
+
// , 2 // ❌ ERROR: A comma is not allowed after array element
|
|
682
|
+
// ];
|
|
683
|
+
|
|
684
|
+
// computed-property-spacing - 强制计算属性括号内无空格(当前:error)
|
|
685
|
+
// const obj = { [ 'key' ]: 1 }; // ❌ ERROR: There should be no space inside computed property brackets
|
|
686
|
+
|
|
687
|
+
// consistent-this - 强制 this 别名一致(当前:off)
|
|
688
|
+
// const self = this;
|
|
689
|
+
// const that = this; // ✅ OK: rule is off
|
|
690
|
+
|
|
691
|
+
// eol-last - 强制文件末尾换行(当前:error)
|
|
692
|
+
// // ❌ ERROR: Newline required at end of file but not found
|
|
693
|
+
|
|
694
|
+
// func-call-spacing - 强制函数调用时括号前无空格(当前:error)
|
|
695
|
+
// test (); // ❌ ERROR: Unexpected space between function name and paren
|
|
696
|
+
|
|
697
|
+
// func-name-matching - 强制函数名与赋值的变量名匹配(当前:error)
|
|
698
|
+
// const test = function name() {}; // ❌ ERROR: Function name 'name' should match variable name 'test'
|
|
699
|
+
|
|
700
|
+
// func-names - 要求或禁止函数命名(当前:off)
|
|
701
|
+
// const test = function() {}; // ✅ OK: rule is off
|
|
702
|
+
|
|
703
|
+
// func-style - 强制使用函数声明或表达式(当前:off)
|
|
704
|
+
// const test = function() {}; // ✅ OK: rule is off
|
|
705
|
+
|
|
706
|
+
// function-call-argument-newline - 强制函数调用参数换行(当前:off)
|
|
707
|
+
// test(1, 2, 3); // ✅ OK: rule is off
|
|
708
|
+
|
|
709
|
+
// function-paren-newline - 强制函数括号换行(当前:off)
|
|
710
|
+
// function test() {} // ✅ OK: rule is off
|
|
711
|
+
|
|
712
|
+
// id-denylist - 禁止特定的标识符(当前:off)
|
|
713
|
+
// const foo = 1; // ✅ OK: rule is off
|
|
714
|
+
|
|
715
|
+
// id-length - 强制标识符最小和最大长度(当前:off)
|
|
716
|
+
// const x = 1; // ✅ OK: rule is off
|
|
717
|
+
|
|
718
|
+
// id-match - 强制标识符匹配正则表达式(当前:off)
|
|
719
|
+
// const test = 1; // ✅ OK: rule is off
|
|
720
|
+
|
|
721
|
+
// implicit-arrow-linebreak - 强制箭头函数的箭头与参数在同一行(当前:error)
|
|
722
|
+
// const test =
|
|
723
|
+
// () => {}; // ❌ ERROR: Unexpected line break after this arrow
|
|
724
|
+
|
|
725
|
+
// indent - 强制缩进(当前:off)
|
|
726
|
+
// function test() {
|
|
727
|
+
// const x = 1; // ✅ OK: rule is off
|
|
728
|
+
// }
|
|
729
|
+
|
|
730
|
+
// jsx-quotes - 强制 JSX 引号(当前:off)
|
|
731
|
+
// // ✅ OK: rule is off
|
|
732
|
+
|
|
733
|
+
// key-spacing - 强制对象属性键冒号前后空格(当前:error)
|
|
734
|
+
// const obj = { key : 1 }; // ❌ ERROR: There should be no space before ':'
|
|
735
|
+
// const obj = { key: 1 }; // ❌ ERROR: A space is required after ':'
|
|
736
|
+
|
|
737
|
+
// keyword-spacing - 强制关键字前后空格(当前:error)
|
|
738
|
+
// if(true) {} // ❌ ERROR: Missing space before '('
|
|
739
|
+
// if (true ) {} // ❌ ERROR: Unexpected space after ')'
|
|
740
|
+
|
|
741
|
+
// line-comment-position - 强制行注释位置(当前:off)
|
|
742
|
+
// const x = 1; // comment // ✅ OK: rule is off
|
|
743
|
+
|
|
744
|
+
// linebreak-style - 强制换行符风格(当前:error)
|
|
745
|
+
// // ❌ ERROR: Expected linebreaks to be 'LF' but found 'CRLF'
|
|
746
|
+
|
|
747
|
+
// lines-around-comment - 强制注释周围空行(当前:off)
|
|
748
|
+
// const x = 1;
|
|
749
|
+
// // comment
|
|
750
|
+
// const y = 2; // ✅ OK: rule is off
|
|
751
|
+
|
|
752
|
+
// lines-between-class-members - 强制类成员之间空行(当前:error)
|
|
753
|
+
// class Test {
|
|
754
|
+
// method1() {}
|
|
755
|
+
// method2() {} // ❌ ERROR: Expected blank line between class members
|
|
756
|
+
// }
|
|
757
|
+
|
|
758
|
+
// max-depth - 强制最大嵌套深度(当前:off)
|
|
759
|
+
// function test() {
|
|
760
|
+
// if (true) {
|
|
761
|
+
// if (true) {
|
|
762
|
+
// if (true) { // ✅ OK: rule is off
|
|
763
|
+
// }
|
|
764
|
+
// }
|
|
765
|
+
// }
|
|
766
|
+
// }
|
|
767
|
+
|
|
768
|
+
// max-len - 强制最大行长度(当前:off)
|
|
769
|
+
// const x = 'very long string that exceeds the maximum line length limit'; // ✅ OK: rule is off
|
|
770
|
+
|
|
771
|
+
// max-lines - 强制文件最大行数(当前:off)
|
|
772
|
+
// // ✅ OK: rule is off
|
|
773
|
+
|
|
774
|
+
// max-lines-per-function - 强制函数最大行数(当前:off)
|
|
775
|
+
// function test() {
|
|
776
|
+
// // many lines
|
|
777
|
+
// } // ✅ OK: rule is off
|
|
778
|
+
|
|
779
|
+
// max-nested-callbacks - 强制最大回调嵌套深度(当前:off)
|
|
780
|
+
// async(function() {
|
|
781
|
+
// async(function() { // ✅ OK: rule is off
|
|
782
|
+
// });
|
|
783
|
+
// });
|
|
784
|
+
|
|
785
|
+
// max-params - 强制函数最大参数数量(当前:off)
|
|
786
|
+
// function test(a, b, c, d, e, f) {} // ✅ OK: rule is off
|
|
787
|
+
|
|
788
|
+
// max-statements - 强制函数最大语句数量(当前:off)
|
|
789
|
+
// function test() {
|
|
790
|
+
// const a = 1;
|
|
791
|
+
// const b = 2;
|
|
792
|
+
// // many statements
|
|
793
|
+
// } // ✅ OK: rule is off
|
|
794
|
+
|
|
795
|
+
// max-statements-per-line - 强制每行最大语句数量(当前:error)
|
|
796
|
+
// const a = 1; const b = 2; // ❌ ERROR: This line has a maximum statement count of 1
|
|
797
|
+
|
|
798
|
+
// multiline-comment-style - 强制多行注释风格(当前:off)
|
|
799
|
+
// /**
|
|
800
|
+
// * comment
|
|
801
|
+
// */ // ✅ OK: rule is off
|
|
802
|
+
|
|
803
|
+
// multiline-ternary - 强制三元运算符换行(当前:off)
|
|
804
|
+
// const result = condition
|
|
805
|
+
// ? value1
|
|
806
|
+
// : value2; // ✅ OK: rule is off
|
|
807
|
+
|
|
808
|
+
// new-cap - 强制构造函数首字母大写(当前:error)
|
|
809
|
+
// const test = new testClass(); // ❌ ERROR: A constructor name should start with an uppercase letter
|
|
810
|
+
|
|
811
|
+
// new-parens - 强制 new 时使用括号(当前:error)
|
|
812
|
+
// const date = new Date; // ❌ ERROR: Missing '()' invoking a constructor
|
|
813
|
+
|
|
814
|
+
// newline-per-chained-call - 强制链式调用换行(当前:off)
|
|
815
|
+
// obj.method1().method2().method3(); // ✅ OK: rule is off
|
|
816
|
+
|
|
817
|
+
// no-array-constructor - 禁止使用 Array 构造函数(当前:error)
|
|
818
|
+
// const arr = new Array(1, 2, 3); // ❌ ERROR: The array literal notation [] is preferable
|
|
819
|
+
|
|
820
|
+
// no-bitwise - 禁止位运算符(当前:warn)
|
|
821
|
+
// const x = 1 | 2; // ⚠️ WARN: Unexpected use of '|'
|
|
822
|
+
|
|
823
|
+
// no-continue - 禁止 continue 语句(当前:warn)
|
|
824
|
+
// for (let i = 0; i < 10; i++) {
|
|
825
|
+
// if (i === 5) continue; // ⚠️ WARN: Unexpected use of 'continue'
|
|
826
|
+
// }
|
|
827
|
+
|
|
828
|
+
// no-inline-comments - 禁止行内注释(当前:off)
|
|
829
|
+
// const x = 1; // comment // ✅ OK: rule is off
|
|
830
|
+
|
|
831
|
+
// no-lonely-if - 禁止 if 语句作为 else 块的唯一语句(当前:error)
|
|
832
|
+
// if (x) {
|
|
833
|
+
// console.log('x');
|
|
834
|
+
// } else {
|
|
835
|
+
// if (y) { // ❌ ERROR: Unexpected if as the only statement in an else block
|
|
836
|
+
// console.log('y');
|
|
837
|
+
// }
|
|
838
|
+
// }
|
|
839
|
+
|
|
840
|
+
// no-mixed-operators - 禁止混合运算符(当前:error)
|
|
841
|
+
// const x = a && b || c; // ❌ ERROR: Unexpected mix of '&&' and '||'
|
|
842
|
+
|
|
843
|
+
// no-mixed-spaces-and-tabs - 禁止混合空格和制表符(当前:error)
|
|
844
|
+
// const x = 1; // ❌ ERROR: Mixed spaces and tabs
|
|
845
|
+
|
|
846
|
+
// no-multi-assign - 禁止链式变量赋值(当前:warn)
|
|
847
|
+
// let a = b = c = 1; // ⚠️ WARN: Unexpected chained assignment
|
|
848
|
+
|
|
849
|
+
// no-multiple-empty-lines - 禁止多个空行(当前:error)
|
|
850
|
+
// const x = 1;
|
|
851
|
+
//
|
|
852
|
+
//
|
|
853
|
+
// const y = 2; // ❌ ERROR: Too many blank lines
|
|
854
|
+
|
|
855
|
+
// no-negated-condition - 禁止否定条件(当前:off)
|
|
856
|
+
// if (!x) { // ✅ OK: rule is off
|
|
857
|
+
// }
|
|
858
|
+
|
|
859
|
+
// no-nested-ternary - 禁止嵌套三元运算符(当前:error)
|
|
860
|
+
// const result = condition1 ? (condition2 ? value1 : value2) : value3; // ❌ ERROR: Do not nest ternary expressions
|
|
861
|
+
|
|
862
|
+
// no-new-object - 禁止使用 Object 构造函数(当前:error)
|
|
863
|
+
// const obj = new Object(); // ❌ ERROR: The object literal notation {} is preferable
|
|
864
|
+
|
|
865
|
+
// no-plusplus - 禁止一元运算符 ++ 和 --(当前:off)
|
|
866
|
+
// let x = 1;
|
|
867
|
+
// x++; // ✅ OK: rule is off
|
|
868
|
+
|
|
869
|
+
// no-restricted-syntax - 禁止特定的语法(当前:error)
|
|
870
|
+
// for (const key in obj) { // ❌ ERROR: for..in loops iterate over the entire prototype chain
|
|
871
|
+
// console.log(key);
|
|
872
|
+
// }
|
|
873
|
+
// label: while (true) { // ❌ ERROR: Labels are a form of GOTO
|
|
874
|
+
// break label;
|
|
875
|
+
// }
|
|
876
|
+
// with (obj) { // ❌ ERROR: 'with' is disallowed in strict mode
|
|
877
|
+
// console.log(prop);
|
|
878
|
+
// }
|
|
879
|
+
|
|
880
|
+
// no-tabs - 禁止制表符(当前:error)
|
|
881
|
+
// const x = 1; // ❌ ERROR: Unexpected tab character
|
|
882
|
+
|
|
883
|
+
// no-ternary - 禁止三元运算符(当前:off)
|
|
884
|
+
// const result = condition ? value1 : value2; // ✅ OK: rule is off
|
|
885
|
+
|
|
886
|
+
// no-trailing-spaces - 禁止行尾空格(当前:error)
|
|
887
|
+
// const x = 1; // ❌ ERROR: Trailing spaces not allowed
|
|
888
|
+
|
|
889
|
+
// no-underscore-dangle - 禁止标识符中使用下划线(当前:off)
|
|
890
|
+
// const _private = 1; // ✅ OK: rule is off
|
|
891
|
+
|
|
892
|
+
// no-unneeded-ternary - 禁止不必要的嵌套三元运算符(当前:error)
|
|
893
|
+
// const result = x ? x : y; // ❌ ERROR: Unnecessary use of boolean literals in ternary expression
|
|
894
|
+
|
|
895
|
+
// no-whitespace-before-property - 禁止属性前空格(当前:error)
|
|
896
|
+
// const obj = {};
|
|
897
|
+
// obj .prop = 1; // ❌ ERROR: Unexpected whitespace before property
|
|
898
|
+
|
|
899
|
+
// nonblock-statement-body-position - 强制非块语句的位置(当前:error)
|
|
900
|
+
// if (true)
|
|
901
|
+
// console.log('test'); // ❌ ERROR: Expected this statement to be on a line after the previous keyword
|
|
902
|
+
|
|
903
|
+
// object-curly-newline - 强制对象大括号换行(当前:error)
|
|
904
|
+
// const obj = {
|
|
905
|
+
// a: 1
|
|
906
|
+
// , b: 2 // ❌ ERROR: Object properties must go on a new line if they are on new lines
|
|
907
|
+
// };
|
|
908
|
+
|
|
909
|
+
// object-curly-spacing - 强制对象大括号内空格(当前:error)
|
|
910
|
+
// const obj = {a: 1}; // ❌ ERROR: A space is required after '{'
|
|
911
|
+
// const obj = { a: 1 }; // ❌ ERROR: A space is required before '}'
|
|
912
|
+
|
|
913
|
+
// object-property-newline - 强制对象属性换行(当前:error)
|
|
914
|
+
// const obj = { a: 1, b: 2, c: 3 }; // ❌ ERROR: Object properties must go on a new line
|
|
915
|
+
|
|
916
|
+
// one-var - 强制每个作用域一个变量声明(当前:error)
|
|
917
|
+
// let x = 1, y = 2; // ❌ ERROR: Define one variable per assignment
|
|
918
|
+
|
|
919
|
+
// one-var-declaration-per-line - 强制每行一个变量声明(当前:error)
|
|
920
|
+
// let x = 1, y = 2; // ❌ ERROR: Declare one variable per line
|
|
921
|
+
|
|
922
|
+
// operator-assignment - 强制或禁止简化赋值运算符(当前:error)
|
|
923
|
+
// x = x + 1; // ❌ ERROR: Assignment can be replaced with operator assignment
|
|
924
|
+
|
|
925
|
+
// operator-linebreak - 强制运算符换行(当前:error)
|
|
926
|
+
// const result = a +
|
|
927
|
+
// b; // ❌ ERROR: Operator '+' should be placed at the beginning of the line
|
|
928
|
+
|
|
929
|
+
// padded-blocks - 强制块内填充空行(当前:error)
|
|
930
|
+
// function test() {
|
|
931
|
+
//
|
|
932
|
+
// console.log('test');
|
|
933
|
+
//
|
|
934
|
+
// } // ❌ ERROR: Block must not be padded by blank lines
|
|
935
|
+
|
|
936
|
+
// padding-line-between-statements - 强制语句间空行(当前:off)
|
|
937
|
+
// const x = 1;
|
|
938
|
+
// const y = 2; // ✅ OK: rule is off
|
|
939
|
+
|
|
940
|
+
// quote-props - 强制对象属性引号(当前:error)
|
|
941
|
+
// const obj = { 'key': 1 }; // ❌ ERROR: Unnecessarily quoted property 'key' found
|
|
942
|
+
|
|
943
|
+
// quotes - 强制使用单引号(当前:error)
|
|
944
|
+
// const str = "test"; // ❌ ERROR: Strings must use singlequote
|
|
945
|
+
|
|
946
|
+
// semi - 强制使用分号(当前:error)
|
|
947
|
+
// const x = 1 // ❌ ERROR: Missing semicolon
|
|
948
|
+
|
|
949
|
+
// semi-spacing - 强制分号前后空格(当前:error)
|
|
950
|
+
// const x = 1 ; // ❌ ERROR: Extra space before semicolon
|
|
951
|
+
// const x = 1; // ❌ ERROR: Missing space after semicolon
|
|
952
|
+
|
|
953
|
+
// semi-style - 强制分号位置(当前:error)
|
|
954
|
+
// const x = 1
|
|
955
|
+
// ; // ❌ ERROR: Extra semicolon
|
|
956
|
+
|
|
957
|
+
// sort-keys - 强制对象属性排序(当前:off)
|
|
958
|
+
// const obj = { b: 1, a: 2 }; // ✅ OK: rule is off
|
|
959
|
+
|
|
960
|
+
// sort-vars - 强制变量声明排序(当前:off)
|
|
961
|
+
// let b = 1;
|
|
962
|
+
// let a = 2; // ✅ OK: rule is off
|
|
963
|
+
|
|
964
|
+
// space-before-blocks - 强制块前空格(当前:error)
|
|
965
|
+
// if (true){} // ❌ ERROR: Missing space before opening brace
|
|
966
|
+
|
|
967
|
+
// space-before-function-paren - 强制函数括号前空格(当前:error)
|
|
968
|
+
// function test(){} // ❌ ERROR: Missing space before function parentheses
|
|
969
|
+
// const test = function(){}; // ❌ ERROR: Missing space before function parentheses
|
|
970
|
+
// const test = () => {}; // ❌ ERROR: Missing space before function parentheses
|
|
971
|
+
|
|
972
|
+
// space-in-parens - 强制括号内空格(当前:error)
|
|
973
|
+
// const x = ( 1 + 2 ); // ❌ ERROR: There should be no space inside this paren
|
|
974
|
+
|
|
975
|
+
// space-infix-ops - 强制运算符周围空格(当前:error)
|
|
976
|
+
// const x = 1+2; // ❌ ERROR: Operator '+' must be spaced
|
|
977
|
+
|
|
978
|
+
// space-unary-ops - 强制一元运算符前后空格(当前:error)
|
|
979
|
+
// const x = - 1; // ❌ ERROR: Unexpected space after unary operator '-'
|
|
980
|
+
|
|
981
|
+
// spaced-comment - 强制注释周围空格(当前:error)
|
|
982
|
+
// //comment // ❌ ERROR: Expected space after '//'
|
|
983
|
+
// /*comment*/ // ❌ ERROR: Expected space after '/*'
|
|
984
|
+
|
|
985
|
+
// switch-colon-spacing - 强制 switch 冒号前后空格(当前:error)
|
|
986
|
+
// switch (x) {
|
|
987
|
+
// case 1: // ❌ ERROR: Expected space after ':'
|
|
988
|
+
// break;
|
|
989
|
+
// }
|
|
990
|
+
|
|
991
|
+
// template-tag-spacing - 强制模板标签空格(当前:error)
|
|
992
|
+
// const fn = (strings) => strings;
|
|
993
|
+
// fn `test`; // ❌ ERROR: Unexpected space between template tag and template literal
|
|
994
|
+
|
|
995
|
+
// unicode-bom - 强制或禁止 Unicode BOM(当前:error)
|
|
996
|
+
// // ❌ ERROR: Unexpected Unicode BOM (Byte Order Mark)
|
|
997
|
+
|
|
998
|
+
// wrap-regex - 强制正则表达式换行(当前:off)
|
|
999
|
+
// const pattern = /^test$/; // ✅ OK: rule is off
|
|
1000
|
+
|
|
1001
|
+
// ============================================================================
|
|
1002
|
+
// ECMAScript 6 - ES6+
|
|
1003
|
+
// ============================================================================
|
|
1004
|
+
|
|
1005
|
+
// arrow-body-style - 强制箭头函数函数体风格(当前:as-needed)
|
|
1006
|
+
// const test = () => { return 1; }; // ❌ ERROR: Unexpected block statement surrounding arrow body
|
|
1007
|
+
|
|
1008
|
+
// arrow-parens - 强制箭头函数参数使用括号(当前:error)
|
|
1009
|
+
// const test = x => x; // ❌ ERROR: Expected parentheses around arrow function argument
|
|
1010
|
+
|
|
1011
|
+
// arrow-spacing - 强制箭头函数箭头前后空格(当前:error)
|
|
1012
|
+
// const test = x=>x; // ❌ ERROR: Missing space before and after arrow
|
|
1013
|
+
|
|
1014
|
+
// constructor-super - 要求构造函数中调用 super()(当前:error)
|
|
1015
|
+
// class Test extends Parent {
|
|
1016
|
+
// constructor() { // ❌ ERROR: Derived constructors must call super()
|
|
1017
|
+
// }
|
|
1018
|
+
// }
|
|
1019
|
+
|
|
1020
|
+
// generator-star-spacing - 强制生成器函数星号位置(当前:error)
|
|
1021
|
+
// function* test() {} // ❌ ERROR: Missing space before * in generator
|
|
1022
|
+
|
|
1023
|
+
// no-class-assign - 禁止重新分配类声明(当前:error)
|
|
1024
|
+
// class Test {}
|
|
1025
|
+
// Test = function() {}; // ❌ ERROR: 'Test' is read-only
|
|
1026
|
+
|
|
1027
|
+
// no-confusing-arrow - 禁止可能与比较运算符混淆的箭头函数(当前:error)
|
|
1028
|
+
// const x = x => (1 ? 2 : 3); // ❌ ERROR: Arrow function used ambiguously with a conditional expression
|
|
1029
|
+
|
|
1030
|
+
// no-const-assign - 禁止重新分配 const 变量(当前:error)
|
|
1031
|
+
// const x = 1;
|
|
1032
|
+
// x = 2; // ❌ ERROR: 'x' is constant
|
|
1033
|
+
|
|
1034
|
+
// no-dupe-class-members - 禁止类成员重复(当前:error)
|
|
1035
|
+
// class Test {
|
|
1036
|
+
// method() {}
|
|
1037
|
+
// method() {} // ❌ ERROR: Duplicate member 'method'
|
|
1038
|
+
// }
|
|
1039
|
+
|
|
1040
|
+
// no-duplicate-imports - 禁止重复导入(当前:error)
|
|
1041
|
+
// import { a } from './test';
|
|
1042
|
+
// import { b } from './test'; // ❌ ERROR: Duplicate import
|
|
1043
|
+
|
|
1044
|
+
// no-new-symbol - 禁止使用 new Symbol(当前:error)
|
|
1045
|
+
// const sym = new Symbol('test'); // ❌ ERROR: Symbol is not a constructor
|
|
1046
|
+
|
|
1047
|
+
// no-restricted-exports - 禁止特定的导出(当前:off)
|
|
1048
|
+
// export { a }; // ✅ OK: rule is off
|
|
1049
|
+
|
|
1050
|
+
// no-restricted-imports - 禁止特定的导入(当前:off)
|
|
1051
|
+
// import { a } from './test'; // ✅ OK: rule is off
|
|
1052
|
+
|
|
1053
|
+
// no-this-before-super - 禁止在调用 super() 之前使用 this(当前:error)
|
|
1054
|
+
// class Test extends Parent {
|
|
1055
|
+
// constructor() {
|
|
1056
|
+
// this.x = 1; // ❌ ERROR: 'this' is not allowed before super()
|
|
1057
|
+
// super();
|
|
1058
|
+
// }
|
|
1059
|
+
// }
|
|
1060
|
+
|
|
1061
|
+
// no-useless-computed-key - 禁止不必要的计算属性键(当前:error)
|
|
1062
|
+
// const obj = { ['key']: 1 }; // ❌ ERROR: Unnecessarily computed property key found
|
|
1063
|
+
|
|
1064
|
+
// no-useless-constructor - 禁止不必要的构造函数(当前:error)
|
|
1065
|
+
// class Test {
|
|
1066
|
+
// constructor() {} // ❌ ERROR: Useless constructor
|
|
1067
|
+
// }
|
|
1068
|
+
|
|
1069
|
+
// no-useless-rename - 禁止解构时重命名(当前:error)
|
|
1070
|
+
// const { a: a } = obj; // ❌ ERROR: Useless renaming
|
|
1071
|
+
|
|
1072
|
+
// no-var - 禁止使用 var(当前:error)
|
|
1073
|
+
// var x = 1; // ❌ ERROR: Unexpected var, use let or const instead
|
|
1074
|
+
|
|
1075
|
+
// object-shorthand - 强制或禁止对象属性简写(当前:error)
|
|
1076
|
+
// const obj = { x: x }; // ❌ ERROR: Expected property shorthand
|
|
1077
|
+
|
|
1078
|
+
// prefer-arrow-callback - 要求使用箭头函数作为回调(当前:error)
|
|
1079
|
+
// arr.map(function(x) { // ❌ ERROR: Unexpected function expression
|
|
1080
|
+
// return x;
|
|
1081
|
+
// });
|
|
1082
|
+
|
|
1083
|
+
// prefer-const - 要求使用 const 声明不会被重新赋值的变量(当前:error)
|
|
1084
|
+
// let x = 1; // ❌ ERROR: 'x' is never reassigned. Use 'const' instead
|
|
1085
|
+
|
|
1086
|
+
// prefer-destructuring - 要求使用解构(当前:warn)
|
|
1087
|
+
// const obj = { a: 1, b: 2 };
|
|
1088
|
+
// const a = obj.a; // ⚠️ WARN: Use object destructuring
|
|
1089
|
+
|
|
1090
|
+
// prefer-exponentiation-operator - 要求使用指数运算符(当前:error)
|
|
1091
|
+
// const x = Math.pow(2, 3); // ❌ ERROR: Prefer the exponentiation operator
|
|
1092
|
+
|
|
1093
|
+
// prefer-named-capture-group - 要求使用命名捕获组(当前:off)
|
|
1094
|
+
// const pattern = /(\d+)/; // ✅ OK: rule is off
|
|
1095
|
+
|
|
1096
|
+
// prefer-numeric-literals - 要求使用数字字面量(当前:error)
|
|
1097
|
+
// const x = 0o10; // ❌ ERROR: Use decimal literal instead of Octal
|
|
1098
|
+
|
|
1099
|
+
// prefer-object-has-own - 要求使用 Object.hasOwn(当前:error)
|
|
1100
|
+
// const hasOwn = Object.prototype.hasOwnProperty.call(obj, 'key'); // ❌ ERROR: Use Object.hasOwn instead
|
|
1101
|
+
|
|
1102
|
+
// prefer-object-spread - 要求使用对象展开(当前:error)
|
|
1103
|
+
// const obj = { ...obj1, ...obj2 }; // ✅ OK: this is correct
|
|
1104
|
+
// const obj = Object.assign({}, obj1, obj2); // ❌ ERROR: Use object spread instead
|
|
1105
|
+
|
|
1106
|
+
// prefer-rest-params - 要求使用剩余参数(当前:error)
|
|
1107
|
+
// function test() { // ❌ ERROR: Use the rest parameters instead of 'arguments'
|
|
1108
|
+
// console.log(arguments);
|
|
1109
|
+
// }
|
|
1110
|
+
|
|
1111
|
+
// prefer-spread - 要求使用展开运算符(当前:error)
|
|
1112
|
+
// const arr = [1, 2, 3];
|
|
1113
|
+
// const arr2 = arr.concat([4, 5]); // ❌ ERROR: Use spread syntax instead
|
|
1114
|
+
|
|
1115
|
+
// prefer-template - 要求使用模板字面量(当前:error)
|
|
1116
|
+
// const str = 'Hello ' + name; // ❌ ERROR: Unexpected string concatenation
|
|
1117
|
+
|
|
1118
|
+
// rest-spread-spacing - 强制剩余和展开运算符周围空格(当前:error)
|
|
1119
|
+
// const arr = [... arr]; // ❌ ERROR: There should be no space after '...'
|
|
1120
|
+
|
|
1121
|
+
// sort-imports - 强制导入排序(当前:off)
|
|
1122
|
+
// import { b } from './test';
|
|
1123
|
+
// import { a } from './test'; // ✅ OK: rule is off
|
|
1124
|
+
|
|
1125
|
+
// symbol-description - 要求 Symbol 描述(当前:error)
|
|
1126
|
+
// const sym = Symbol(); // ❌ ERROR: Expected Symbol to have a description
|
|
1127
|
+
|
|
1128
|
+
// template-curly-spacing - 强制模板字面量花括号内空格(当前:error)
|
|
1129
|
+
// const str = `${ x }`; // ❌ ERROR: Unexpected space(s) inside template expression
|
|
1130
|
+
|
|
1131
|
+
// yield-star-spacing - 强制 yield* 星号位置(当前:error)
|
|
1132
|
+
// function* test() {
|
|
1133
|
+
// yield* test2(); // ❌ ERROR: Missing space before *
|
|
1134
|
+
// }
|