@houheaven/eslint-config-helper 1.3.1 → 2.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 (84) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +155 -28
  3. package/lib/format-es5.js +23 -0
  4. package/lib/format-es6.js +25 -0
  5. package/lib/format-html.js +23 -0
  6. package/lib/format-import.js +23 -0
  7. package/lib/format-typescript.js +28 -0
  8. package/lib/format-vue2.js +23 -0
  9. package/lib/format-vue3.js +23 -0
  10. package/lib/html.js +13 -22
  11. package/lib/import.js +23 -0
  12. package/lib/javascript-es5.js +23 -0
  13. package/lib/javascript-es6.js +25 -0
  14. package/lib/rules/eslint/_deprecated.js +132 -0
  15. package/lib/rules/eslint/_removed.js +25 -0
  16. package/lib/rules/eslint/es6.js +279 -110
  17. package/lib/rules/eslint/layout-formatting.js +441 -0
  18. package/lib/rules/eslint/possible-errors.js +140 -131
  19. package/lib/rules/eslint/suggestions.js +666 -0
  20. package/lib/rules/html/accessibility.js +47 -23
  21. package/lib/rules/html/best-practice.js +122 -36
  22. package/lib/rules/html/seo.js +16 -11
  23. package/lib/rules/html/style.js +53 -15
  24. package/lib/rules/import/helpful-warnings.js +23 -18
  25. package/lib/rules/import/module-systems.js +16 -17
  26. package/lib/rules/import/static-analysis.js +54 -38
  27. package/lib/rules/import/style-guide.js +89 -61
  28. package/lib/rules/typescript/_deprecated.js +57 -0
  29. package/lib/rules/typescript/conflict.js +16 -0
  30. package/lib/rules/typescript/deprecated.js +41 -0
  31. package/lib/rules/typescript/extension.js +207 -0
  32. package/lib/rules/typescript/fixable.js +215 -0
  33. package/lib/rules/typescript/other.js +125 -0
  34. package/lib/rules/typescript/stylistic.js +34 -0
  35. package/lib/rules/typescript/suggestion.js +53 -0
  36. package/lib/rules/typescript/type-checked.js +263 -0
  37. package/lib/rules/vue/_deprecated.js +37 -0
  38. package/lib/rules/vue/common-base.js +1 -11
  39. package/lib/rules/vue/common-essential.js +25 -38
  40. package/lib/rules/vue/common-extension.js +321 -0
  41. package/lib/rules/vue/common-recommended.js +64 -31
  42. package/lib/rules/vue/common-strongly-recommended.js +37 -20
  43. package/lib/rules/vue/{common-extra.js → common-uncategorized.js} +141 -52
  44. package/lib/rules/vue/vue2-essential.js +16 -14
  45. package/lib/rules/vue/vue2-uncategorized.js +15 -0
  46. package/lib/rules/vue/vue3-essential.js +54 -24
  47. package/lib/rules/vue/vue3-strongly-recommended.js +8 -10
  48. package/lib/rules/vue/vue3-uncategorized.js +115 -0
  49. package/lib/support/es5-support.js +29 -0
  50. package/lib/support/es6-support.js +39 -0
  51. package/lib/support/html-support.js +38 -0
  52. package/lib/support/import-bugfix.js +65 -0
  53. package/lib/support/import-support.js +25 -0
  54. package/lib/support/typescript-support.js +27 -0
  55. package/lib/support/vue2-support.js +43 -0
  56. package/lib/support/vue3-support.js +43 -0
  57. package/lib/support/vue3-ts-support.js +51 -0
  58. package/lib/typescript.js +37 -0
  59. package/lib/utils/utils.js +160 -0
  60. package/lib/vue2.js +16 -22
  61. package/lib/vue3-ts.js +31 -0
  62. package/lib/vue3.js +13 -17
  63. package/package.json +39 -20
  64. package/lib/configs/eslint-es5.js +0 -24
  65. package/lib/configs/eslint.js +0 -23
  66. package/lib/configs/format-html.js +0 -22
  67. package/lib/configs/format-js.js +0 -134
  68. package/lib/configs/format-vue.js +0 -278
  69. package/lib/configs/html.js +0 -20
  70. package/lib/configs/import-bugfix.js +0 -36
  71. package/lib/configs/import.js +0 -44
  72. package/lib/configs/vue2.js +0 -28
  73. package/lib/configs/vue3.js +0 -28
  74. package/lib/eslint.js +0 -18
  75. package/lib/format.js +0 -40
  76. package/lib/rules/eslint/best-practices.js +0 -422
  77. package/lib/rules/eslint/node.js +0 -48
  78. package/lib/rules/eslint/strict-mode.js +0 -12
  79. package/lib/rules/eslint/stylistic-issues.js +0 -577
  80. package/lib/rules/eslint/variables.js +0 -73
  81. package/lib/rules/vue/common-eslint.js +0 -220
  82. package/lib/rules/vue/vue2-recommended.js +0 -17
  83. package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
  84. package/lib/rules/vue/vue3-recommended.js +0 -17
