@houheaven/eslint-config-helper 1.4.0 → 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 (91) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +149 -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 +24 -32
  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 +38 -22
  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/typescript.js +0 -10
  73. package/lib/configs/vue2.js +0 -28
  74. package/lib/configs/vue3.js +0 -28
  75. package/lib/eslint.js +0 -18
  76. package/lib/format.js +0 -40
  77. package/lib/rules/eslint/best-practices.js +0 -422
  78. package/lib/rules/eslint/node.js +0 -48
  79. package/lib/rules/eslint/strict-mode.js +0 -12
  80. package/lib/rules/eslint/stylistic-issues.js +0 -578
  81. package/lib/rules/eslint/variables.js +0 -73
  82. package/lib/rules/typescript/all.js +0 -193
  83. package/lib/rules/typescript/base.js +0 -10
  84. package/lib/rules/typescript/eslint-recommended.js +0 -36
  85. package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
  86. package/lib/rules/typescript/recommended.js +0 -36
  87. package/lib/rules/typescript/strict.js +0 -47
  88. package/lib/rules/vue/common-eslint.js +0 -220
  89. package/lib/rules/vue/vue2-recommended.js +0 -17
  90. package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
  91. package/lib/rules/vue/vue3-recommended.js +0 -17
@@ -6,185 +6,194 @@
6
6
 
