@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.
- 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 +13 -22
- package/lib/import.js +23 -0
- package/lib/javascript-es5.js +23 -0
- package/lib/javascript-es6.js +25 -0
- package/lib/rules/eslint/_deprecated.js +132 -0
- package/lib/rules/eslint/_removed.js +25 -0
- package/lib/rules/eslint/es6.js +279 -110
- package/lib/rules/eslint/layout-formatting.js +441 -0
- package/lib/rules/eslint/possible-errors.js +140 -131
- package/lib/rules/eslint/suggestions.js +666 -0
- package/lib/rules/html/accessibility.js +47 -23
- package/lib/rules/html/best-practice.js +122 -36
- package/lib/rules/html/seo.js +16 -11
- package/lib/rules/html/style.js +53 -15
- package/lib/rules/import/helpful-warnings.js +23 -18
- package/lib/rules/import/module-systems.js +16 -17
- package/lib/rules/import/static-analysis.js +54 -38
- package/lib/rules/import/style-guide.js +89 -61
- package/lib/rules/typescript/_deprecated.js +57 -0
- package/lib/rules/typescript/conflict.js +16 -0
- package/lib/rules/typescript/deprecated.js +41 -0
- package/lib/rules/typescript/extension.js +207 -0
- package/lib/rules/typescript/fixable.js +215 -0
- package/lib/rules/typescript/other.js +125 -0
- package/lib/rules/typescript/stylistic.js +34 -0
- package/lib/rules/typescript/suggestion.js +53 -0
- package/lib/rules/typescript/type-checked.js +263 -0
- package/lib/rules/vue/_deprecated.js +37 -0
- package/lib/rules/vue/common-base.js +1 -11
- package/lib/rules/vue/common-essential.js +25 -38
- package/lib/rules/vue/common-extension.js +321 -0
- package/lib/rules/vue/common-recommended.js +64 -31
- package/lib/rules/vue/common-strongly-recommended.js +37 -20
- package/lib/rules/vue/{common-extra.js → common-uncategorized.js} +141 -52
- package/lib/rules/vue/vue2-essential.js +16 -14
- package/lib/rules/vue/vue2-uncategorized.js +15 -0
- package/lib/rules/vue/vue3-essential.js +54 -24
- package/lib/rules/vue/vue3-strongly-recommended.js +8 -10
- package/lib/rules/vue/vue3-uncategorized.js +115 -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 +24 -32
- package/lib/utils/utils.js +160 -0
- package/lib/vue2.js +16 -22
- package/lib/vue3-ts.js +31 -0
- package/lib/vue3.js +13 -17
- package/package.json +38 -22
- 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/node.js +0 -48
- 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/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
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// Suggestions
|
|
4
|
+
// 这些规则提出了做事的替代方法
|
|
5
|
+
// ==========================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
rules: {
|
|
9
|
+
// 在定义的范围内强制使用变量
|
|
10
|
+
// https://zh-hans.eslint.org/docs/latest/rules/block-scoped-var
|
|
11
|
+
"block-scoped-var": "error",
|
|
12
|
+
|
|
13
|
+
// 要求使用骆驼拼写法
|
|
14
|
+
// https://zh-hans.eslint.org/docs/latest/rules/camelcase
|
|
15
|
+
"camelcase": ["error", {
|
|
16
|
+
properties: "always", // always 执行属性名称的骆驼大写风格
|
|
17
|
+
ignoreDestructuring: false, // false 对非结构化的标识符执行驼峰大写风格
|
|
18
|
+
ignoreImports: false, // false 对 ES2015 导入执行骆驼大写风格
|
|
19
|
+
ignoreGlobals: false, // false 对全局变量执行骆驼大写风格
|
|
20
|
+
allow: [],
|
|
21
|
+
}],
|
|
22
|
+
|
|
23
|
+
// 强制或禁止注释首字母大写
|
|
24
|
+
// https://zh-hans.eslint.org/docs/latest/rules/capitalized-comments
|
|
25
|
+
"capitalized-comments": ["off", "never", {
|
|
26
|
+
line: {
|
|
27
|
+
ignorePattern: ".*",
|
|
28
|
+
ignoreInlineComments: true,
|
|
29
|
+
ignoreConsecutiveComments: true,
|
|
30
|
+
},
|
|
31
|
+
block: {
|
|
32
|
+
ignorePattern: ".*",
|
|
33
|
+
ignoreInlineComments: true,
|
|
34
|
+
ignoreConsecutiveComments: true,
|
|
35
|
+
},
|
|
36
|
+
}],
|
|
37
|
+
|
|
38
|
+
// 强制实现程序中允许的最大循环复杂度
|
|
39
|
+
// https://zh-hans.eslint.org/docs/latest/rules/complexity
|
|
40
|
+
"complexity": ["error", {
|
|
41
|
+
max: 100,
|
|
42
|
+
}],
|
|
43
|
+
|
|
44
|
+
// 要求返回语句要么始终指定值,要么从不指定值
|
|
45
|
+
// https://zh-hans.eslint.org/docs/latest/rules/consistent-return
|
|
46
|
+
"consistent-return": ["error", {
|
|
47
|
+
treatUndefinedAsUnspecified: true,
|
|
48
|
+
}],
|
|
49
|
+
|
|
50
|
+
// 在捕获当前执行上下文时,应确保命名的一致性
|
|
51
|
+
// https://zh-hans.eslint.org/docs/latest/rules/consistent-this
|
|
52
|
+
"consistent-this": ["error", "that"],
|
|
53
|
+
|
|
54
|
+
// 强制所有控制语句使用一致的括号风格
|
|
55
|
+
// https://zh-hans.eslint.org/docs/latest/rules/curly
|
|
56
|
+
"curly": ["off", "multi-or-nest"],
|
|
57
|
+
|
|
58
|
+
// 要求 switch 语句中有 default 分支
|
|
59
|
+
// https://zh-hans.eslint.org/docs/latest/rules/default-case
|
|
60
|
+
"default-case": ["off", {
|
|
61
|
+
commentPattern: "^no default$",
|
|
62
|
+
}],
|
|
63
|
+
|
|
64
|
+
// 强制 switch 语句中的 default 子句放在最后
|
|
65
|
+
// https://zh-hans.eslint.org/docs/latest/rules/default-case-last
|
|
66
|
+
"default-case-last": "off",
|
|
67
|
+
|
|
68
|
+
// 尽可能的使用点符号
|
|
69
|
+
// https://zh-hans.eslint.org/docs/latest/rules/dot-notation
|
|
70
|
+
"dot-notation": ["warn", {
|
|
71
|
+
allowKeywords: true,
|
|
72
|
+
allowPattern: "",
|
|
73
|
+
}],
|
|
74
|
+
|
|
75
|
+
// 要求使用 === 和 !==
|
|
76
|
+
// https://zh-hans.eslint.org/docs/latest/rules/eqeqeq
|
|
77
|
+
"eqeqeq": ["warn", "always", { null: "ignore" }],
|
|
78
|
+
|
|
79
|
+
// 要求函数名称与分配给它们的变量或属性的名称相匹配
|
|
80
|
+
// https://zh-hans.eslint.org/docs/latest/rules/func-name-matching
|
|
81
|
+
"func-name-matching": ["off", "always", {
|
|
82
|
+
includeCommonJSModuleExports: false,
|
|
83
|
+
considerPropertyDescriptor: true,
|
|
84
|
+
}],
|
|
85
|
+
|
|
86
|
+
// 要求函数表达式要有一个函数名称
|
|
87
|
+
// https://zh-hans.eslint.org/docs/latest/rules/func-names
|
|
88
|
+
"func-names": "off",
|
|
89
|
+
|
|
90
|
+
// 强制一致使用函数声明或表达式
|
|
91
|
+
// https://zh-hans.eslint.org/docs/latest/rules/func-style
|
|
92
|
+
"func-style": ["off", "declaration"],
|
|
93
|
+
|
|
94
|
+
// 要求 for-in 循环中有一个 if 语句
|
|
95
|
+
// 在使用 for in 遍历对象时,会把从原型链继承来的属性也包括进来,这样会导致意想不到的项出现
|
|
96
|
+
// https://zh-hans.eslint.org/docs/latest/rules/guard-for-in
|
|
97
|
+
"guard-for-in": "error",
|
|
98
|
+
|
|
99
|
+
// 禁止使用指定的标识符
|
|
100
|
+
// https://zh-hans.eslint.org/docs/latest/rules/id-denylist
|
|
101
|
+
"id-denylist": "off",
|
|
102
|
+
|
|
103
|
+
// 强制变量等标识符的最小和最大长度
|
|
104
|
+
"id-length": "off",
|
|
105
|
+
|
|
106
|
+
// 要求变量等标识符定义时需要匹配指定的正则表达式
|
|
107
|
+
"id-match": "off",
|
|
108
|
+
|
|
109
|
+
// 在变量声明时是否要初始化
|
|
110
|
+
// https://zh-hans.eslint.org/docs/latest/rules/init-declarations
|
|
111
|
+
"init-declarations": ["error", "always"],
|
|
112
|
+
|
|
113
|
+
// 要求或禁止逻辑赋值运算符简写
|
|
114
|
+
"logical-assignment-operators": ["warn", "never"],
|
|
115
|
+
|
|
116
|
+
// 指定块语句的最大嵌套深度
|
|
117
|
+
"max-depth": ["error", 4],
|
|
118
|
+
|
|
119
|
+
// 每个文件强制代码的最大行数
|
|
120
|
+
// https://zh-hans.eslint.org/docs/latest/rules/max-lines
|
|
121
|
+
"max-lines": ["off", {
|
|
122
|
+
max: 300,
|
|
123
|
+
skipBlankLines: true,
|
|
124
|
+
skipComments: true,
|
|
125
|
+
}],
|
|
126
|
+
|
|
127
|
+
// 每个函数强制代码的最大行数
|
|
128
|
+
// https://zh-hans.eslint.org/docs/latest/rules/max-lines-per-function
|
|
129
|
+
"max-lines-per-function": ["off", {
|
|
130
|
+
max: 50,
|
|
131
|
+
skipBlankLines: true,
|
|
132
|
+
skipComments: true,
|
|
133
|
+
IIFEs: true,
|
|
134
|
+
}],
|
|
135
|
+
|
|
136
|
+
// 指定回调函数的最大嵌套深度
|
|
137
|
+
"max-nested-callbacks": "off",
|
|
138
|
+
|
|
139
|
+
// 强制规定了函数定义中参数的最大数量
|
|
140
|
+
// https://zh-hans.eslint.org/docs/latest/rules/max-params
|
|
141
|
+
"max-params": ["off", 3],
|
|
142
|
+
|
|
143
|
+
// 强制规定了功能块中允许的最大语句数
|
|
144
|
+
"max-statements": ["off", 10],
|
|
145
|
+
|
|
146
|
+
// 强制使用星号样式的多行注释
|
|
147
|
+
// https://zh-hans.eslint.org/docs/latest/rules/multiline-comment-style
|
|
148
|
+
"multiline-comment-style": ["off", "starred-block"],
|
|
149
|
+
|
|
150
|
+
// 禁用 alert、confirm 和 prompt
|
|
151
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-alert
|
|
152
|
+
"no-alert": "off",
|
|
153
|
+
|
|
154
|
+
// 不允许使用数组构造函数
|
|
155
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-array-constructor
|
|
156
|
+
"no-array-constructor": "error",
|
|
157
|
+
|
|
158
|
+
// 禁用按位运算符
|
|
159
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-bitwise
|
|
160
|
+
"no-bitwise": "error",
|
|
161
|
+
|
|
162
|
+
// 禁止使用 arguments.caller 或 arguments.callee
|
|
163
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-caller
|
|
164
|
+
"no-caller": "error",
|
|
165
|
+
|
|
166
|
+
// 不允许在 case 分句中进行词汇声明
|
|
167
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-case-declarations
|
|
168
|
+
"no-case-declarations": "off",
|
|
169
|
+
|
|
170
|
+
// 禁用 console
|
|
171
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-console
|
|
172
|
+
"no-console": "off",
|
|
173
|
+
|
|
174
|
+
// 禁止使用 continue 语句
|
|
175
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-continue
|
|
176
|
+
"no-continue": "off",
|
|
177
|
+
|
|
178
|
+
// 不允许对变量使用 delete 运算符
|
|
179
|
+
// delete 运算符的目的是为了从一个对象中删除一个属性。在一个变量上使用 delete 运算符可能会导致意外的行为。
|
|
180
|
+
"no-delete-var": "error",
|
|
181
|
+
|
|
182
|
+
// 禁止在正则表达式的开头显式地使用等号
|
|
183
|
+
// 正则表达式文字开头的字符 /= 可能与除法赋值运算符混淆
|
|
184
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-div-regex
|
|
185
|
+
"no-div-regex": "warn",
|
|
186
|
+
|
|
187
|
+
// 禁止 if 语句中 return 语句之后有 else 块
|
|
188
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-else-return
|
|
189
|
+
"no-else-return": "off",
|
|
190
|
+
// "no-else-return": ["error", { allowElseIf: false }],
|
|
191
|
+
|
|
192
|
+
// 禁用空块语句
|
|
193
|
+
"no-empty": ["error", { "allowEmptyCatch": true }],
|
|
194
|
+
|
|
195
|
+
// 不允许空函数
|
|
196
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-empty-function
|
|
197
|
+
"no-empty-function": ["error", {
|
|
198
|
+
allow: [
|
|
199
|
+
// "functions", // 普通函数
|
|
200
|
+
// "arrowFunctions", // 箭头函数
|
|
201
|
+
// "generatorFunctions", // 生成器函数
|
|
202
|
+
// "methods", // 类的方法和对象字面的方法缩写
|
|
203
|
+
// "generatorMethods", // 带有生成器的对象字面的类方法和方法速记
|
|
204
|
+
// "getters", // 获取器
|
|
205
|
+
// "setters", // 设置器
|
|
206
|
+
// "constructors", // 类的构造函数
|
|
207
|
+
// "asyncFunctions", // 异步函数
|
|
208
|
+
// "asyncMethods", // 异步类方法和对象字面的方法缩写
|
|
209
|
+
],
|
|
210
|
+
}],
|
|
211
|
+
|
|
212
|
+
// 禁止空静态块
|
|
213
|
+
"no-empty-static-block": "error",
|
|
214
|
+
|
|
215
|
+
// 在没有类型检查运算符(== 或 !=)的情况下与 null 比较,可能会产生意想不到的结果,因为在与 null 和 undefined 的值比较时,比较结果将为真
|
|
216
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-eq-null
|
|
217
|
+
"no-eq-null": "error",
|
|
218
|
+
|
|
219
|
+
// 禁止使用 eval()
|
|
220
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-eval
|
|
221
|
+
"no-eval": "error",
|
|
222
|
+
|
|
223
|
+
// 不允许扩展原生类型
|
|
224
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-extend-native
|
|
225
|
+
"no-extend-native": "error",
|
|
226
|
+
|
|
227
|
+
// 禁止不必要的函数绑定 .bind()
|
|
228
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-extra-bind
|
|
229
|
+
"no-extra-bind": "warn",
|
|
230
|
+
|
|
231
|
+
// 禁止不必要的布尔转换
|
|
232
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-extra-boolean-cast
|
|
233
|
+
"no-extra-boolean-cast": "warn",
|
|
234
|
+
|
|
235
|
+
// 禁止不必要的标签
|
|
236
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-extra-label
|
|
237
|
+
"no-extra-label": "warn",
|
|
238
|
+
|
|
239
|
+
// 禁止不必要的分号
|
|
240
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-extra-semi
|
|
241
|
+
"no-extra-semi": "warn",
|
|
242
|
+
|
|
243
|
+
// 禁止数字字面量中使用前导和末尾小数点
|
|
244
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-floating-decimal
|
|
245
|
+
"no-floating-decimal": "warn",
|
|
246
|
+
|
|
247
|
+
// 禁止对原生对象或只读全局变量进行重新赋值
|
|
248
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-global-assign
|
|
249
|
+
"no-global-assign": ["error", { exceptions: [] }],
|
|
250
|
+
|
|
251
|
+
// 禁止对变量使用隐式类型转换
|
|
252
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-implicit-coercion
|
|
253
|
+
"no-implicit-coercion": ["off", {
|
|
254
|
+
boolean: false,
|
|
255
|
+
number: true,
|
|
256
|
+
string: true,
|
|
257
|
+
allow: [],
|
|
258
|
+
}],
|
|
259
|
+
|
|
260
|
+
// 禁止在全局作用域中使用 var 或命名函数
|
|
261
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-implicit-globals
|
|
262
|
+
"no-implicit-globals": "off",
|
|
263
|
+
|
|
264
|
+
// 禁止使用 eval() 等方法
|
|
265
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-implied-eval
|
|
266
|
+
"no-implied-eval": "error",
|
|
267
|
+
|
|
268
|
+
// 禁止与代码在同一行的注释
|
|
269
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-inline-comments
|
|
270
|
+
"no-inline-comments": "off",
|
|
271
|
+
|
|
272
|
+
// 禁止在全局作用域中使用 this
|
|
273
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-invalid-this
|
|
274
|
+
"no-invalid-this": "error",
|
|
275
|
+
|
|
276
|
+
// 不允许标签与变量名称相同
|
|
277
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-label-var
|
|
278
|
+
"no-label-var": "error",
|
|
279
|
+
|
|
280
|
+
// 不允许带标签的语句
|
|
281
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-labels
|
|
282
|
+
"no-labels": ["error", {
|
|
283
|
+
allowLoop: false,
|
|
284
|
+
allowSwitch: false,
|
|
285
|
+
}],
|
|
286
|
+
|
|
287
|
+
// 不允许不必要的嵌套块
|
|
288
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-lone-blocks
|
|
289
|
+
"no-lone-blocks": "error",
|
|
290
|
+
|
|
291
|
+
// 禁止 if 作为唯一的语句出现在 else 语句中
|
|
292
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-lonely-if
|
|
293
|
+
"no-lonely-if": "off",
|
|
294
|
+
// "no-lonely-if": "warn",
|
|
295
|
+
|
|
296
|
+
// 不允许在循环语句中包含不安全引用的函数声明
|
|
297
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-loop-func
|
|
298
|
+
"no-loop-func": "error",
|
|
299
|
+
|
|
300
|
+
// 禁止使用“魔数”
|
|
301
|
+
// “魔数“是在代码中多次出现的数字,没有明确的含义,它们最好被命名的常量所取代
|
|
302
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-magic-numbers
|
|
303
|
+
"no-magic-numbers": ["off", {
|
|
304
|
+
ignore: [],
|
|
305
|
+
ignoreArrayIndexes: true,
|
|
306
|
+
enforceConst: true,
|
|
307
|
+
detectObjects: false,
|
|
308
|
+
}],
|
|
309
|
+
|
|
310
|
+
// 禁止混合使用不同的操作符
|
|
311
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-mixed-operators
|
|
312
|
+
"no-mixed-operators": ["off", {
|
|
313
|
+
groups: [
|
|
314
|
+
["+", "-", "*", "/", "%", "**"],
|
|
315
|
+
["&", "|", "^", "~", "<<", ">>", ">>>"],
|
|
316
|
+
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
|
|
317
|
+
["&&", "||"],
|
|
318
|
+
["in", "instanceof"],
|
|
319
|
+
],
|
|
320
|
+
allowSamePrecedence: true,
|
|
321
|
+
}],
|
|
322
|
+
|
|
323
|
+
// 禁止连续赋值
|
|
324
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-multi-assign
|
|
325
|
+
"no-multi-assign": ["error", {
|
|
326
|
+
ignoreNonDeclaration: false,
|
|
327
|
+
}],
|
|
328
|
+
|
|
329
|
+
// 禁止使用多行字符串
|
|
330
|
+
// 在 JavaScript 中,可以通过在换行前使用斜线来创建多行字符串
|
|
331
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-multi-str
|
|
332
|
+
"no-multi-str": "error",
|
|
333
|
+
|
|
334
|
+
// if 语句和三元表达式中不允许使用否定条件
|
|
335
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-negated-condition
|
|
336
|
+
"no-negated-condition": "off",
|
|
337
|
+
|
|
338
|
+
// 禁用嵌套的三元表达式
|
|
339
|
+
"no-nested-ternary": "off",
|
|
340
|
+
|
|
341
|
+
// 禁止使用 new 以避免产生副作用
|
|
342
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-new
|
|
343
|
+
"no-new": "off",
|
|
344
|
+
|
|
345
|
+
// 不允许使用 new Function() 来创建函数
|
|
346
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-new-func
|
|
347
|
+
"no-new-func": "error",
|
|
348
|
+
|
|
349
|
+
// 不允许使用 new Object() 来创建对象
|
|
350
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-new-object
|
|
351
|
+
"no-new-object": "error",
|
|
352
|
+
|
|
353
|
+
// 禁止使用 new String()、new Number() 或 new Boolean() 来创建字符串、数字或布尔值
|
|
354
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-new-wrappers
|
|
355
|
+
"no-new-wrappers": "error",
|
|
356
|
+
|
|
357
|
+
// 禁止在字符串字面量中使用八进制转义序列(\8、\9)
|
|
358
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-nonoctal-decimal-escape
|
|
359
|
+
"no-nonoctal-decimal-escape": "error",
|
|
360
|
+
|
|
361
|
+
// 不允许八进制字头(0 开头的数字)
|
|
362
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-octal
|
|
363
|
+
"no-octal": "error",
|
|
364
|
+
|
|
365
|
+
// 从 ECMAScript 5 规范开始,字符串中的八进制转义序列已被废弃,不应使用。应该使用 Unicode 转义序列。
|
|
366
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-octal-escape
|
|
367
|
+
"no-octal-escape": "error",
|
|
368
|
+
|
|
369
|
+
// 禁止对函数参数再赋值
|
|
370
|
+
// rule: https://zh-hans.eslint.org/docs/latest/rules/no-param-reassign.html
|
|
371
|
+
"no-param-reassign": "off",
|
|
372
|
+
// "no-param-reassign": ["error", {
|
|
373
|
+
// props: true,
|
|
374
|
+
// ignorePropertyModificationsFor: [
|
|
375
|
+
// "acc", // for reduce accumulators
|
|
376
|
+
// "accumulator", // for reduce accumulators
|
|
377
|
+
// "e", // for e.returnvalue
|
|
378
|
+
// "ctx", // for Koa routing
|
|
379
|
+
// "context", // for Koa routing
|
|
380
|
+
// "req", // for Express requests
|
|
381
|
+
// "request", // for Express requests
|
|
382
|
+
// "res", // for Express responses
|
|
383
|
+
// "response", // for Express responses
|
|
384
|
+
// "$scope", // for Angular 1 scopes
|
|
385
|
+
// "staticContext", // for ReactRouter context
|
|
386
|
+
// ],
|
|
387
|
+
// }],
|
|
388
|
+
|
|
389
|
+
// 禁用一元操作符 ++ 和 --
|
|
390
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-plusplus
|
|
391
|
+
"no-plusplus": "off",
|
|
392
|
+
|
|
393
|
+
// 禁止使用 __proto__ 属性
|
|
394
|
+
// __proto__ 属性在 ECMAScript 3.1 中已经被废弃,不应该在代码中使用。使用 Object.getPrototypeOf 和 Object.setPrototypeOf 代替。
|
|
395
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-proto
|
|
396
|
+
"no-proto": "error",
|
|
397
|
+
|
|
398
|
+
// 禁止重复声明变量
|
|
399
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-redeclare
|
|
400
|
+
"no-redeclare": ["error", {
|
|
401
|
+
builtinGlobals: true,
|
|
402
|
+
}],
|
|
403
|
+
|
|
404
|
+
// 禁止正则表达式中出现多个空格
|
|
405
|
+
"no-regex-spaces": "warn",
|
|
406
|
+
|
|
407
|
+
// 禁用特定的全局变量
|
|
408
|
+
"no-restricted-globals": "off",
|
|
409
|
+
// "no-restricted-globals": [
|
|
410
|
+
// "error",
|
|
411
|
+
// {
|
|
412
|
+
// name: "isFinite",
|
|
413
|
+
// message: "Use Number.isFinite instead https://github.com/airbnb/javascript#standard-library--isfinite",
|
|
414
|
+
// },
|
|
415
|
+
// {
|
|
416
|
+
// name: "isNaN",
|
|
417
|
+
// message: "Use Number.isNaN instead https://github.com/airbnb/javascript#standard-library--isnan",
|
|
418
|
+
// },
|
|
419
|
+
// ].concat(confusingBrowserGlobals),
|
|
420
|
+
|
|
421
|
+
// 禁止使用特定对象的特定属性
|
|
422
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-restricted-properties
|
|
423
|
+
"no-restricted-properties": [
|
|
424
|
+
"error",
|
|
425
|
+
{
|
|
426
|
+
object: "arguments",
|
|
427
|
+
property: "callee",
|
|
428
|
+
message: "arguments.callee is deprecated",
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
object: "global",
|
|
432
|
+
property: "isFinite",
|
|
433
|
+
message: "Please use Number.isFinite instead",
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
object: "self",
|
|
437
|
+
property: "isFinite",
|
|
438
|
+
message: "Please use Number.isFinite instead",
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
object: "window",
|
|
442
|
+
property: "isFinite",
|
|
443
|
+
message: "Please use Number.isFinite instead",
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
object: "global",
|
|
447
|
+
property: "isNaN",
|
|
448
|
+
message: "Please use Number.isNaN instead",
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
object: "self",
|
|
452
|
+
property: "isNaN",
|
|
453
|
+
message: "Please use Number.isNaN instead",
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
object: "window",
|
|
457
|
+
property: "isNaN",
|
|
458
|
+
message: "Please use Number.isNaN instead",
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
property: "__defineGetter__",
|
|
462
|
+
message: "Please use Object.defineProperty instead.",
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
property: "__defineSetter__",
|
|
466
|
+
message: "Please use Object.defineProperty instead.",
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
object: "Math",
|
|
470
|
+
property: "pow",
|
|
471
|
+
message: "Use the exponentiation operator (**) instead.",
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
|
|
475
|
+
// 禁用特定的语法
|
|
476
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-restricted-syntax
|
|
477
|
+
"no-restricted-syntax": [
|
|
478
|
+
"off",
|
|
479
|
+
{
|
|
480
|
+
selector: "ForInStatement",
|
|
481
|
+
message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
selector: "ForOfStatement",
|
|
485
|
+
message: "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.",
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
selector: "LabeledStatement",
|
|
489
|
+
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
selector: "WithStatement",
|
|
493
|
+
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
|
|
497
|
+
// 禁止在 return 语句中使用赋值语句
|
|
498
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-return-assign
|
|
499
|
+
"no-return-assign": ["error", "always"],
|
|
500
|
+
|
|
501
|
+
// 禁止使用 `javascript:` urls.
|
|
502
|
+
// 比如:location.href = "javascript:void(0)";
|
|
503
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-script-url
|
|
504
|
+
"no-script-url": "error",
|
|
505
|
+
|
|
506
|
+
// 禁止使用逗号运算符
|
|
507
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-sequences
|
|
508
|
+
"no-sequences": "error",
|
|
509
|
+
|
|
510
|
+
// 禁止变量声明掩盖在外部作用域中声明的变量
|
|
511
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-shadow
|
|
512
|
+
"no-shadow": ["error", {
|
|
513
|
+
builtinGlobals: true,
|
|
514
|
+
hoist: "all",
|
|
515
|
+
allow: ["name"],
|
|
516
|
+
ignoreOnInitialization: true,
|
|
517
|
+
}],
|
|
518
|
+
|
|
519
|
+
// disallow shadowing of names such as arguments
|
|
520
|
+
"no-shadow-restricted-names": "error",
|
|
521
|
+
|
|
522
|
+
// 禁止使用三元运算符
|
|
523
|
+
"no-ternary": "off",
|
|
524
|
+
|
|
525
|
+
// restrict what can be thrown as an exception
|
|
526
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-throw-literal
|
|
527
|
+
"no-throw-literal": "error",
|
|
528
|
+
|
|
529
|
+
// 禁止将 undefined 赋值给变量
|
|
530
|
+
"no-undef-init": "error",
|
|
531
|
+
|
|
532
|
+
// 禁止使用 undefined
|
|
533
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-undefined
|
|
534
|
+
"no-undefined": "error",
|
|
535
|
+
|
|
536
|
+
// 禁止标识符中有悬空下划线
|
|
537
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-underscore-dangle
|
|
538
|
+
"no-underscore-dangle": "off",
|
|
539
|
+
// "no-underscore-dangle": ["error", {
|
|
540
|
+
// allow: [],
|
|
541
|
+
// allowAfterThis: false,
|
|
542
|
+
// allowAfterSuper: false,
|
|
543
|
+
// enforceInMethodNames: true,
|
|
544
|
+
// }],
|
|
545
|
+
|
|
546
|
+
// 禁止使用不必要的三元运算符
|
|
547
|
+
// 比如:`a || b` 代替 `a ? a : b`
|
|
548
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unneeded-ternary
|
|
549
|
+
"no-unneeded-ternary": ["warn", {
|
|
550
|
+
defaultAssignment: false,
|
|
551
|
+
}],
|
|
552
|
+
|
|
553
|
+
// 禁止未使用过的表达式
|
|
554
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unused-expressions
|
|
555
|
+
"no-unused-expressions": ["error", {
|
|
556
|
+
allowShortCircuit: true,
|
|
557
|
+
allowTernary: true,
|
|
558
|
+
allowTaggedTemplates: false,
|
|
559
|
+
enforceForJSX: true,
|
|
560
|
+
// ignoreDirectives: true,
|
|
561
|
+
}],
|
|
562
|
+
|
|
563
|
+
// 禁止未使用的标签
|
|
564
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-unused-labels
|
|
565
|
+
"no-unused-labels": "warn",
|
|
566
|
+
|
|
567
|
+
// 禁止不必要的 .call() .apply()
|
|
568
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-call
|
|
569
|
+
"no-useless-call": "off",
|
|
570
|
+
|
|
571
|
+
// 禁止不必要的 catch 子句
|
|
572
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-catch
|
|
573
|
+
"no-useless-catch": "error",
|
|
574
|
+
|
|
575
|
+
// 禁止不必要的文字或模板文字串联
|
|
576
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-concat
|
|
577
|
+
"no-useless-concat": "error",
|
|
578
|
+
|
|
579
|
+
// 禁止不必要的转义字符
|
|
580
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-escape
|
|
581
|
+
"no-useless-escape": "error",
|
|
582
|
+
|
|
583
|
+
// 禁止冗余的 return 语句
|
|
584
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-useless-return
|
|
585
|
+
"no-useless-return": "warn",
|
|
586
|
+
|
|
587
|
+
// 禁止使用 void 运算符
|
|
588
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-void
|
|
589
|
+
"no-void": "error",
|
|
590
|
+
|
|
591
|
+
// disallow usage of configurable warning terms in comments: e.g. todo
|
|
592
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-warning-comments
|
|
593
|
+
"no-warning-comments": ["off", {
|
|
594
|
+
terms: ["todo", "fixme", "xxx"],
|
|
595
|
+
location: "start",
|
|
596
|
+
}],
|
|
597
|
+
|
|
598
|
+
// 禁止使用 with 语句
|
|
599
|
+
// https://zh-hans.eslint.org/docs/latest/rules/no-with
|
|
600
|
+
"no-with": "error",
|
|
601
|
+
|
|
602
|
+
// 强制函数中的变量要么一起声明要么分开声明
|
|
603
|
+
// https://zh-hans.eslint.org/docs/latest/rules/one-var
|
|
604
|
+
"one-var": "off",
|
|
605
|
+
|
|
606
|
+
// 要求或禁止在变量声明周围换行
|
|
607
|
+
// https://zh-hans.eslint.org/docs/latest/rules/one-var-declaration-per-line
|
|
608
|
+
"one-var-declaration-per-line": "off",
|
|
609
|
+
|
|
610
|
+
// 尽可能要求或允许使用赋值运算符简写
|
|
611
|
+
// https://zh-hans.eslint.org/docs/latest/rules/operator-assignment
|
|
612
|
+
"operator-assignment": ["warn", "always"],
|
|
613
|
+
|
|
614
|
+
// 不允许使用 RegExp 构造函数,转而使用常规表达式字面量
|
|
615
|
+
// https://zh-hans.eslint.org/docs/latest/rules/prefer-regex-literals
|
|
616
|
+
"prefer-regex-literals": ["error", {
|
|
617
|
+
disallowRedundantWrapping: true,
|
|
618
|
+
}],
|
|
619
|
+
|
|
620
|
+
// 要求对象字面量属性名称用引号括起来
|
|
621
|
+
// https://zh-hans.eslint.org/docs/latest/rules/quote-props.html
|
|
622
|
+
"quote-props": ["warn", "consistent"],
|
|
623
|
+
|
|
624
|
+
// 当使用 parseInt() 函数时,要求必须有基数
|
|
625
|
+
// https://zh-hans.eslint.org/docs/latest/rules/radix
|
|
626
|
+
"radix": ["error", "as-needed"],
|
|
627
|
+
|
|
628
|
+
// 要求对象键名进行排序
|
|
629
|
+
"sort-keys": ["off", "asc", {
|
|
630
|
+
caseSensitive: false,
|
|
631
|
+
natural: true,
|
|
632
|
+
}],
|
|
633
|
+
|
|
634
|
+
// 要求对同一声明块中的变量进行排序
|
|
635
|
+
"sort-vars": "off",
|
|
636
|
+
|
|
637
|
+
// 要求或禁止在注释前有空白 (space 或 tab)
|
|
638
|
+
// https://zh-hans.eslint.org/docs/latest/rules/spaced-comment
|
|
639
|
+
"spaced-comment": ["warn", "always", {
|
|
640
|
+
line: {
|
|
641
|
+
exceptions: ["-", "+"],
|
|
642
|
+
markers: ["=", "!", "/"], // space here to support sprockets directives, slash for TS /// comments
|
|
643
|
+
},
|
|
644
|
+
block: {
|
|
645
|
+
exceptions: ["-", "+"],
|
|
646
|
+
markers: ["=", "!", ":", "::"], // space here to support sprockets directives and flow comment types
|
|
647
|
+
balanced: true,
|
|
648
|
+
},
|
|
649
|
+
}],
|
|
650
|
+
|
|
651
|
+
// 要求或禁止严格模式指令("use strict";)
|
|
652
|
+
"strict": ["off", "never"],
|
|
653
|
+
|
|
654
|
+
// 要求在包裹作用域的最上方使用 var 定义变量
|
|
655
|
+
// https://zh-hans.eslint.org/docs/latest/rules/vars-on-top
|
|
656
|
+
"vars-on-top": "off",
|
|
657
|
+
|
|
658
|
+
// 要求或禁止 “Yoda” 条件
|
|
659
|
+
// 尤达条件之所以被命名为尤达,是因为条件的字面量值在前,而变量在后
|
|
660
|
+
// https://zh-hans.eslint.org/docs/latest/rules/yoda
|
|
661
|
+
"yoda": ["off", "never", {
|
|
662
|
+
exceptRange: true,
|
|
663
|
+
}],
|
|
664
|
+
|
|
665
|
+
},
|
|
666
|
+
};
|