@houheaven/eslint-config-helper 1.4.0 → 2.1.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.
- package/LICENSE +21 -21
- package/README.md +149 -28
- package/lib/format-es5.js +23 -0
- package/lib/format-es6.js +25 -0
- package/lib/format-html.js +23 -0
- package/lib/format-import.js +23 -0
- package/lib/format-typescript.js +28 -0
- package/lib/format-vue2.js +23 -0
- package/lib/format-vue3.js +23 -0
- package/lib/html.js +16 -22
- package/lib/import.js +26 -0
- package/lib/javascript-es5.js +25 -0
- package/lib/javascript-es6.js +28 -0
- package/lib/support/es5-support.js +29 -0
- package/lib/support/es6-support.js +39 -0
- package/lib/support/html-support.js +38 -0
- package/lib/support/import-bugfix.js +65 -0
- package/lib/support/import-support.js +25 -0
- package/lib/support/typescript-support.js +27 -0
- package/lib/support/vue2-support.js +43 -0
- package/lib/support/vue3-support.js +43 -0
- package/lib/support/vue3-ts-support.js +51 -0
- package/lib/typescript.js +27 -32
- package/lib/utils/utils.js +2 -0
- package/lib/vue2.js +19 -22
- package/lib/vue3-ts.js +32 -0
- package/lib/vue3.js +16 -17
- package/node_modules/@houheaven/eslint-config-helper-core/package.json +7 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_deprecated.js +132 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_removed.js +25 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/es6.js +365 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +441 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/possible-errors.js +199 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/suggestions.js +666 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/accessibility.js +68 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/best-practice.js +150 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/seo.js +29 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/html/style.js +70 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/helpful-warnings.js +23 -18
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/module-systems.js +33 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/static-analysis.js +85 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/import/style-guide.js +125 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/_deprecated.js +57 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/conflict.js +16 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/deprecated.js +41 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/extension.js +207 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/fixable.js +215 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/other.js +125 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/stylistic.js +34 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/suggestion.js +53 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/type-checked.js +263 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/_deprecated.js +37 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-base.js +1 -11
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-essential.js +25 -38
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-extension.js +321 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-recommended.js +64 -31
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-strongly-recommended.js +37 -20
- package/{lib/rules/vue/common-extra.js → node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-uncategorized.js} +141 -52
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-essential.js +16 -14
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue2-uncategorized.js +15 -0
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-essential.js +54 -24
- package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-strongly-recommended.js +8 -10
- package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue3-uncategorized.js +115 -0
- package/node_modules/@houheaven/eslint-config-helper-core/summary.js +57 -0
- package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +160 -0
- package/package.json +59 -25
- package/lib/configs/eslint-es5.js +0 -24
- package/lib/configs/eslint.js +0 -23
- package/lib/configs/format-html.js +0 -22
- package/lib/configs/format-js.js +0 -134
- package/lib/configs/format-vue.js +0 -278
- package/lib/configs/html.js +0 -20
- package/lib/configs/import-bugfix.js +0 -36
- package/lib/configs/import.js +0 -44
- package/lib/configs/typescript.js +0 -10
- package/lib/configs/vue2.js +0 -28
- package/lib/configs/vue3.js +0 -28
- package/lib/eslint.js +0 -18
- package/lib/format.js +0 -40
- package/lib/rules/eslint/best-practices.js +0 -422
- package/lib/rules/eslint/es6.js +0 -196
- package/lib/rules/eslint/node.js +0 -48
- package/lib/rules/eslint/possible-errors.js +0 -190
- package/lib/rules/eslint/strict-mode.js +0 -12
- package/lib/rules/eslint/stylistic-issues.js +0 -578
- package/lib/rules/eslint/variables.js +0 -73
- package/lib/rules/html/accessibility.js +0 -44
- package/lib/rules/html/best-practice.js +0 -64
- package/lib/rules/html/seo.js +0 -24
- package/lib/rules/html/style.js +0 -32
- package/lib/rules/import/module-systems.js +0 -34
- package/lib/rules/import/static-analysis.js +0 -69
- package/lib/rules/import/style-guide.js +0 -97
- package/lib/rules/typescript/all.js +0 -193
- package/lib/rules/typescript/base.js +0 -10
- package/lib/rules/typescript/eslint-recommended.js +0 -36
- package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
- package/lib/rules/typescript/recommended.js +0 -36
- package/lib/rules/typescript/strict.js +0 -47
- package/lib/rules/vue/common-eslint.js +0 -220
- package/lib/rules/vue/vue2-recommended.js +0 -17
- package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
- package/lib/rules/vue/vue3-recommended.js +0 -17
- /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vuejs-accessibility/index.js +0 -0
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// Possible Errors
|
|
4
|
+
// 这些规则与 JavaScript 代码中可能的错误或逻辑错误有关
|
|
5
|
+
// ==========================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
rules: {
|
|
9
|
+
// 防止死循环,执行“for”循环更新子句,使计数器朝着正确的方向移动
|
|
10
|
+
"for-direction": "error",
|
|
11
|
+
|
|
12
|
+
// 禁止与-0进行比较
|
|
13
|
+
// 这条规则应该对试图与 -0 比较的代码提出警告,因为这不会像预期的那样工作。也就是说,像 x === -0 这样的代码对于 +0 和 -0 都会通过。作者可能想要的是 Object.is(x, -0)。
|
|
14
|
+
"no-compare-neg-zero": "error",
|
|
15
|
+
|
|
16
|
+
// 禁止在条件表达式中使用赋值运算符
|
|
17
|
+
// 在条件语句中,很容易把比较运算符(如 ==)误打成赋值运算符(如 =)
|
|
18
|
+
// 使用此规则禁用 if、for、while 和 do...while 测试条件中的模糊赋值运算符
|
|
19
|
+
"no-cond-assign": ["error", "always"],
|
|
20
|
+
|
|
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",
|
|
24
|
+
|
|
25
|
+
// 禁止条件中的常量表达式
|
|
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
|
+
}],
|
|
34
|
+
|
|
35
|
+
// 禁止在正则表达式中使用控制字符
|
|
36
|
+
// 控制字符是 ASCII 范围内 0-31 的特殊、不可见的字符。这些字符在 JavaScript 字符串中很少使用,所以一个包含明确匹配这些字符的元素的正则表达式很可能是一个错误。
|
|
37
|
+
// 这条规则不允许使用控制字符和一些转义序列与正则表达式中的控制字符匹配。
|
|
38
|
+
"no-control-regex": "error",
|
|
39
|
+
|
|
40
|
+
// 禁用 debugger
|
|
41
|
+
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
|
|
42
|
+
|
|
43
|
+
// 禁止函数参数名称重复
|
|
44
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-dupe-args
|
|
45
|
+
"no-dupe-args": "error",
|
|
46
|
+
|
|
47
|
+
// 禁止在 if-else-if 中存在重复条件
|
|
48
|
+
// 这条规则不允许在同一个 if-else-if 链中出现重复的条件。
|
|
49
|
+
"no-dupe-else-if": "error",
|
|
50
|
+
|
|
51
|
+
// 禁止对象字面中的键名重复
|
|
52
|
+
"no-dupe-keys": "error",
|
|
53
|
+
|
|
54
|
+
// 禁止在 switch 的 case 子句中重复测试表达式
|
|
55
|
+
"no-duplicate-case": "error",
|
|
56
|
+
|
|
57
|
+
// 禁止在正则表达式中使用空字符类
|
|
58
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-empty-character-class
|
|
59
|
+
"no-empty-character-class": "error",
|
|
60
|
+
|
|
61
|
+
// disallow assigning to the exception in a catch block
|
|
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,
|
|
71
|
+
}],
|
|
72
|
+
|
|
73
|
+
// 禁止对函数赋值
|
|
74
|
+
// 这条规则不允许重新分配 function 的声明
|
|
75
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-func-assign
|
|
76
|
+
"no-func-assign": "error",
|
|
77
|
+
|
|
78
|
+
// 禁止在嵌套块中声明变量或函数
|
|
79
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-inner-declarations
|
|
80
|
+
"no-inner-declarations": ["error", "functions"],
|
|
81
|
+
|
|
82
|
+
// 禁止在 RegExp 构造函数中使用无效的正则表达式字符串
|
|
83
|
+
"no-invalid-regexp": "error",
|
|
84
|
+
|
|
85
|
+
// 禁止不规则的空格
|
|
86
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-irregular-whitespace
|
|
87
|
+
"no-irregular-whitespace": ["error", {
|
|
88
|
+
skipStrings: false,
|
|
89
|
+
skipComments: false,
|
|
90
|
+
skipRegExps: false,
|
|
91
|
+
skipTemplates: false,
|
|
92
|
+
}],
|
|
93
|
+
|
|
94
|
+
// 禁止失去精度的文字数字
|
|
95
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-loss-of-precision
|
|
96
|
+
"no-loss-of-precision": "error",
|
|
97
|
+
|
|
98
|
+
// Disallow characters which are made with multiple code points in character class syntax
|
|
99
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-misleading-character-class
|
|
100
|
+
"no-misleading-character-class": "error",
|
|
101
|
+
|
|
102
|
+
// 这条规则不允许将 Math、JSON、Reflect、Atomics 和 Intl 对象作为函数调用
|
|
103
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-obj-calls
|
|
104
|
+
"no-obj-calls": "error",
|
|
105
|
+
|
|
106
|
+
// 不允许直接在对象上调用某些 Object.prototype 方法
|
|
107
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-prototype-builtins
|
|
108
|
+
"no-prototype-builtins": "error",
|
|
109
|
+
|
|
110
|
+
// 禁止将变量赋值给它自己
|
|
111
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-self-assign
|
|
112
|
+
"no-self-assign": ["error", {
|
|
113
|
+
props: true,
|
|
114
|
+
}],
|
|
115
|
+
|
|
116
|
+
// 禁止将变量与自身进行比较
|
|
117
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-self-compare
|
|
118
|
+
"no-self-compare": "error",
|
|
119
|
+
|
|
120
|
+
// 禁止使用稀疏数组
|
|
121
|
+
// 稀疏数组包含空槽,最常见的原因是在数组字面中使用了多个逗号(比如:[,,])
|
|
122
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-sparse-arrays
|
|
123
|
+
"no-sparse-arrays": "error",
|
|
124
|
+
|
|
125
|
+
// 禁止未定义的变量
|
|
126
|
+
"no-undef": ["error", {
|
|
127
|
+
typeof: true,
|
|
128
|
+
}],
|
|
129
|
+
|
|
130
|
+
// 禁止出现令人困惑的多行表达式
|
|
131
|
+
// 这条规则不允许出现混乱的多行表达式,即换行看起来像是在结束一个语句,但实际上不是。
|
|
132
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unexpected-multiline
|
|
133
|
+
"no-unexpected-multiline": "error",
|
|
134
|
+
|
|
135
|
+
// 不允许未修改的循环条件
|
|
136
|
+
// 经常会循环中修改循环条件中的变量。 如果没有,那可能是个错误。
|
|
137
|
+
// 这条规则会找到位于循环条件内的引用,然后检查是否有在循环中修改这些引用的变量。
|
|
138
|
+
"no-unmodified-loop-condition": "error",
|
|
139
|
+
|
|
140
|
+
// 不允许在 return、throw、continue、break 语句后出现无法访问的代码
|
|
141
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unreachable
|
|
142
|
+
"no-unreachable": "error",
|
|
143
|
+
|
|
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
|
+
}],
|
|
149
|
+
|
|
150
|
+
// 禁止在finally块中使用控制流语句
|
|
151
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unsafe-finally
|
|
152
|
+
"no-unsafe-finally": "error",
|
|
153
|
+
|
|
154
|
+
// 禁止对关系操作符的左操作数取反
|
|
155
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unsafe-negation
|
|
156
|
+
"no-unsafe-negation": ["error", {
|
|
157
|
+
enforceForOrderingRelations: false,
|
|
158
|
+
}],
|
|
159
|
+
|
|
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
|
+
}],
|
|
172
|
+
|
|
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
|
+
}],
|
|
181
|
+
|
|
182
|
+
// Disallow useless backreferences in regular expressions
|
|
183
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-backreference
|
|
184
|
+
"no-useless-backreference": "error",
|
|
185
|
+
|
|
186
|
+
// 要求使用 isNaN() 检测 NaN
|
|
187
|
+
"use-isnan": ["error", {
|
|
188
|
+
enforceForSwitchCase: true, // 不允许在 switch 语句中使用 case NaN 和 switch(NaN)
|
|
189
|
+
enforceForIndexOf: true, // 不允许使用 indexOf(NaN) 或 lastIndexOf(NaN)
|
|
190
|
+
}],
|
|
191
|
+
|
|
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
|
+
}],
|
|
198
|
+
},
|
|
199
|
+
};
|