7
7
  module.exports = {
8
8
  rules: {
9
- // Enforce “for” loop update clause moving the counter in the right direction
10
- // https://eslint.org/docs/rules/for-direction
11
- // "for-direction": "error",
9
+ // 防止死循环,执行“for”循环更新子句,使计数器朝着正确的方向移动
10
+ "for-direction": "error",
12
11
 
13
- // Enforces that a return statement is present in property getters
14
- // https://eslint.org/docs/rules/getter-return
15
- // "getter-return": ["error", { allowImplicit: true }],
12
+ // 禁止与-0进行比较
13
+ // 这条规则应该对试图与 -0 比较的代码提出警告,因为这不会像预期的那样工作。也就是说,像 x === -0 这样的代码对于 +0 和 -0 都会通过。作者可能想要的是 Object.is(x, -0)。
14
+ "no-compare-neg-zero": "error",
16
15
 
17
- // disallow using an async function as a Promise executor
18
- // https://eslint.org/docs/rules/no-async-promise-executor
19
- // "no-async-promise-executor": "error",
16
+ // 禁止在条件表达式中使用赋值运算符
17
+ // 在条件语句中,很容易把比较运算符(如 ==)误打成赋值运算符(如 =)
18
+ // 使用此规则禁用 if、for、while 和 do...while 测试条件中的模糊赋值运算符
19
+ "no-cond-assign": ["error", "always"],
20
20
 
21
- // Disallow await inside of loops
22
- // https://eslint.org/docs/rules/no-await-in-loop
23
- // "no-await-in-loop": "error",
24
-
25
- // Disallow comparisons to negative zero
26
- // https://eslint.org/docs/rules/no-compare-neg-zero
27
- // "no-compare-neg-zero": "error",
28
-
29
- // disallow assignment in conditional expressions
30
- // "no-cond-assign": ["error", "always"],
31
-
32
- // 禁用 console
33
- "no-console": "off",
21
+ // Disallow expressions where the operation doesn't affect the value
22
+ // https://zh-hans.eslint.org/docs/latest/rules/no-constant-binary-expression
23
+ "no-constant-binary-expression": "error",
34
24
 
35
25
  // 禁止条件中的常量表达式
36
- "no-constant-condition": "warn",
26
+ // 这条规则不允许在以下测试条件中使用常量表达式:
27
+ // - if、for、while 或 do...while 语句
28
+ // - ?: 三元表达式
29
+ // https://zh-hans.eslint.org/docs/latest/rules/no-constant-condition
30
+ "no-constant-condition": ["error", {
31
+ // 默认为 true。将此选项设置为 false 允许在循环中使用常量表达式。
32
+ checkLoops: true,
33
+ }],
37
34
 
38
- // disallow control characters in regular expressions
39
- // "no-control-regex": "error",
35
+ // 禁止在正则表达式中使用控制字符
36
+ // 控制字符是 ASCII 范围内 0-31 的特殊、不可见的字符。这些字符在 JavaScript 字符串中很少使用,所以一个包含明确匹配这些字符的元素的正则表达式很可能是一个错误。
37
+ // 这条规则不允许使用控制字符和一些转义序列与正则表达式中的控制字符匹配。
38
+ "no-control-regex": "error",
40
39
 
41
40
  // 禁用 debugger
42
41
  "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
43
42
 
44
- // disallow duplicate arguments in functions
45
- // "no-dupe-args": "error",
46
-
47
- // Disallow duplicate conditions in if-else-if chains
48
- // https://eslint.org/docs/rules/no-dupe-else-if
49
- // "no-dupe-else-if": "error",
43
+ // 禁止函数参数名称重复
44
+ // https://zh-hans.eslint.org/docs/latest/rules/no-dupe-args
45
+ "no-dupe-args": "error",
50
46
 
51
- // disallow duplicate keys when creating object literals
52
- // "no-dupe-keys": "error",
47
+ // 禁止在 if-else-if 中存在重复条件
48
+ // 这条规则不允许在同一个 if-else-if 链中出现重复的条件。
49
+ "no-dupe-else-if": "error",
53
50
 
54
- // disallow a duplicate case label.
55
- // "no-duplicate-case": "error",
51
+ // 禁止对象字面中的键名重复
52
+ "no-dupe-keys": "error",
56
53
 
57
- // disallow empty statements
58
- // "no-empty": "error",
54
+ // 禁止在 switch 的 case 子句中重复测试表达式
55
+ "no-duplicate-case": "error",
59
56
 
60
- // disallow the use of empty character classes in regular expressions
61
- // "no-empty-character-class": "error",
57
+ // 禁止在正则表达式中使用空字符类
58
+ // https://zh-hans.eslint.org/docs/latest/rules/no-empty-character-class
59
+ "no-empty-character-class": "error",
62
60
 
63
61
  // disallow assigning to the exception in a catch block
64
- // "no-ex-assign": "error",
65
-
66
- // 禁止不必要的布尔转换
67
- // https://eslint.org/docs/rules/no-extra-boolean-cast
68
- "no-extra-boolean-cast": "off",
69
-
70
- // 禁止冗余的括号
71
- // https://eslint.org/docs/rules/no-extra-parens
72
- "no-extra-parens": ["off", "all", {
73
- conditionalAssign: true,
74
- nestedBinaryExpressions: false,
75
- returnAssign: false,
76
- ignoreJSX: "all", // delegate to eslint-plugin-react
77
- enforceForArrowConditionals: false,
62
+ // https://zh-hans.eslint.org/docs/latest/rules/no-ex-assign
63
+ "no-ex-assign": "error",
64
+
65
+ // 禁止条件语句中的“穿透”行为
66
+ // case 语句中需要有 break,防止穿透到下一个 case 语句
67
+ // https://zh-hans.eslint.org/docs/latest/rules/no-fallthrough
68
+ "no-fallthrough": ["error", {
69
+ commentPattern: "",
70
+ allowEmptyCase: true,
78
71
  }],
79
72
 
80
- // 禁止不必要的分号
81
- "no-extra-semi": "warn",
73
+ // 禁止对函数赋值
74
+ // 这条规则不允许重新分配 function 的声明
75
+ // https://zh-hans.eslint.org/docs/latest/rules/no-func-assign
76
+ "no-func-assign": "error",
82
77
 
83
- // disallow overwriting functions written as function declarations
84
- // "no-func-assign": "error",
78
+ // 禁止在嵌套块中声明变量或函数
79
+ // https://zh-hans.eslint.org/docs/latest/rules/no-inner-declarations
80
+ "no-inner-declarations": ["error", "functions"],
85
81
 
86
- // https://eslint.org/docs/rules/no-import-assign
87
- // "no-import-assign": "error",
88
-
89
- // disallow function or variable declarations in nested blocks
90
- // "no-inner-declarations": "error",
91
-
92
- // disallow invalid regular expression strings in the RegExp constructor
93
- // "no-invalid-regexp": "error",
82
+ // 禁止在 RegExp 构造函数中使用无效的正则表达式字符串
83
+ "no-invalid-regexp": "error",
94
84
 
95
85
  // 禁止不规则的空格
86
+ // https://zh-hans.eslint.org/docs/latest/rules/no-irregular-whitespace
96
87
  "no-irregular-whitespace": ["error", {
97
- "skipStrings": true,
98
- "skipComments": false,
99
- "skipRegExps": false,
100
- "skipTemplates": false,
88
+ skipStrings: false,
89
+ skipComments: false,
90
+ skipRegExps: false,
91
+ skipTemplates: false,
101
92
  }],
102
93
 
103
94
  // 禁止失去精度的文字数字
104
- // https://eslint.org/docs/rules/no-loss-of-precision
95
+ // https://zh-hans.eslint.org/docs/latest/rules/no-loss-of-precision
105
96
  "no-loss-of-precision": "error",
106
97
 
107
98
  // Disallow characters which are made with multiple code points in character class syntax
108
- // https://eslint.org/docs/rules/no-misleading-character-class
109
- // "no-misleading-character-class": "error",
110
-
111
- // disallow the use of object properties of the global object (Math and JSON) as functions
112
- // "no-obj-calls": "error",
99
+ // https://zh-hans.eslint.org/docs/latest/rules/no-misleading-character-class
100
+ "no-misleading-character-class": "error",
113
101
 
114
- // Disallow returning values from Promise executor functions
115
- // https://eslint.org/docs/rules/no-promise-executor-return
116
- // "no-promise-executor-return": "error",
102
+ // 这条规则不允许将 Math、JSON、Reflect、Atomics 和 Intl 对象作为函数调用
103
+ // https://zh-hans.eslint.org/docs/latest/rules/no-obj-calls
104
+ "no-obj-calls": "error",
117
105
 
118
- // disallow use of Object.prototypes builtins directly
119
- // https://eslint.org/docs/rules/no-prototype-builtins
120
- // "no-prototype-builtins": "error",
106
+ // 不允许直接在对象上调用某些 Object.prototype 方法
107
+ // https://zh-hans.eslint.org/docs/latest/rules/no-prototype-builtins
108
+ "no-prototype-builtins": "error",
121
109
 
122
- // disallow multiple spaces in a regular expression literal
123
- // "no-regex-spaces": "error",
110
+ // 禁止将变量赋值给它自己
111
+ // https://zh-hans.eslint.org/docs/latest/rules/no-self-assign
112
+ "no-self-assign": ["error", {
113
+ props: true,
114
+ }],
124
115
 
125
- // Disallow returning values from setters
126
- // https://eslint.org/docs/rules/no-setter-return
127
- // "no-setter-return": "error",
116
+ // 禁止将变量与自身进行比较
117
+ // https://zh-hans.eslint.org/docs/latest/rules/no-self-compare
118
+ "no-self-compare": "error",
128
119
 
129
- // 禁止稀疏数组
120
+ // 禁止使用稀疏数组
121
+ // 稀疏数组包含空槽,最常见的原因是在数组字面中使用了多个逗号(比如:[,,])
122
+ // https://zh-hans.eslint.org/docs/latest/rules/no-sparse-arrays
130
123
  "no-sparse-arrays": "error",
131
124
 
132
- // 禁止在字符串中使用模板文字占位符语法
133
- // https://eslint.org/docs/rules/no-template-curly-in-string
134
- "no-template-curly-in-string": "error",
125
+ // 禁止未定义的变量
126
+ "no-undef": ["error", {
127
+ typeof: true,
128
+ }],
135
129
 
136
130
  // 禁止出现令人困惑的多行表达式
137
- // https://eslint.org/docs/rules/no-unexpected-multiline
131
+ // 这条规则不允许出现混乱的多行表达式,即换行看起来像是在结束一个语句,但实际上不是。
132
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unexpected-multiline
138
133
  "no-unexpected-multiline": "error",
139
134
 
140
- // disallow unreachable statements after a return, throw, continue, or break statement
141
- // "no-unreachable": "error",
135
+ // 不允许未修改的循环条件
136
+ // 经常会循环中修改循环条件中的变量。 如果没有,那可能是个错误。
137
+ // 这条规则会找到位于循环条件内的引用,然后检查是否有在循环中修改这些引用的变量。
138
+ "no-unmodified-loop-condition": "error",
142
139
 
143
- // Disallow loops with a body that allows only one iteration
144
- // https://eslint.org/docs/rules/no-unreachable-loop
145
- // "no-unreachable-loop": ["error", {
146
- // ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
147
- // }],
140
+ // 不允许在 return、throw、continue、break 语句后出现无法访问的代码
141
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unreachable
142
+ "no-unreachable": "error",
148
143
 
149
- // disallow return/throw/break/continue inside finally blocks
150
- // https://eslint.org/docs/rules/no-unsafe-finally
151
- // "no-unsafe-finally": "error",
152
-
153
- // disallow negating the left operand of relational operators
154
- // https://eslint.org/docs/rules/no-unsafe-negation
155
- // "no-unsafe-negation": "error",
156
-
157
- // disallow use of optional chaining in contexts where the undefined value is not allowed
158
- // https://eslint.org/docs/rules/no-unsafe-optional-chaining
159
- // "no-unsafe-optional-chaining": ["error", { disallowArithmeticOperators: true }],
144
+ // 禁止只允许一次迭代的循环体
145
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unreachable-loop
146
+ "no-unreachable-loop": ["error", {
147
+ ignore: [], // WhileStatement, DoWhileStatement, ForStatement, ForInStatement, ForOfStatement
148
+ }],
160
149
 
161
- // Disallow Unused Private Class Members
162
- // https://eslint.org/docs/rules/no-unused-private-class-members
163
- // TODO: enable once eslint 7 is dropped (which is semver-major)
164
- // "no-unused-private-class-members": "off",
150
+ // 禁止在finally块中使用控制流语句
151
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unsafe-finally
152
+ "no-unsafe-finally": "error",
165
153
 
166
- // Disallow useless backreferences in regular expressions
167
- // https://eslint.org/docs/rules/no-useless-backreference
168
- // "no-useless-backreference": "error",
154
+ // 禁止对关系操作符的左操作数取反
155
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unsafe-negation
156
+ "no-unsafe-negation": ["error", {
157
+ enforceForOrderingRelations: false,
158
+ }],
169
159
 
170
- // disallow negation of the left operand of an in expression
171
- // deprecated in favor of no-unsafe-negation
172
- // "no-negated-in-lhs": "off",
160
+ // 禁止定义变量后不使用
161
+ // https://zh-hans.eslint.org/docs/latest/rules/no-unused-vars
162
+ "no-unused-vars": ["error", {
163
+ vars: "all",
164
+ varsIgnorePattern: "",
165
+ args: "after-used", // 参数相关
166
+ argsIgnorePattern: "^_|^(evt|err)\\d*$|^(resolve|reject)$", // 指定了不检查使用情况的例外情况:参数的名称与 regexp 模式相匹配。例如,名称以下划线开头的变量。
167
+ caughtErrors: "none",
168
+ caughtErrorsIgnorePattern: "^_|^(e|err|error)\\d*$", // try-catch 代码块
169
+ destructuredArrayIgnorePattern: "", // 数组解构相关
170
+ ignoreRestSiblings: true,
171
+ }],
173
172
 
174
- // Disallow assignments that can lead to race conditions due to usage of await or yield
175
- // https://eslint.org/docs/rules/require-atomic-updates
176
- // note: not enabled because it is very buggy
177
- // "require-atomic-updates": "off",
173
+ // 禁止定义前使用
174
+ // https://zh-hans.eslint.org/docs/latest/rules/no-use-before-define
175
+ "no-use-before-define": ["error", {
176
+ functions: false,
177
+ classes: true,
178
+ variables: true,
179
+ allowNamedExports: false,
180
+ }],
178
181
 
179
- // disallow comparisons with the value NaN
180
- // "use-isnan": "error",
182
+ // Disallow useless backreferences in regular expressions
183
+ // https://zh-hans.eslint.org/docs/latest/rules/no-useless-backreference
184
+ "no-useless-backreference": "error",
181
185
 
182
- // ensure JSDoc comments are valid
183
- // https://eslint.org/docs/rules/valid-jsdoc
184
- // "valid-jsdoc": "off",
186
+ // 要求使用 isNaN() 检测 NaN
187
+ "use-isnan": ["error", {
188
+ enforceForSwitchCase: true, // 不允许在 switch 语句中使用 case NaN 和 switch(NaN)
189
+ enforceForIndexOf: true, // 不允许使用 indexOf(NaN) 或 lastIndexOf(NaN)
190
+ }],
185
191
 
186
- // ensure that the results of typeof are compared against a valid string
187
- // https://eslint.org/docs/rules/valid-typeof
188
- // "valid-typeof": ["error", { requireStringLiterals: true }],
192
+ // 这条规则强制将 typeof 表达式与有效的字符串字面量进行比较。
193
+ // 有效的字符串字面量:"undefined", "object", "boolean", "number", "string", "function", "symbol", and "bigint"
194
+ // https://zh-hans.eslint.org/docs/latest/rules/valid-typeof
195
+ "valid-typeof": ["error", {
196
+ requireStringLiterals: true,
197
+ }],
189
198
  },
190
199
  };