@@ -0,0 +1,441 @@
1
+
2
+ // ==========================================================
3
+ // Layout and Formatting
4
+ // 这些规则关心的是代码的外观而不是执行方式
5
+ // ==========================================================
6
+
7
+ module.exports = {
8
+ rules: {
9
+ // 在数组开括号后和闭括号前强制换行
10
+ // https://zh-hans.eslint.org/docs/latest/rules/array-bracket-newline
11
+ "array-bracket-newline": ["warn", "consistent"],
12
+
13
+ // 强制数组方括号中使用一致的空格
14
+ "array-bracket-spacing": ["warn", "never", {
15
+ singleValue: false,
16
+ objectsInArrays: false,
17
+ arraysInArrays: false,
18
+ }],
19
+
20
+ // 强制数组元素间出现换行
21
+ // https://zh-hans.eslint.org/docs/latest/rules/array-element-newline
22
+ "array-element-newline": ["warn", "consistent"],
23
+
24
+ // 禁止或强制在代码块中开括号前和闭括号后有空格
25
+ // https://zh-hans.eslint.org/docs/latest/rules/block-spacing
26
+ "block-spacing": ["warn", "always"],
27
+
28
+ // 强制在代码块中使用一致的大括号风格
29
+ // https://zh-hans.eslint.org/docs/latest/rules/brace-style
30
+ "brace-style": ["warn", "stroustrup", {
31
+ allowSingleLine: true,
32
+ }],
33
+
34
+ // TODO
35
+ // 要求或禁止使用拖尾逗号(对象、数组、导入、导出、函数参数的最后一项后面是否允许有逗号)
36
+ // https://zh-hans.eslint.org/docs/latest/rules/comma-dangle
37
+ "comma-dangle": ["warn", {
38
+ arrays: "always-multiline",
39
+ objects: "always-multiline",
40
+ imports: "always-multiline",
41
+ exports: "always-multiline",
42
+ functions: "never",
43
+ // importAttributes: "always-multiline",
44
+ // dynamicImports: "never",
45
+ // enums: "always-multiline",
46
+ // generics: "never",
47
+ // tuples: "never",
48
+ }],
49
+
50
+ // 强制在逗号前后使用一致的空格
51
+ // https://zh-hans.eslint.org/docs/latest/rules/comma-spacing
52
+ "comma-spacing": ["warn", {
53
+ before: false,
54
+ after: true,
55
+ }],
56
+
57
+ // 强制使用一致的逗号风格
58
+ // https://zh-hans.eslint.org/docs/latest/rules/comma-style
59
+ "comma-style": ["warn", "last", {
60
+ exceptions: {
61
+ ArrayExpression: false,
62
+ ArrayPattern: false,
63
+ ArrowFunctionExpression: false,
64
+ CallExpression: false,
65
+ FunctionDeclaration: false,
66
+ FunctionExpression: false,
67
+ ImportDeclaration: false,
68
+ ObjectExpression: false,
69
+ ObjectPattern: false,
70
+ VariableDeclaration: false,
71
+ NewExpression: false,
72
+ },
73
+ }],
74
+
75
+ // 强制在计算的属性的方括号中使用一致的空格
76
+ // https://zh-hans.eslint.org/docs/latest/rules/computed-property-spacing
77
+ "computed-property-spacing": ["warn", "never"],
78
+
79
+ // 强制在点号之前和之后一致的换行
80
+ // https://zh-hans.eslint.org/docs/latest/rules/dot-location
81
+ "dot-location": ["warn", "property"],
82
+
83
+ // 要求或禁止文件末尾存在空行
84
+ // https://zh-hans.eslint.org/docs/latest/rules/eol-last
85
+ "eol-last": ["warn", "always"],
86
+
87
+ // 要求或禁止在函数标识符和其调用之间有空格
88
+ // https://zh-hans.eslint.org/docs/latest/rules/func-call-spacing
89
+ "func-call-spacing": ["warn", "never"],
90
+
91
+ // 函数调用参数换行符
92
+ // https://zh-hans.eslint.org/docs/latest/rules/function-call-argument-newline
93
+ "function-call-argument-newline": ["warn", "consistent"],
94
+
95
+ // 强制在函数括号内使用一致的换行
96
+ // https://zh-hans.eslint.org/docs/latest/rules/function-paren-newline
97
+ "function-paren-newline": ["warn", "consistent"],
98
+
99
+ // TODO
100
+ // 强制使用一致的缩进
101
+ // https://zh-hans.eslint.org/docs/latest/rules/indent
102
+ "indent": ["warn", 2, {
103
+ SwitchCase: 1,
104
+ VariableDeclarator: 1,
105
+ outerIIFEBody: 1,
106
+ MemberExpression: 1,
107
+ FunctionDeclaration: {
108
+ parameters: 1,
109
+ body: 1,
110
+ },
111
+ FunctionExpression: {
112
+ parameters: 1,
113
+ body: 1,
114
+ },
115
+ StaticBlock: {
116
+ body: 1,
117
+ },
118
+ CallExpression: {
119
+ arguments: 1,
120
+ },
121
+ ArrayExpression: 1,
122
+ ObjectExpression: 1,
123
+ ImportDeclaration: 1,
124
+ flatTernaryExpressions: false,
125
+ // offsetTernaryExpressions: true,
126
+ // offsetTernaryExpressionsOffsetCallExpressions: true,
127
+ // assignmentOperator: 1,
128
+ ignoreComments: false,
129
+ // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
130
+ ignoredNodes: [
131
+ "JSXElement",
132
+ "JSXElement > *",
133
+ "JSXAttribute",
134
+ "JSXIdentifier",
135
+ "JSXNamespacedName",
136
+ "JSXMemberExpression",
137
+ "JSXSpreadAttribute",
138
+ "JSXExpressionContainer",
139
+ "JSXOpeningElement",
140
+ "JSXClosingElement",
141
+ "JSXFragment",
142
+ "JSXOpeningFragment",
143
+ "JSXClosingFragment",
144
+ "JSXText",
145
+ "JSXEmptyExpression",
146
+ "JSXSpreadChild",
147
+ ],
148
+ }],
149
+
150
+ // 强制在 JSX 属性中一致地使用双引号或单引号
151
+ // https://zh-hans.eslint.org/docs/latest/rules/jsx-quotes
152
+ "jsx-quotes": ["warn", "prefer-double"],
153
+
154
+ // 强制在对象字面量的键和值之间使用一致的空格
155
+ // https://zh-hans.eslint.org/docs/latest/rules/key-spacing
156
+ "key-spacing": ["warn", {
157
+ beforeColon: false,
158
+ afterColon: true,
159
+ mode: "strict",
160
+ // 以下配置不要开启
161
+ // align: {},
162
+ // singleLine: {},
163
+ // multiLine: {},
164
+ // ignoredNodes: [],
165
+ }],
166
+
167
+ // 强制关键字周围空格的一致性
168
+ // https://zh-hans.eslint.org/docs/latest/rules/keyword-spacing
169
+ "keyword-spacing": ["warn", {
170
+ before: true,
171
+ after: true,
172
+ overrides: {
173
+ if: { after: true },
174
+ for: { after: false },
175
+ while: { after: false },
176
+ switch: { after: false },
177
+ case: { after: true },
178
+ catch: { after: false },
179
+ return: { after: true },
180
+ throw: { after: true },
181
+ },
182
+ }],
183
+
184
+ // enforce position of line comments
185
+ // 不支持自动修复,后续开启改规则,可以设置为 error
186
+ // https://zh-hans.eslint.org/docs/latest/rules/line-comment-position
187
+ "line-comment-position": ["off", {
188
+ position: "above",
189
+ ignorePattern: "",
190
+ applyDefaultPatterns: true,
191
+ }],
192
+
193
+ // 强制使用一致的换行符风格
194
+ // Windows - "CRLF"
195
+ // Unix、Linux - "LF"
196
+ // https://zh-hans.eslint.org/docs/latest/rules/linebreak-style
197
+ "linebreak-style": ["warn", "unix"],
198
+
199
+ // 要求在注释周围有空行
200
+ // 支持自动修复,后续开启改规则,可以设置为 warn
201
+ "lines-around-comment": "off",
202
+
203
+ // 强制一行的最大长度
204
+ // https://zh-hans.eslint.org/docs/latest/rules/max-len
205
+ "max-len": ["error", {
206
+ code: 200,
207
+ tabWidth: 2,
208
+ comments: 200,
209
+ ignorePattern: "",
210
+ ignoreComments: false,
211
+ ignoreTrailingComments: true,
212
+ ignoreUrls: true,
213
+ ignoreStrings: true,
214
+ ignoreTemplateLiterals: true,
215
+ ignoreRegExpLiterals: true,
216
+ }],
217
+
218
+ // 强制限制每行允许的语句数量上限
219
+ // 不支持自动修复,后续开启改规则,可以设置为 error
220
+ // https://zh-hans.eslint.org/docs/latest/rules/max-statements-per-line
221
+ "max-statements-per-line": ["off", {
222
+ max: 1,
223
+ }],
224
+
225
+ // 要求或禁止在三元操作数中间换行
226
+ // 支持自动修复,后续开启改规则,可以设置为 warn
227
+ // https://zh-hans.eslint.org/docs/latest/rules/multiline-ternary
228
+ "multiline-ternary": ["off", "never"],
229
+
230
+ // 强制或禁止调用无参构造函数时有圆括号
231
+ // https://zh-hans.eslint.org/docs/latest/rules/new-parens
232
+ "new-parens": ["warn", "always"],
233
+
234
+ // 要求方法链中每个调用都有一个换行符
235
+ // https://zh-hans.eslint.org/docs/latest/rules/newline-per-chained-call
236
+ "newline-per-chained-call": ["warn", {
237
+ ignoreChainWithDepth: 4,
238
+ }],
239
+
240
+ // TODO
241
+ // 禁止冗余的括号
242
+ // https://zh-hans.eslint.org/docs/latest/rules/no-extra-parens
243
+ "no-extra-parens": ["warn", "all", {
244
+ conditionalAssign: false, // 允许在条件测试表达式中的赋值周围加上括号
245
+ returnAssign: false, // 允许在 return 语句中使用额外的小括号
246
+ nestedBinaryExpressions: false, // 允许在嵌套二进制表达式中使用额外的小括号
247
+ ternaryOperandBinaryExpressions: false, // 允许在三元运算符 ?: 的操作数周围添加额外的括号
248
+ ignoreJSX: "all", // 允许在没有/所有/多行/单行 JSX 组件周围使用额外的小括号,delegate to eslint-plugin-react
249
+ enforceForArrowConditionals: false, // 废弃 - 允许在作为箭头函数主体的三元表达式周围添加小括号
250
+ enforceForSequenceExpressions: false, // 允许在序列表达式周围加上小括号
251
+ enforceForNewInMemberExpressions: false, // 废弃 - 允许在成员表达式中的 new 表达式周围使用额外的小括号
252
+ enforceForFunctionPrototypeMethods: false, // 允许在函数表达式的即时 .call 和 .apply 方法调用周围以及同一上下文中的函数表达式周围添加括号
253
+ allowParensAfterCommentPattern: "", // 允许在匹配正则表达式的注释前面加上额外的括号
254
+ // nestedConditionalExpressions: false, // 允许在嵌套的条件表达式周围添加额外的小括号
255
+ }],
256
+
257
+ // 禁止空格和 tab 的混合缩进
258
+ "no-mixed-spaces-and-tabs": "error",
259
+
260
+ // 禁止使用多个空格
261
+ // https://zh-hans.eslint.org/docs/latest/rules/no-multi-spaces
262
+ "no-multi-spaces": ["warn", {
263
+ ignoreEOLComments: true,
264
+ exceptions: {},
265
+ }],
266
+
267
+ // 禁止出现多行空行
268
+ // https://zh-hans.eslint.org/docs/latest/rules/no-multiple-empty-lines
269
+ "no-multiple-empty-lines": ["warn", {
270
+ max: 2,
271
+ maxBOF: 1,
272
+ maxEOF: 1,
273
+ }],
274
+
275
+ // 禁用 tab
276
+ "no-tabs": ["error", {
277
+ allowIndentationTabs: false, // 允许缩进使用 tab
278
+ }],
279
+
280
+ // 禁用行尾空白
281
+ // 这条规则不允许在行末有尾随空格(空格、制表符和其他 Unicode 空白字符)
282
+ "no-trailing-spaces": ["warn", {
283
+ skipBlankLines: true,
284
+ ignoreComments: false,
285
+ }],
286
+
287
+ // 禁止属性前有空白
288
+ // https://zh-hans.eslint.org/docs/latest/rules/no-whitespace-before-property
289
+ "no-whitespace-before-property": "warn",
290
+
291
+ // 强制单个语句的位置
292
+ // 这条规则的目的是为单行语句执行一个一致的位置
293
+ // https://zh-hans.eslint.org/docs/latest/rules/nonblock-statement-body-position
294
+ "nonblock-statement-body-position": ["warn", "any"],
295
+
296
+ // 强制大括号内换行符的一致性
297
+ // https://zh-hans.eslint.org/docs/latest/rules/object-curly-newline
298
+ "object-curly-newline": ["warn", {
299
+ // 对象字面量
300
+ ObjectExpression: {
301
+ multiline: true,
302
+ consistent: true,
303
+ },
304
+ // 解构赋值
305
+ ObjectPattern: {
306
+ multiline: true,
307
+ consistent: true,
308
+ },
309
+ // 导入模块
310
+ ImportDeclaration: {
311
+ multiline: true,
312
+ consistent: true,
313
+ },
314
+ // 导出模块
315
+ ExportDeclaration: {
316
+ multiline: true,
317
+ minProperties: 1,
318
+ },
319
+ }],
320
+
321
+ // 强制在花括号中使用一致的空格
322
+ // https://zh-hans.eslint.org/docs/latest/rules/object-curly-spacing
323
+ "object-curly-spacing": ["warn", "always", {
324
+ arraysInObjects: true,
325
+ objectsInObjects: true,
326
+ }],
327
+
328
+ // 强制将对象的属性放在不同的行上
329
+ // https://zh-hans.eslint.org/docs/latest/rules/object-property-newline
330
+ "object-property-newline": ["warn", {
331
+ allowAllPropertiesOnSameLine: true,
332
+ }],
333
+
334
+ // 强制操作符使用一致的换行符
335
+ // https://zh-hans.eslint.org/docs/latest/rules/operator-linebreak
336
+ "operator-linebreak": ["warn", "none", {
337
+ overrides: { "=": "none" },
338
+ }],
339
+
340
+ // 要求或禁止块内填充
341
+ // 这条规则使块内的空行填充一致
342
+ // 支持自动修复,后续开启改规则,可以设置为 warn
343
+ "padded-blocks": "off",
344
+
345
+ // 要求或禁止语句之间的填充行
346
+ // 支持自动修复,后续开启改规则,可以设置为 warn
347
+ // https://zh-hans.eslint.org/docs/latest/rules/padding-line-between-statements
348
+ "padding-line-between-statements": "off",
349
+
350
+ // 强制使用一致的反勾号、双引号或单引号
351
+ // https://zh-hans.eslint.org/docs/latest/rules/quotes
352
+ "quotes": ["warn", "double", {
353
+ avoidEscape: true,
354
+ allowTemplateLiterals: false,
355
+ }],
356
+
357
+ // 要求或禁止使用分号代替 ASI(自动分号插入)
358
+ // https://zh-hans.eslint.org/docs/latest/rules/semi
359
+ "semi": ["warn", "always", {
360
+ omitLastInOneLineBlock: false,
361
+ omitLastInOneLineClassBody: false,
362
+ }],
363
+
364
+ // 强制分号之前和之后使用一致的空格
365
+ // https://zh-hans.eslint.org/docs/latest/rules/semi-spacing
366
+ "semi-spacing": ["warn", {
367
+ before: false,
368
+ after: true,
369
+ }],
370
+
371
+ // 强制分号的位置
372
+ // https://zh-hans.eslint.org/docs/latest/rules/semi-style
373
+ "semi-style": ["warn", "last"],
374
+
375
+ // TODO
376
+ // 要求或禁止语句块之前的空格(代码块大括号前面是否需要空格)
377
+ // https://zh-hans.eslint.org/docs/latest/rules/space-before-blocks
378
+ "space-before-blocks": ["warn", {
379
+ functions: "always",
380
+ keywords: "always",
381
+ classes: "always",
382
+ // modules: "always",
383
+ }],
384
+
385
+ // TODO
386
+ // 强制在 function 的左括号之前使用一致的空格
387
+ // https://zh-hans.eslint.org/docs/latest/rules/space-before-function-paren
388
+ "space-before-function-paren": ["warn", {
389
+ anonymous: "never",
390
+ named: "never",
391
+ asyncArrow: "always",
392
+ // catch: "never",
393
+ }],
394
+
395
+ // 强制在圆括号内使用一致的空格
396
+ // https://zh-hans.eslint.org/docs/latest/rules/space-in-parens
397
+ "space-in-parens": ["warn", "never", {
398
+ exceptions: [],
399
+ }],
400
+
401
+ // TODO
402
+ // 要求中缀操作符周围有空格(+-*/?| etc.)
403
+ // https://zh-hans.eslint.org/docs/latest/rules/space-infix-ops
404
+ "space-infix-ops": ["warn", {
405
+ // 设置 int32Hint 选项为 true(默认为是 false),以允许写 a|0 时不留空格
406
+ int32Hint: false,
407
+ // ignoreTypes: false,
408
+ }],
409
+
410
+ // 强制在一元操作符前后使用一致的空格
411
+ // https://zh-hans.eslint.org/docs/latest/rules/space-unary-ops
412
+ "space-unary-ops": ["warn", {
413
+ words: true, // 适用于单数词运算符,如 new, delete, typeof, void, yield
414
+ nonwords: false, // 适用于单数运算符,如 -, +, --, ++, !, !!
415
+ overrides: {},
416
+ }],
417
+
418
+ // 强制在 switch 的冒号左右有空格
419
+ // https://zh-hans.eslint.org/docs/latest/rules/switch-colon-spacing
420
+ "switch-colon-spacing": ["warn", {
421
+ after: true,
422
+ before: false,
423
+ }],
424
+
425
+ // 要求或禁止 Unicode 字节顺序标记 (BOM)
426
+ // 支持自动修复,后续开启改规则,可以设置为 warn
427
+ // https://zh-hans.eslint.org/docs/latest/rules/unicode-bom
428
+ "unicode-bom": ["off", "never"],
429
+
430
+ // 要求 IIFE 使用括号括起来
431
+ // 这条规则要求所有立即调用的函数表达式都要用圆括号包裹起来
432
+ // https://zh-hans.eslint.org/docs/latest/rules/wrap-iife
433
+ "wrap-iife": ["warn", "inside", {
434
+ functionPrototypeMethods: true,
435
+ }],
436
+
437
+ // 要求正则表达式被括号括起来
438
+ // 支持自动修复,后续开启改规则,可以设置为 warn
439
+ "wrap-regex": "off",
440
+ },
441
+ };