@huangjunsen/eslint-config 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.editorconfig +17 -0
  2. package/.eslintignore +17 -0
  3. package/.eslintrc.js +5 -0
  4. package/LICENSE +21 -0
  5. package/README.md +286 -0
  6. package/__tests__/fixtures/es5.js +4 -0
  7. package/__tests__/fixtures/index.js +3 -0
  8. package/__tests__/fixtures/node.js +24 -0
  9. package/__tests__/fixtures/react-display-name.js +7 -0
  10. package/__tests__/fixtures/react.jsx +132 -0
  11. package/__tests__/fixtures/ts-import-a.ts +3 -0
  12. package/__tests__/fixtures/ts-import-b.ts +3 -0
  13. package/__tests__/fixtures/ts-node.ts +20 -0
  14. package/__tests__/fixtures/ts-react.tsx +27 -0
  15. package/__tests__/fixtures/ts-vue.vue +36 -0
  16. package/__tests__/fixtures/ts.ts +17 -0
  17. package/__tests__/fixtures/tsconfig.json +8 -0
  18. package/__tests__/fixtures/use-babel-eslint.jsx +170 -0
  19. package/__tests__/fixtures/vue.vue +16 -0
  20. package/__tests__/use-babel-eslint.test.js +47 -0
  21. package/__tests__/validate-js-configs.test.js +259 -0
  22. package/__tests__/validate-ts-configs.test.js +263 -0
  23. package/es5.js +10 -0
  24. package/essential/es5.js +12 -0
  25. package/essential/index.js +12 -0
  26. package/essential/react.js +76 -0
  27. package/essential/rules/blacklist.js +48 -0
  28. package/essential/rules/es6-blacklist.js +62 -0
  29. package/essential/rules/set-style-to-warn.js +30 -0
  30. package/essential/rules/ts-blacklist.js +15 -0
  31. package/essential/typescript/index.js +7 -0
  32. package/essential/typescript/react.js +7 -0
  33. package/essential/typescript/vue.js +9 -0
  34. package/essential/vue.js +8 -0
  35. package/index.js +23 -0
  36. package/jsx-a11y.js +5 -0
  37. package/node.js +6 -0
  38. package/package.json +48 -0
  39. package/react.js +11 -0
  40. package/rules/base/best-practices.js +284 -0
  41. package/rules/base/es6.js +168 -0
  42. package/rules/base/possible-errors.js +126 -0
  43. package/rules/base/strict.js +6 -0
  44. package/rules/base/style.js +445 -0
  45. package/rules/base/variables.js +48 -0
  46. package/rules/es5.js +11 -0
  47. package/rules/imports.js +167 -0
  48. package/rules/jsx-a11y.js +23 -0
  49. package/rules/node.js +11 -0
  50. package/rules/react.js +354 -0
  51. package/rules/typescript.js +807 -0
  52. package/rules/vue.js +96 -0
  53. package/typescript/index.js +6 -0
  54. package/typescript/node.js +6 -0
  55. package/typescript/react.js +6 -0
  56. package/typescript/vue.js +10 -0
  57. package/vue.js +10 -0
@@ -0,0 +1,807 @@
1
+ /**
2
+ * 本文件的规则由 @typescript-eslint/eslint-plugin 提供,使用 @typescript-eslint/parser 作为 parser
3
+ * @link https://github.com/typescript-eslint/typescript-eslint
4
+ */
5
+
6
+ module.exports = {
7
+ parser: '@typescript-eslint/parser',
8
+ plugins: ['@typescript-eslint'],
9
+ settings: {
10
+ // Apply special parsing for TypeScript files
11
+ 'import/parsers': {
12
+ '@typescript-eslint/parser': ['.ts', '.d.ts', '.tsx'],
13
+ },
14
+ // Use eslint-import-resolver-typescript
15
+ 'import/resolver': {
16
+ typescript: {},
17
+ },
18
+ // Append 'ts' extensions to 'import/extensions' setting
19
+ 'import/extensions': ['.js', '.ts', '.mjs'],
20
+ },
21
+ parserOptions: {
22
+ project: './tsconfig.json', // default project config
23
+ createDefaultProgram: true, // 兼容未在 tsconfig.json 中 provided 的文件
24
+ extraFileExtensions: ['.vue'],
25
+ },
26
+ rules: {
27
+ /**
28
+ * 【强制】将重载的函数写在一起以增加代码可读性
29
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md
30
+ */
31
+ '@typescript-eslint/adjacent-overload-signatures': 'error',
32
+
33
+ /**
34
+ * 【推荐】简单类型请使用 T[] 或 readonly T[]
35
+ * 对于所有其他类型(联合类型,交集类型,对象类型,函数类型等),请使用 Array<T> 或 ReadonlyArray<T>
36
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
37
+ */
38
+ '@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
39
+
40
+ /**
41
+ * 【关闭】禁止对没有 then 方法的对象使用 await
42
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md
43
+ */
44
+ '@typescript-eslint/await-thenable': 'off',
45
+
46
+ /**
47
+ * 【推荐】使用 @ts-expect-error/@ts-ignore/@ts-nocheck/@ts-check 等指令时需跟随注释描述
48
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md
49
+ */
50
+ '@typescript-eslint/ban-ts-comment': [
51
+ 'warn',
52
+ {
53
+ 'ts-expect-error': 'allow-with-description',
54
+ 'ts-ignore': 'allow-with-description',
55
+ 'ts-nocheck': 'allow-with-description',
56
+ 'ts-check': 'allow-with-description',
57
+ },
58
+ ],
59
+
60
+ /**
61
+ * 【强制】禁止使用 tslint:<rule-flag> 等相关注释
62
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-tslint-comment.md
63
+ * @reason tslint 已经被废弃
64
+ */
65
+ '@typescript-eslint/ban-tslint-comment': 'error',
66
+
67
+ /**
68
+ * 【关闭】禁止使用指定的类型
69
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
70
+ */
71
+ '@typescript-eslint/ban-types': 'off',
72
+
73
+ /**
74
+ * 【强制】大括号换行风格:one true brace style 风格,且单行代码块可不换行
75
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/brace-style.md
76
+ * @extend
77
+ */
78
+ 'brace-style': 'off',
79
+ '@typescript-eslint/brace-style': [
80
+ 'error',
81
+ '1tbs',
82
+ { allowSingleLine: true },
83
+ ],
84
+
85
+ /**
86
+ * 【推荐】类的属性如果是字面量,则必须是只读属性而不能用 getter
87
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-literal-property-style.md
88
+ */
89
+ '@typescript-eslint/class-literal-property-style': ['warn', 'fields'],
90
+
91
+ /**
92
+ * 【强制】逗号的前面无空格,后面有空格
93
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-spacing.md
94
+ * @extend
95
+ */
96
+ 'comma-spacing': 'off',
97
+ '@typescript-eslint/comma-spacing': [
98
+ 'error',
99
+ { before: false, after: true },
100
+ ],
101
+
102
+ /**
103
+ * 【强制】类型断言必须使用 as Type 而非 <T>,对象字面量禁止类型断言(断言成 any 除外)
104
+ * <T> 容易与 JSX 语法混淆
105
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-assertions.md
106
+ */
107
+ '@typescript-eslint/consistent-type-assertions': [
108
+ 'error',
109
+ {
110
+ assertionStyle: 'as',
111
+ objectLiteralTypeAssertions: 'never',
112
+ },
113
+ ],
114
+
115
+ /**
116
+ * 【推荐】优先使用 interface 而不是 type 定义对象类型
117
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
118
+ */
119
+ '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
120
+
121
+ /**
122
+ * 【关闭】有默认值或可选的参数必须放到最后
123
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/default-param-last.md
124
+ */
125
+ 'default-param-last': 'off',
126
+ '@typescript-eslint/default-param-last': 'off',
127
+
128
+ /**
129
+ * 【强制】优先使用 . 访问对象的属性
130
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/dot-notation.md
131
+ * @extend
132
+ */
133
+ 'dot-notation': 'off',
134
+ '@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
135
+
136
+ /**
137
+ * 【关闭】函数返回值必须与声明的类型一致
138
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
139
+ */
140
+ '@typescript-eslint/explicit-function-return-type': 'off',
141
+
142
+ /**
143
+ * 【推荐】设置类的成员的可访问性,public 可省略
144
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
145
+ */
146
+ '@typescript-eslint/explicit-member-accessibility': [
147
+ 'warn',
148
+ { accessibility: 'no-public' },
149
+ ],
150
+
151
+ /**
152
+ * 【关闭】导出的函数或类中的 public 方法必须定义输入输出参数的类型
153
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md
154
+ */
155
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
156
+
157
+ /**
158
+ * 【强制】函数名与调用它的括号间无空格
159
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/func-call-spacing.md
160
+ */
161
+ 'func-call-spacing': 'off',
162
+ '@typescript-eslint/func-call-spacing': ['error', 'never'],
163
+
164
+ /**
165
+ * 【强制】缩进为两个空格
166
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
167
+ */
168
+ indent: 'off',
169
+ '@typescript-eslint/indent': [
170
+ 'error',
171
+ 2,
172
+ {
173
+ SwitchCase: 1,
174
+ VariableDeclarator: 1,
175
+ outerIIFEBody: 1,
176
+ // MemberExpression: null,
177
+ FunctionDeclaration: {
178
+ parameters: 1,
179
+ body: 1,
180
+ },
181
+ FunctionExpression: {
182
+ parameters: 1,
183
+ body: 1,
184
+ },
185
+ CallExpression: {
186
+ arguments: 1,
187
+ },
188
+ ArrayExpression: 1,
189
+ ObjectExpression: 1,
190
+ ImportDeclaration: 1,
191
+ flatTernaryExpressions: false,
192
+ // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
193
+ ignoredNodes: [
194
+ 'JSXElement',
195
+ 'JSXElement > *',
196
+ 'JSXAttribute',
197
+ 'JSXIdentifier',
198
+ 'JSXNamespacedName',
199
+ 'JSXMemberExpression',
200
+ 'JSXSpreadAttribute',
201
+ 'JSXExpressionContainer',
202
+ 'JSXOpeningElement',
203
+ 'JSXClosingElement',
204
+ 'JSXText',
205
+ 'JSXEmptyExpression',
206
+ 'JSXSpreadChild',
207
+ ],
208
+ ignoreComments: false,
209
+ },
210
+ ],
211
+
212
+ /**
213
+ * 【关闭】变量必须在定义的时候赋值
214
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/init-declarations.md
215
+ * @extend
216
+ */
217
+ 'init-declarations': 'off',
218
+ '@typescript-eslint/init-declarations': 'off',
219
+
220
+ /**
221
+ * 【强制】关键字前后有一个空格
222
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/keyword-spacing.md
223
+ * @extend
224
+ */
225
+ 'keyword-spacing': 'off',
226
+ '@typescript-eslint/keyword-spacing': [
227
+ 'error',
228
+ {
229
+ before: true,
230
+ after: true,
231
+ overrides: {
232
+ return: { after: true },
233
+ throw: { after: true },
234
+ case: { after: true },
235
+ },
236
+ },
237
+ ],
238
+
239
+ /**
240
+ * 【关闭】类成员之间保留一个空行
241
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/lines-between-class-members.md
242
+ * @extend
243
+ */
244
+ 'lines-between-class-members': 'off',
245
+ '@typescript-eslint/lines-between-class-members': 'off',
246
+
247
+ /**
248
+ * 【强制】interface/type 类型中保持一致的成员分隔符分号「;」,单行类型的最后一个元素不加分号
249
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md
250
+ */
251
+ '@typescript-eslint/member-delimiter-style': 'error',
252
+
253
+ /**
254
+ * 【推荐】类成员的遵循一定的排序规则
255
+ * 1. 类的静态方法/属性(static)优先于实例的方法/属性(instance)
256
+ * 2. 属性(field)优先于构造函数(constructor),优先于方法(method)
257
+ * 3. 公开的项(public)优先于受保护的(protected),优先于私有的(private)
258
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md
259
+ */
260
+ '@typescript-eslint/member-ordering': [
261
+ 'warn',
262
+ {
263
+ default: [
264
+ 'public-static-field',
265
+ 'protected-static-field',
266
+ 'private-static-field',
267
+ 'static-field',
268
+ 'public-static-method',
269
+ 'protected-static-method',
270
+ 'private-static-method',
271
+ 'static-method',
272
+ 'public-instance-field',
273
+ 'protected-instance-field',
274
+ 'private-instance-field',
275
+ 'public-field',
276
+ 'protected-field',
277
+ 'private-field',
278
+ 'instance-field',
279
+ 'field',
280
+ 'constructor',
281
+ 'public-instance-method',
282
+ 'protected-instance-method',
283
+ 'private-instance-method',
284
+ 'public-method',
285
+ 'protected-method',
286
+ 'private-method',
287
+ 'instance-method',
288
+ 'method',
289
+ ],
290
+ },
291
+ ],
292
+
293
+ /**
294
+ * 【推荐】interface 中的方法用属性的方式定义
295
+ * A method and a function property of the same type behave differently.
296
+ * Methods are always bivariant in their argument, while function properties
297
+ * are contravariant in their argument under strictFunctionTypes.
298
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/method-signature-style.md
299
+ */
300
+ '@typescript-eslint/method-signature-style': ['warn', 'property'],
301
+
302
+ /**
303
+ * 【关闭】限制各种变量或类型的命名规则
304
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
305
+ */
306
+ camelcase: 'off',
307
+ '@typescript-eslint/camelcase': 'off',
308
+ '@typescript-eslint/naming-convention': 'off',
309
+
310
+ /**
311
+ * 【强制】禁止使用 Array 构造函数创建数组
312
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md
313
+ * @extend
314
+ */
315
+ 'no-array-constructor': 'off',
316
+ '@typescript-eslint/no-array-constructor': 'error',
317
+
318
+ /**
319
+ * 【关闭】限制 toString 方法的使用
320
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-base-to-string.md
321
+ */
322
+ '@typescript-eslint/no-base-to-string': 'off',
323
+
324
+ /**
325
+ * 【推荐】禁止使用容易混淆的非空断言
326
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md
327
+ */
328
+ '@typescript-eslint/no-confusing-non-null-assertion': 'warn',
329
+
330
+ /**
331
+ * 【强制】避免重复的类成员命名
332
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
333
+ * @extend
334
+ */
335
+ 'no-dupe-class-members': 'off',
336
+ '@typescript-eslint/no-dupe-class-members': 'error',
337
+
338
+ /**
339
+ * 【关闭】delete 时传入的 key 必须是静态的字面量
340
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dynamic-delete.md
341
+ */
342
+ '@typescript-eslint/no-dynamic-delete': 'off',
343
+
344
+ /**
345
+ * 【强制】禁止出现空函数,普通函数(非 async/await/generator)、箭头函数、类上的方法除外
346
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
347
+ * @extend
348
+ */
349
+ 'no-empty-function': 'off',
350
+ '@typescript-eslint/no-empty-function': [
351
+ 'error',
352
+ {
353
+ allow: ['arrowFunctions', 'functions', 'methods'],
354
+ },
355
+ ],
356
+
357
+ /**
358
+ * 【推荐】禁止出现空的 interface
359
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-interface.md
360
+ */
361
+ '@typescript-eslint/no-empty-interface': 'warn',
362
+
363
+ /**
364
+ * 【关闭】禁止使用 any
365
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md
366
+ */
367
+ '@typescript-eslint/no-explicit-any': 'off',
368
+
369
+ /**
370
+ * 【关闭】禁止多余的 non-null 断言
371
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md
372
+ */
373
+ '@typescript-eslint/no-extra-non-null-assertion': 'off',
374
+
375
+ /**
376
+ * 【关闭】禁止不必要的小括号
377
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-parens.md
378
+ */
379
+ 'no-extra-parens': 'off',
380
+ '@typescript-eslint/no-extra-parens': 'off',
381
+
382
+ /**
383
+ * 【强制】禁止不必要的分号
384
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-semi.md
385
+ * @extend
386
+ */
387
+ 'no-extra-semi': 'off',
388
+ '@typescript-eslint/no-extra-semi': 'error',
389
+
390
+ /**
391
+ * 【关闭】禁止定义没必要的类,比如只有静态方法的类
392
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md
393
+ */
394
+ '@typescript-eslint/no-extraneous-class': 'off',
395
+
396
+ /**
397
+ * 【关闭】禁止调用 Promise 时没有处理异常情况
398
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md
399
+ */
400
+ '@typescript-eslint/no-floating-promises': 'off',
401
+
402
+ /**
403
+ * 【关闭】禁止对 array 使用 for in 循环
404
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-for-in-array.md
405
+ */
406
+ '@typescript-eslint/no-for-in-array': 'off',
407
+
408
+ /**
409
+ * 【关闭】禁止使用 eval
410
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-implied-eval.md
411
+ */
412
+ '@typescript-eslint/no-implied-eval': 'off',
413
+
414
+ /**
415
+ * 【推荐】禁止给一个初始化时直接赋值为 number, string 的变量显式的声明类型
416
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-inferrable-types.md
417
+ */
418
+ '@typescript-eslint/no-inferrable-types': 'warn',
419
+
420
+ /**
421
+ * 【关闭】禁止在 class 外使用 this
422
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-invalid-this.md
423
+ * @extend
424
+ */
425
+ 'no-invalid-this': 'off',
426
+ '@typescript-eslint/no-invalid-this': 'off',
427
+
428
+ /**
429
+ * 【强制】禁止使用无意义的 void 类型,void 只能用在函数的返回值中
430
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
431
+ */
432
+ '@typescript-eslint/no-invalid-void-type': 'error',
433
+
434
+ // @typescript-eslint/no-loss-of-precision needs eslint version >= v7
435
+
436
+ /**
437
+ * 【关闭】禁止使用 magic numbers
438
+ * @extend
439
+ */
440
+ 'no-magic-numbers': 'off',
441
+ '@typescript-eslint/no-magic-numbers': 'off',
442
+
443
+ /**
444
+ * 【关闭】禁止在接口中定义 constructor,或在类中定义 new
445
+ */
446
+ '@typescript-eslint/no-misused-new': 'off',
447
+
448
+ /**
449
+ * 【关闭】避免错误的使用 Promise
450
+ */
451
+ '@typescript-eslint/no-misused-promises': 'off',
452
+
453
+ /**
454
+ * 【强制】禁止使用 namespace 来定义命名空间,但允许使用 declare namespace 定义外部命名空间
455
+ */
456
+ '@typescript-eslint/no-namespace': [
457
+ 'error',
458
+ {
459
+ allowDeclarations: true,
460
+ allowDefinitionFiles: true,
461
+ },
462
+ ],
463
+
464
+ /**
465
+ * 【强制】禁止在 optional chaining 之后使用 non-null 断言(感叹号)
466
+ * optional chaining 后面的属性一定是非空的
467
+ */
468
+ '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
469
+
470
+ /**
471
+ * 【关闭】禁止使用 non-null 断言(感叹号)
472
+ */
473
+ '@typescript-eslint/no-non-null-assertion': 'off',
474
+
475
+ /**
476
+ * 【关闭】禁止给类的构造函数的参数添加修饰符
477
+ */
478
+ '@typescript-eslint/no-parameter-properties': 'off',
479
+
480
+ /**
481
+ * 【推荐】不建议使用 require 引入模块,使用 import
482
+ */
483
+ '@typescript-eslint/no-require-imports': 'warn',
484
+
485
+ /**
486
+ * @extend
487
+ * @link https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
488
+ */
489
+ 'no-shadow': 'off',
490
+ '@typescript-eslint/no-shadow': 'error',
491
+
492
+ /**
493
+ * 【推荐】不建议将 this 赋值给其他变量,解构赋值除外
494
+ */
495
+ '@typescript-eslint/no-this-alias': [
496
+ 'warn',
497
+ {
498
+ allowDestructuring: true,
499
+ },
500
+ ],
501
+
502
+ /**
503
+ * 【关闭】禁止 throw 字面量,必须 throw 一个 Error 对象
504
+ */
505
+ '@typescript-eslint/no-throw-literal': 'off',
506
+
507
+ /**
508
+ * 【关闭】禁止使用类型别名
509
+ */
510
+ '@typescript-eslint/no-type-alias': 'off',
511
+
512
+ /**
513
+ * 【关闭】测试表达式中的布尔类型禁止与 true 或 false 直接比较
514
+ */
515
+ '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
516
+
517
+ /**
518
+ * 【关闭】条件表达式禁止是永远为真(或永远为假)的
519
+ */
520
+ '@typescript-eslint/no-unnecessary-condition': 'off',
521
+
522
+ /**
523
+ * 【关闭】在命名空间中,可以直接使用内部变量,不需要添加命名空间前缀
524
+ */
525
+ '@typescript-eslint/no-unnecessary-qualifier': 'off',
526
+
527
+ /**
528
+ * 【关闭】禁止范型的类型有默认值时,将范型设置为该默认值
529
+ */
530
+ '@typescript-eslint/no-unnecessary-type-arguments': 'off',
531
+
532
+ /**
533
+ * 【关闭】禁止无用的类型断言
534
+ */
535
+ '@typescript-eslint/no-unnecessary-type-assertion': 'off',
536
+
537
+ /**
538
+ * 【关闭】禁止将变量或属性的类型设置为 any
539
+ */
540
+ '@typescript-eslint/no-unsafe-assignment': 'off',
541
+
542
+ /**
543
+ * 【关闭】禁止调用 any 类型的变量上的方法
544
+ */
545
+ '@typescript-eslint/no-unsafe-call': 'off',
546
+
547
+ /**
548
+ * 【关闭】禁止获取 any 类型的变量中的属性
549
+ */
550
+ '@typescript-eslint/no-unsafe-member-access': 'off',
551
+
552
+ /**
553
+ * 【关闭】禁止函数的返回值的类型是 any
554
+ */
555
+ '@typescript-eslint/no-unsafe-return': 'off',
556
+
557
+ /**
558
+ * 【强制】禁止无用的表达式
559
+ * @extend
560
+ */
561
+ 'no-unused-expressions': 'off',
562
+ '@typescript-eslint/no-unused-expressions': [
563
+ 'error',
564
+ {
565
+ allowShortCircuit: true,
566
+ allowTernary: true,
567
+ allowTaggedTemplates: true,
568
+ },
569
+ ],
570
+
571
+ /**
572
+ * 【强制】声明的变量必须被使用
573
+ * @extend
574
+ */
575
+ 'no-unused-vars': 'off',
576
+ '@typescript-eslint/no-unused-vars': [
577
+ 'error',
578
+ { vars: 'all', args: 'after-used', ignoreRestSiblings: true },
579
+ ],
580
+
581
+ /**
582
+ * 【关闭】禁止已定义的变量未使用
583
+ */
584
+ '@typescript-eslint/no-unused-vars-experimental': 'off',
585
+
586
+ /**
587
+ * 【强制】禁止在定义变量之前就使用它
588
+ * @extend
589
+ */
590
+ 'no-use-before-define': 'off',
591
+ '@typescript-eslint/no-use-before-define': [
592
+ 'error',
593
+ { functions: false, classes: false, variables: false },
594
+ ],
595
+
596
+ /**
597
+ * 【强制】禁止出现没必要的 constructor
598
+ * @extend
599
+ */
600
+ 'no-useless-constructor': 'off',
601
+ '@typescript-eslint/no-useless-constructor': 'error',
602
+
603
+ /**
604
+ * 【关闭】禁止使用 require 来引入模块,被 no-require-imports 规则包含
605
+ */
606
+ '@typescript-eslint/no-var-requires': 'off',
607
+
608
+ /**
609
+ * 【推荐】当设定当前值为当前类型时,推荐使用 as const 替代 as 'bar'
610
+ */
611
+ '@typescript-eslint/prefer-as-const': 'warn',
612
+
613
+ /**
614
+ * 【关闭】如果索引仅用于访问正在迭代的数组,则建议首选 for of 循环,而不是标准 for 循环
615
+ */
616
+ '@typescript-eslint/prefer-for-of': 'off',
617
+
618
+ /**
619
+ * 【关闭】可以简写为函数类型的接口或对象字面类型的话,则必须简写
620
+ */
621
+ '@typescript-eslint/prefer-function-type': 'off',
622
+
623
+ /**
624
+ * 【关闭】使用 includes 而不是 indexOf
625
+ */
626
+ '@typescript-eslint/prefer-includes': 'off',
627
+
628
+ /**
629
+ * 【强制】禁止使用 module 来定义命名空间,declare module 是允许的
630
+ */
631
+ '@typescript-eslint/prefer-namespace-keyword': 'error',
632
+
633
+ /**
634
+ * 【关闭】使用 ?? 替代 ||
635
+ */
636
+ '@typescript-eslint/prefer-nullish-coalescing': 'off',
637
+
638
+ /**
639
+ * 【关闭】使用 optional chaining 替代 &&
640
+ * TODO:由于对 ts 版本有要求,暂不开启
641
+ */
642
+ '@typescript-eslint/prefer-optional-chain': 'off',
643
+
644
+ /**
645
+ * 【关闭】私有变量如果没有在构造函数外被赋值,则必须设为 readonly
646
+ */
647
+ '@typescript-eslint/prefer-readonly': 'off',
648
+
649
+ /**
650
+ * 【关闭】函数的参数必须设置为 readonly
651
+ */
652
+ '@typescript-eslint/prefer-readonly-parameter-types': 'off',
653
+
654
+ /**
655
+ * 【关闭】使用 reduce 方法时,必须传入范型,而不是对第二个参数使用 as
656
+ */
657
+ '@typescript-eslint/prefer-reduce-type-parameter': 'off',
658
+
659
+ /**
660
+ * 【关闭】使用 RegExp#exec 而不是 String#match
661
+ */
662
+ '@typescript-eslint/prefer-regexp-exec': 'off',
663
+
664
+ /**
665
+ * 【关闭】使用 String#startsWith 而不是其他方式
666
+ */
667
+ '@typescript-eslint/prefer-string-starts-ends-with': 'off',
668
+
669
+ /**
670
+ * 【关闭】当需要忽略下一行的 ts 错误时,必须使用 @ts-expect-error 而不是 @ts-ignore
671
+ */
672
+ '@typescript-eslint/prefer-ts-expect-error': 'off',
673
+
674
+ /**
675
+ * 【关闭】async 函数的返回值必须是 Promise
676
+ */
677
+ '@typescript-eslint/promise-function-async': 'off',
678
+
679
+ /**
680
+ * 【强制】ts 文件字符串字面量优先使用单引号
681
+ */
682
+ quotes: 'off',
683
+ '@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }],
684
+
685
+ /**
686
+ * 【关闭】async 函数中必须存在 await 语句
687
+ */
688
+ 'require-await': 'off',
689
+ '@typescript-eslint/require-await': 'off',
690
+
691
+ /**
692
+ * 【推荐】使用加号时,两者必须同为数字或同为字符串
693
+ */
694
+ '@typescript-eslint/restrict-plus-operands': 'warn',
695
+
696
+ /**
697
+ * 【关闭】模版字符串中的变量类型必须是字符串
698
+ */
699
+ '@typescript-eslint/restrict-template-expressions': 'off',
700
+
701
+ /**
702
+ * 【强制】禁止在 return 语句里使用 await
703
+ * @extend
704
+ */
705
+ 'no-return-await': 'off',
706
+ '@typescript-eslint/return-await': 'off',
707
+
708
+ /**
709
+ * 【强制】添加分号
710
+ * @extend
711
+ */
712
+ semi: 'off',
713
+ '@typescript-eslint/semi': ['error', 'always'],
714
+
715
+ /**
716
+ * 【强制】命名函数的空格规则,遵循 JS 约定
717
+ * @extend
718
+ */
719
+ 'space-before-function-paren': 'off',
720
+ '@typescript-eslint/space-before-function-paren': [
721
+ 'error',
722
+ {
723
+ anonymous: 'always',
724
+ named: 'never',
725
+ asyncArrow: 'always',
726
+ },
727
+ ],
728
+
729
+ /**
730
+ * 【关闭】条件判断必须传入布尔值
731
+ */
732
+ '@typescript-eslint/strict-boolean-expressions': 'off',
733
+
734
+ /**
735
+ * 【关闭】使用联合类型作为 switch 的对象时,必须包含每一个类型的 case
736
+ */
737
+ '@typescript-eslint/switch-exhaustiveness-check': 'off',
738
+
739
+ /**
740
+ * 【强制】三斜杠导入语法已废弃,在非 dts 文件中禁止使用
741
+ */
742
+ '@typescript-eslint/triple-slash-reference': [
743
+ 'error',
744
+ {
745
+ path: 'never',
746
+ types: 'always',
747
+ lib: 'always',
748
+ },
749
+ ],
750
+
751
+ /**
752
+ * 【强制】定义类型时应正确添加空格
753
+ */
754
+ '@typescript-eslint/type-annotation-spacing': 'error',
755
+
756
+ /**
757
+ * 【强制】interface 和 type 定义时必须声明成员的类型
758
+ */
759
+ '@typescript-eslint/typedef': [
760
+ 'error',
761
+ {
762
+ arrayDestructuring: false,
763
+ arrowParameter: false,
764
+ memberVariableDeclaration: false,
765
+ objectDestructuring: false,
766
+ parameter: false,
767
+ propertyDeclaration: true,
768
+ variableDeclaration: false,
769
+ },
770
+ ],
771
+
772
+ /**
773
+ * 【关闭】方法调用时需要绑定到正确的 this 上
774
+ */
775
+ '@typescript-eslint/unbound-method': 'off',
776
+
777
+ /**
778
+ * 【推荐】定义函数时,优先使用参数的联合类型而不是函数的类型重载
779
+ */
780
+ '@typescript-eslint/unified-signatures': 'warn',
781
+
782
+ /**
783
+ * 不允许重复申明
784
+ * no-redeclare 会导致 typescript 的函数重载报错,详见:
785
+ * https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-redeclare.md
786
+ */
787
+ 'no-redeclare': 'off',
788
+ '@typescript-eslint/no-redeclare': ['error'],
789
+ },
790
+ overrides: [
791
+ {
792
+ files: ['*.ts', '*.tsx'],
793
+ rules: {
794
+ // Disable `no-undef` rule within TypeScript files because it incorrectly errors when exporting default interfaces
795
+ // https://github.com/iamturns/eslint-config-airbnb-typescript/issues/50
796
+ // This will be caught by TypeScript compiler if `strictNullChecks` (or `strict`) is enabled
797
+ 'no-undef': 'off',
798
+
799
+ /* Using TypeScript makes it safe enough to disable the checks below */
800
+
801
+ // Disable ESLint-based module resolution check for improved monorepo support
802
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
803
+ 'import/no-unresolved': 'off',
804
+ },
805
+ },
806
+ ],
807
+ };