@houheaven/eslint-config-helper 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/eslint/eslint-fix.js +29 -0
- package/eslint/file-bof-eof.js +22 -0
- package/eslint/index.js +18 -0
- package/eslint/legacy.js +34 -0
- package/eslint/prettier.js +414 -0
- package/eslint/rules/best-practices.js +422 -0
- package/eslint/rules/es6.js +197 -0
- package/eslint/rules/imports.js +279 -0
- package/eslint/rules/node.js +48 -0
- package/eslint/rules/possible-errors.js +185 -0
- package/eslint/rules/strict-mode.js +12 -0
- package/eslint/rules/stylistic-issues.js +573 -0
- package/eslint/rules/variables.js +71 -0
- package/eslint/rules/vue.js +23 -0
- package/package.json +28 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// Best Practices
|
|
4
|
+
// 这些规则是关于最佳实践的,帮助你避免一些问题
|
|
5
|
+
// ==========================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
rules: {
|
|
9
|
+
// enforces getter/setter pairs in objects
|
|
10
|
+
// https://eslint.org/docs/rules/accessor-pairs
|
|
11
|
+
"accessor-pairs": "off",
|
|
12
|
+
|
|
13
|
+
// enforces return statements in callbacks of array's methods
|
|
14
|
+
// https://eslint.org/docs/rules/array-callback-return
|
|
15
|
+
"array-callback-return": ["error", { allowImplicit: true }],
|
|
16
|
+
|
|
17
|
+
// treat var statements as if they were block scoped
|
|
18
|
+
// https://eslint.org/docs/rules/block-scoped-var
|
|
19
|
+
"block-scoped-var": "error",
|
|
20
|
+
|
|
21
|
+
// specify the maximum cyclomatic complexity allowed in a program
|
|
22
|
+
// https://eslint.org/docs/rules/complexity
|
|
23
|
+
"complexity": ["off", 20],
|
|
24
|
+
|
|
25
|
+
// enforce that class methods use "this"
|
|
26
|
+
// https://eslint.org/docs/rules/class-methods-use-this
|
|
27
|
+
"class-methods-use-this": ["error", {
|
|
28
|
+
exceptMethods: [],
|
|
29
|
+
}],
|
|
30
|
+
|
|
31
|
+
// require return statements to either always or never specify values
|
|
32
|
+
// https://eslint.org/docs/rules/consistent-return
|
|
33
|
+
"consistent-return": "error",
|
|
34
|
+
|
|
35
|
+
// 强制所有控制语句使用一致的括号风格
|
|
36
|
+
// https://eslint.org/docs/rules/curly
|
|
37
|
+
"curly": "off",
|
|
38
|
+
|
|
39
|
+
// 要求 switch 语句中有 default 分支
|
|
40
|
+
// https://eslint.org/docs/rules/default-case
|
|
41
|
+
"default-case": "off",
|
|
42
|
+
// 'default-case': ['error', { commentPattern: '^no default$' }],
|
|
43
|
+
|
|
44
|
+
// Enforce default clauses in switch statements to be last
|
|
45
|
+
// https://eslint.org/docs/rules/default-case-last
|
|
46
|
+
"default-case-last": "error",
|
|
47
|
+
|
|
48
|
+
// https://eslint.org/docs/rules/default-param-last
|
|
49
|
+
"default-param-last": "error",
|
|
50
|
+
|
|
51
|
+
// encourages use of dot notation whenever possible
|
|
52
|
+
// https://eslint.org/docs/rules/dot-notation
|
|
53
|
+
"dot-notation": ["error", { allowKeywords: true }],
|
|
54
|
+
|
|
55
|
+
// 强制在点号之前和之后一致的换行
|
|
56
|
+
// https://eslint.org/docs/rules/dot-location
|
|
57
|
+
"dot-location": ["warn", "property"],
|
|
58
|
+
|
|
59
|
+
// require the use of === and !==
|
|
60
|
+
// https://eslint.org/docs/rules/eqeqeq
|
|
61
|
+
"eqeqeq": ["error", "always", { null: "ignore" }],
|
|
62
|
+
|
|
63
|
+
// Require grouped accessor pairs in object literals and classes
|
|
64
|
+
// https://eslint.org/docs/rules/grouped-accessor-pairs
|
|
65
|
+
"grouped-accessor-pairs": "error",
|
|
66
|
+
|
|
67
|
+
// 要求 for-in 循环中有一个 if 语句(在使用 for in 遍历对象时,会把从原型链继承来的属性也包括进来。这样会导致意想不到的项出现。)
|
|
68
|
+
// https://eslint.org/docs/rules/guard-for-in
|
|
69
|
+
"guard-for-in": "off",
|
|
70
|
+
// 'guard-for-in': 'error',
|
|
71
|
+
|
|
72
|
+
// enforce a maximum number of classes per file
|
|
73
|
+
// https://eslint.org/docs/rules/max-classes-per-file
|
|
74
|
+
"max-classes-per-file": ["error", 1],
|
|
75
|
+
|
|
76
|
+
// 禁用 alert、confirm 和 prompt
|
|
77
|
+
// https://eslint.org/docs/rules/no-alert
|
|
78
|
+
"no-alert": "off",
|
|
79
|
+
// 'no-alert': 'warn',
|
|
80
|
+
|
|
81
|
+
// disallow use of arguments.caller or arguments.callee
|
|
82
|
+
// https://eslint.org/docs/rules/no-caller
|
|
83
|
+
"no-caller": "error",
|
|
84
|
+
|
|
85
|
+
// 不允许在 case 子句中使用词法声明
|
|
86
|
+
// https://eslint.org/docs/rules/no-case-declarations
|
|
87
|
+
"no-case-declarations": "off",
|
|
88
|
+
// 'no-case-declarations': 'error',
|
|
89
|
+
|
|
90
|
+
// Disallow returning value in constructor
|
|
91
|
+
// https://eslint.org/docs/rules/no-constructor-return
|
|
92
|
+
"no-constructor-return": "error",
|
|
93
|
+
|
|
94
|
+
// disallow division operators explicitly at beginning of regular expression
|
|
95
|
+
// https://eslint.org/docs/rules/no-div-regex
|
|
96
|
+
"no-div-regex": "off",
|
|
97
|
+
|
|
98
|
+
// 禁止 if 语句中 return 语句之后有 else 块
|
|
99
|
+
// https://eslint.org/docs/rules/no-else-return
|
|
100
|
+
"no-else-return": "off",
|
|
101
|
+
// 'no-else-return': ['error', { allowElseIf: false }],
|
|
102
|
+
|
|
103
|
+
// disallow empty functions, except for standalone funcs/arrows
|
|
104
|
+
// https://eslint.org/docs/rules/no-empty-function
|
|
105
|
+
"no-empty-function": ["error", {
|
|
106
|
+
allow: [
|
|
107
|
+
"arrowFunctions",
|
|
108
|
+
"functions",
|
|
109
|
+
"methods"
|
|
110
|
+
],
|
|
111
|
+
}],
|
|
112
|
+
|
|
113
|
+
// disallow empty destructuring patterns
|
|
114
|
+
// https://eslint.org/docs/rules/no-empty-pattern
|
|
115
|
+
"no-empty-pattern": "error",
|
|
116
|
+
|
|
117
|
+
// disallow comparisons to null without a type-checking operator
|
|
118
|
+
// https://eslint.org/docs/rules/no-eq-null
|
|
119
|
+
"no-eq-null": "off",
|
|
120
|
+
|
|
121
|
+
// disallow use of eval()
|
|
122
|
+
// https://eslint.org/docs/rules/no-eval
|
|
123
|
+
"no-eval": "error",
|
|
124
|
+
|
|
125
|
+
// disallow adding to native types
|
|
126
|
+
// https://eslint.org/docs/rules/no-extend-native
|
|
127
|
+
"no-extend-native": "error",
|
|
128
|
+
|
|
129
|
+
// disallow unnecessary function binding
|
|
130
|
+
// https://eslint.org/docs/rules/no-extra-bind
|
|
131
|
+
"no-extra-bind": "error",
|
|
132
|
+
|
|
133
|
+
// disallow Unnecessary Labels
|
|
134
|
+
// https://eslint.org/docs/rules/no-extra-label
|
|
135
|
+
"no-extra-label": "error",
|
|
136
|
+
|
|
137
|
+
// disallow fallthrough of case statements
|
|
138
|
+
// https://eslint.org/docs/rules/no-fallthrough
|
|
139
|
+
"no-fallthrough": "error",
|
|
140
|
+
|
|
141
|
+
// 禁止数字字面量中使用前导和末尾小数点
|
|
142
|
+
// https://eslint.org/docs/rules/no-floating-decimal
|
|
143
|
+
"no-floating-decimal": "error",
|
|
144
|
+
|
|
145
|
+
// disallow reassignments of native objects or read-only globals
|
|
146
|
+
// https://eslint.org/docs/rules/no-global-assign
|
|
147
|
+
"no-global-assign": ["error", { exceptions: []}],
|
|
148
|
+
|
|
149
|
+
// deprecated in favor of no-global-assign
|
|
150
|
+
// https://eslint.org/docs/rules/no-native-reassign
|
|
151
|
+
"no-native-reassign": "off",
|
|
152
|
+
|
|
153
|
+
// disallow implicit type conversions
|
|
154
|
+
// https://eslint.org/docs/rules/no-implicit-coercion
|
|
155
|
+
"no-implicit-coercion": ["off", {
|
|
156
|
+
boolean: false,
|
|
157
|
+
number: true,
|
|
158
|
+
string: true,
|
|
159
|
+
allow: [],
|
|
160
|
+
}],
|
|
161
|
+
|
|
162
|
+
// disallow var and named functions in global scope
|
|
163
|
+
// https://eslint.org/docs/rules/no-implicit-globals
|
|
164
|
+
"no-implicit-globals": "off",
|
|
165
|
+
|
|
166
|
+
// disallow use of eval()-like methods
|
|
167
|
+
// https://eslint.org/docs/rules/no-implied-eval
|
|
168
|
+
"no-implied-eval": "error",
|
|
169
|
+
|
|
170
|
+
// disallow this keywords outside of classes or class-like objects
|
|
171
|
+
// https://eslint.org/docs/rules/no-invalid-this
|
|
172
|
+
"no-invalid-this": "off",
|
|
173
|
+
|
|
174
|
+
// disallow usage of __iterator__ property
|
|
175
|
+
// https://eslint.org/docs/rules/no-iterator
|
|
176
|
+
"no-iterator": "error",
|
|
177
|
+
|
|
178
|
+
// disallow use of labels for anything other than loops and switches
|
|
179
|
+
// https://eslint.org/docs/rules/no-labels
|
|
180
|
+
"no-labels": ["error", { allowLoop: false, allowSwitch: false }],
|
|
181
|
+
|
|
182
|
+
// disallow unnecessary nested blocks
|
|
183
|
+
// https://eslint.org/docs/rules/no-lone-blocks
|
|
184
|
+
"no-lone-blocks": "error",
|
|
185
|
+
|
|
186
|
+
// disallow creation of functions within loops
|
|
187
|
+
// https://eslint.org/docs/rules/no-loop-func
|
|
188
|
+
"no-loop-func": "error",
|
|
189
|
+
|
|
190
|
+
// disallow magic numbers
|
|
191
|
+
// https://eslint.org/docs/rules/no-magic-numbers
|
|
192
|
+
"no-magic-numbers": ["off", {
|
|
193
|
+
ignore: [],
|
|
194
|
+
ignoreArrayIndexes: true,
|
|
195
|
+
enforceConst: true,
|
|
196
|
+
detectObjects: false,
|
|
197
|
+
}],
|
|
198
|
+
|
|
199
|
+
// 禁止使用多个空格
|
|
200
|
+
// https://eslint.org/docs/rules/no-multi-spaces
|
|
201
|
+
"no-multi-spaces": ["warn", { "ignoreEOLComments": true }],
|
|
202
|
+
|
|
203
|
+
// disallow use of multiline strings
|
|
204
|
+
// https://eslint.org/docs/rules/no-multi-str
|
|
205
|
+
"no-multi-str": "error",
|
|
206
|
+
|
|
207
|
+
// 禁止使用 new 以避免产生副作用
|
|
208
|
+
// https://eslint.org/docs/rules/no-new
|
|
209
|
+
"no-new": "off",
|
|
210
|
+
// 'no-new': 'error',
|
|
211
|
+
|
|
212
|
+
// disallow use of new operator for Function object
|
|
213
|
+
// https://eslint.org/docs/rules/no-new-func
|
|
214
|
+
"no-new-func": "error",
|
|
215
|
+
|
|
216
|
+
// disallows creating new instances of String, Number, and Boolean
|
|
217
|
+
// https://eslint.org/docs/rules/no-new-wrappers
|
|
218
|
+
"no-new-wrappers": "error",
|
|
219
|
+
|
|
220
|
+
// Disallow \8 and \9 escape sequences in string literals
|
|
221
|
+
// https://eslint.org/docs/rules/no-nonoctal-decimal-escape
|
|
222
|
+
"no-nonoctal-decimal-escape": "error",
|
|
223
|
+
|
|
224
|
+
// disallow use of (old style) octal literals
|
|
225
|
+
// https://eslint.org/docs/rules/no-octal
|
|
226
|
+
"no-octal": "error",
|
|
227
|
+
|
|
228
|
+
// disallow use of octal escape sequences in string literals, such as
|
|
229
|
+
// var foo = 'Copyright \251';
|
|
230
|
+
// https://eslint.org/docs/rules/no-octal-escape
|
|
231
|
+
"no-octal-escape": "error",
|
|
232
|
+
|
|
233
|
+
// 禁止对函数参数再赋值
|
|
234
|
+
// rule: https://eslint.org/docs/rules/no-param-reassign.html
|
|
235
|
+
"no-param-reassign": "off",
|
|
236
|
+
// 'no-param-reassign': ['error', {
|
|
237
|
+
// props: true,
|
|
238
|
+
// ignorePropertyModificationsFor: [
|
|
239
|
+
// 'acc', // for reduce accumulators
|
|
240
|
+
// 'accumulator', // for reduce accumulators
|
|
241
|
+
// 'e', // for e.returnvalue
|
|
242
|
+
// 'ctx', // for Koa routing
|
|
243
|
+
// 'context', // for Koa routing
|
|
244
|
+
// 'req', // for Express requests
|
|
245
|
+
// 'request', // for Express requests
|
|
246
|
+
// 'res', // for Express responses
|
|
247
|
+
// 'response', // for Express responses
|
|
248
|
+
// '$scope', // for Angular 1 scopes
|
|
249
|
+
// 'staticContext', // for ReactRouter context
|
|
250
|
+
// ]
|
|
251
|
+
// }],
|
|
252
|
+
|
|
253
|
+
// disallow usage of __proto__ property
|
|
254
|
+
// https://eslint.org/docs/rules/no-proto
|
|
255
|
+
"no-proto": "error",
|
|
256
|
+
|
|
257
|
+
// disallow declaring the same variable more than once
|
|
258
|
+
// https://eslint.org/docs/rules/no-redeclare
|
|
259
|
+
"no-redeclare": "error",
|
|
260
|
+
|
|
261
|
+
// disallow certain object properties
|
|
262
|
+
// https://eslint.org/docs/rules/no-restricted-properties
|
|
263
|
+
"no-restricted-properties": ["error", {
|
|
264
|
+
object: "arguments",
|
|
265
|
+
property: "callee",
|
|
266
|
+
message: "arguments.callee is deprecated",
|
|
267
|
+
}, {
|
|
268
|
+
object: "global",
|
|
269
|
+
property: "isFinite",
|
|
270
|
+
message: "Please use Number.isFinite instead",
|
|
271
|
+
}, {
|
|
272
|
+
object: "self",
|
|
273
|
+
property: "isFinite",
|
|
274
|
+
message: "Please use Number.isFinite instead",
|
|
275
|
+
}, {
|
|
276
|
+
object: "window",
|
|
277
|
+
property: "isFinite",
|
|
278
|
+
message: "Please use Number.isFinite instead",
|
|
279
|
+
}, {
|
|
280
|
+
object: "global",
|
|
281
|
+
property: "isNaN",
|
|
282
|
+
message: "Please use Number.isNaN instead",
|
|
283
|
+
}, {
|
|
284
|
+
object: "self",
|
|
285
|
+
property: "isNaN",
|
|
286
|
+
message: "Please use Number.isNaN instead",
|
|
287
|
+
}, {
|
|
288
|
+
object: "window",
|
|
289
|
+
property: "isNaN",
|
|
290
|
+
message: "Please use Number.isNaN instead",
|
|
291
|
+
}, {
|
|
292
|
+
property: "__defineGetter__",
|
|
293
|
+
message: "Please use Object.defineProperty instead.",
|
|
294
|
+
}, {
|
|
295
|
+
property: "__defineSetter__",
|
|
296
|
+
message: "Please use Object.defineProperty instead.",
|
|
297
|
+
}, {
|
|
298
|
+
object: "Math",
|
|
299
|
+
property: "pow",
|
|
300
|
+
message: "Use the exponentiation operator (**) instead.",
|
|
301
|
+
}],
|
|
302
|
+
|
|
303
|
+
// 禁止在 return 语句中使用赋值语句
|
|
304
|
+
// https://eslint.org/docs/rules/no-return-assign
|
|
305
|
+
"no-return-assign": "off",
|
|
306
|
+
// 'no-return-assign': ['error', 'always'],
|
|
307
|
+
|
|
308
|
+
// disallow redundant `return await`
|
|
309
|
+
// https://eslint.org/docs/rules/no-return-await
|
|
310
|
+
"no-return-await": "error",
|
|
311
|
+
|
|
312
|
+
// disallow use of `javascript:` urls.
|
|
313
|
+
// https://eslint.org/docs/rules/no-script-url
|
|
314
|
+
"no-script-url": "error",
|
|
315
|
+
|
|
316
|
+
// disallow self assignment
|
|
317
|
+
// https://eslint.org/docs/rules/no-self-assign
|
|
318
|
+
"no-self-assign": ["error", {
|
|
319
|
+
props: true,
|
|
320
|
+
}],
|
|
321
|
+
|
|
322
|
+
// disallow comparisons where both sides are exactly the same
|
|
323
|
+
// https://eslint.org/docs/rules/no-self-compare
|
|
324
|
+
"no-self-compare": "error",
|
|
325
|
+
|
|
326
|
+
// disallow use of comma operator
|
|
327
|
+
// https://eslint.org/docs/rules/no-sequences
|
|
328
|
+
"no-sequences": "error",
|
|
329
|
+
|
|
330
|
+
// restrict what can be thrown as an exception
|
|
331
|
+
// https://eslint.org/docs/rules/no-throw-literal
|
|
332
|
+
"no-throw-literal": "error",
|
|
333
|
+
|
|
334
|
+
// disallow unmodified conditions of loops
|
|
335
|
+
// https://eslint.org/docs/rules/no-unmodified-loop-condition
|
|
336
|
+
"no-unmodified-loop-condition": "off",
|
|
337
|
+
|
|
338
|
+
// 禁止未使用过的表达式
|
|
339
|
+
// https://eslint.org/docs/rules/no-unused-expressions
|
|
340
|
+
"no-unused-expressions": ["warn", { "allowShortCircuit": true }],
|
|
341
|
+
// 'no-unused-expressions': ['error', {
|
|
342
|
+
// allowShortCircuit: false,
|
|
343
|
+
// allowTernary: false,
|
|
344
|
+
// allowTaggedTemplates: false,
|
|
345
|
+
// }],
|
|
346
|
+
|
|
347
|
+
// disallow unused labels
|
|
348
|
+
// https://eslint.org/docs/rules/no-unused-labels
|
|
349
|
+
"no-unused-labels": "error",
|
|
350
|
+
|
|
351
|
+
// disallow unnecessary .call() and .apply()
|
|
352
|
+
// https://eslint.org/docs/rules/no-useless-call
|
|
353
|
+
"no-useless-call": "off",
|
|
354
|
+
|
|
355
|
+
// Disallow unnecessary catch clauses
|
|
356
|
+
// https://eslint.org/docs/rules/no-useless-catch
|
|
357
|
+
"no-useless-catch": "error",
|
|
358
|
+
|
|
359
|
+
// disallow useless string concatenation
|
|
360
|
+
// https://eslint.org/docs/rules/no-useless-concat
|
|
361
|
+
"no-useless-concat": "error",
|
|
362
|
+
|
|
363
|
+
// disallow unnecessary string escaping
|
|
364
|
+
// https://eslint.org/docs/rules/no-useless-escape
|
|
365
|
+
"no-useless-escape": "error",
|
|
366
|
+
|
|
367
|
+
// disallow redundant return; keywords
|
|
368
|
+
// https://eslint.org/docs/rules/no-useless-return
|
|
369
|
+
"no-useless-return": "error",
|
|
370
|
+
|
|
371
|
+
// disallow use of void operator
|
|
372
|
+
// https://eslint.org/docs/rules/no-void
|
|
373
|
+
"no-void": "error",
|
|
374
|
+
|
|
375
|
+
// disallow usage of configurable warning terms in comments: e.g. todo
|
|
376
|
+
// https://eslint.org/docs/rules/no-warning-comments
|
|
377
|
+
"no-warning-comments": ["off", { terms: ["todo", "fixme", "xxx"], location: "start" }],
|
|
378
|
+
|
|
379
|
+
// disallow use of the with statement
|
|
380
|
+
// https://eslint.org/docs/rules/no-with
|
|
381
|
+
"no-with": "error",
|
|
382
|
+
|
|
383
|
+
// require using Error objects as Promise rejection reasons
|
|
384
|
+
// https://eslint.org/docs/rules/prefer-promise-reject-errors
|
|
385
|
+
"prefer-promise-reject-errors": ["error", { allowEmptyReject: true }],
|
|
386
|
+
|
|
387
|
+
// Suggest using named capture group in regular expression
|
|
388
|
+
// https://eslint.org/docs/rules/prefer-named-capture-group
|
|
389
|
+
"prefer-named-capture-group": "off",
|
|
390
|
+
|
|
391
|
+
// https://eslint.org/docs/rules/prefer-regex-literals
|
|
392
|
+
"prefer-regex-literals": ["error", {
|
|
393
|
+
disallowRedundantWrapping: true,
|
|
394
|
+
}],
|
|
395
|
+
|
|
396
|
+
// 当使用parseInt()函数时,要求必须有基数
|
|
397
|
+
// https://eslint.org/docs/rules/radix
|
|
398
|
+
"radix": "off",
|
|
399
|
+
// radix: 'error',
|
|
400
|
+
|
|
401
|
+
// require `await` in `async function` (note: this is a horrible rule that should never be used)
|
|
402
|
+
// https://eslint.org/docs/rules/require-await
|
|
403
|
+
"require-await": "off",
|
|
404
|
+
|
|
405
|
+
// Enforce the use of u flag on RegExp
|
|
406
|
+
// https://eslint.org/docs/rules/require-unicode-regexp
|
|
407
|
+
"require-unicode-regexp": "off",
|
|
408
|
+
|
|
409
|
+
// requires to declare all vars on top of their containing scope
|
|
410
|
+
// https://eslint.org/docs/rules/vars-on-top
|
|
411
|
+
"vars-on-top": "error",
|
|
412
|
+
|
|
413
|
+
// 要求 IIFE 使用括号括起来
|
|
414
|
+
// https://eslint.org/docs/rules/wrap-iife.html
|
|
415
|
+
"wrap-iife": ["error", "outside", { functionPrototypeMethods: true }],
|
|
416
|
+
|
|
417
|
+
// 要求或禁止 “Yoda” 条件
|
|
418
|
+
// https://eslint.org/docs/rules/yoda
|
|
419
|
+
"yoda": "off",
|
|
420
|
+
// yoda: 'error'
|
|
421
|
+
},
|
|
422
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// ES6
|
|
4
|
+
// 这些规则只与 ES6 有关, 即通常所说的 ES2015
|
|
5
|
+
// ==========================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
env: {
|
|
9
|
+
es6: true,
|
|
10
|
+
},
|
|
11
|
+
parserOptions: {
|
|
12
|
+
ecmaVersion: 6,
|
|
13
|
+
sourceType: "module",
|
|
14
|
+
ecmaFeatures: {
|
|
15
|
+
generators: false,
|
|
16
|
+
objectLiteralDuplicateProperties: false,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
rules: {
|
|
20
|
+
// enforces no braces where they can be omitted
|
|
21
|
+
// https://eslint.org/docs/rules/arrow-body-style
|
|
22
|
+
// TODO: enable requireReturnForObjectLiteral?
|
|
23
|
+
"arrow-body-style": ["error", "as-needed", {
|
|
24
|
+
requireReturnForObjectLiteral: false,
|
|
25
|
+
}],
|
|
26
|
+
|
|
27
|
+
// 要求箭头函数的参数使用圆括号
|
|
28
|
+
// https://eslint.org/docs/rules/arrow-parens
|
|
29
|
+
"arrow-parens": ["warn", "as-needed"],
|
|
30
|
+
|
|
31
|
+
// 要求箭头函数的箭头之前或之后有空格
|
|
32
|
+
// https://eslint.org/docs/rules/arrow-spacing
|
|
33
|
+
"arrow-spacing": ["warn", {
|
|
34
|
+
"before": true,
|
|
35
|
+
"after": true,
|
|
36
|
+
}],
|
|
37
|
+
|
|
38
|
+
// verify super() callings in constructors
|
|
39
|
+
"constructor-super": "error",
|
|
40
|
+
|
|
41
|
+
// 强制 generator 函数中 * 号周围使用一致的空格
|
|
42
|
+
// https://eslint.org/docs/rules/generator-star-spacing
|
|
43
|
+
"generator-star-spacing": ["warn", {
|
|
44
|
+
before: false,
|
|
45
|
+
after: true,
|
|
46
|
+
}],
|
|
47
|
+
|
|
48
|
+
// disallow modifying variables of class declarations
|
|
49
|
+
// https://eslint.org/docs/rules/no-class-assign
|
|
50
|
+
"no-class-assign": "error",
|
|
51
|
+
|
|
52
|
+
// 禁止在可能与比较操作符相混淆的地方使用箭头函数
|
|
53
|
+
// https://eslint.org/docs/rules/no-confusing-arrow
|
|
54
|
+
"no-confusing-arrow": ["error", {
|
|
55
|
+
"allowParens": true,
|
|
56
|
+
}],
|
|
57
|
+
|
|
58
|
+
// disallow modifying variables that are declared using const
|
|
59
|
+
"no-const-assign": "error",
|
|
60
|
+
|
|
61
|
+
// disallow duplicate class members
|
|
62
|
+
// https://eslint.org/docs/rules/no-dupe-class-members
|
|
63
|
+
"no-dupe-class-members": "error",
|
|
64
|
+
|
|
65
|
+
// disallow importing from the same path more than once
|
|
66
|
+
// https://eslint.org/docs/rules/no-duplicate-imports
|
|
67
|
+
// replaced by https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
|
|
68
|
+
"no-duplicate-imports": "off",
|
|
69
|
+
|
|
70
|
+
// disallow symbol constructor
|
|
71
|
+
// https://eslint.org/docs/rules/no-new-symbol
|
|
72
|
+
"no-new-symbol": "error",
|
|
73
|
+
|
|
74
|
+
// Disallow specified names in exports
|
|
75
|
+
// https://eslint.org/docs/rules/no-restricted-exports
|
|
76
|
+
"no-restricted-exports": ["error", {
|
|
77
|
+
restrictedNamedExports: [
|
|
78
|
+
"default", // use `export default` to provide a default export
|
|
79
|
+
"then" // this will cause tons of confusion when your module is dynamically `import()`ed, and will break in most node ESM versions
|
|
80
|
+
],
|
|
81
|
+
}],
|
|
82
|
+
|
|
83
|
+
// disallow specific imports
|
|
84
|
+
// https://eslint.org/docs/rules/no-restricted-imports
|
|
85
|
+
"no-restricted-imports": ["off", {
|
|
86
|
+
paths: [],
|
|
87
|
+
patterns: [],
|
|
88
|
+
}],
|
|
89
|
+
|
|
90
|
+
// disallow to use this/super before super() calling in constructors.
|
|
91
|
+
// https://eslint.org/docs/rules/no-this-before-super
|
|
92
|
+
"no-this-before-super": "error",
|
|
93
|
+
|
|
94
|
+
// disallow useless computed property keys
|
|
95
|
+
// https://eslint.org/docs/rules/no-useless-computed-key
|
|
96
|
+
"no-useless-computed-key": "error",
|
|
97
|
+
|
|
98
|
+
// disallow unnecessary constructor
|
|
99
|
+
// https://eslint.org/docs/rules/no-useless-constructor
|
|
100
|
+
"no-useless-constructor": "error",
|
|
101
|
+
|
|
102
|
+
// disallow renaming import, export, and destructured assignments to the same name
|
|
103
|
+
// https://eslint.org/docs/rules/no-useless-rename
|
|
104
|
+
"no-useless-rename": ["error", {
|
|
105
|
+
ignoreDestructuring: false,
|
|
106
|
+
ignoreImport: false,
|
|
107
|
+
ignoreExport: false,
|
|
108
|
+
}],
|
|
109
|
+
|
|
110
|
+
// require let or const instead of var
|
|
111
|
+
"no-var": "error",
|
|
112
|
+
|
|
113
|
+
// require method and property shorthand syntax for object literals
|
|
114
|
+
// https://eslint.org/docs/rules/object-shorthand
|
|
115
|
+
"object-shorthand": ["error", "always", {
|
|
116
|
+
ignoreConstructors: false,
|
|
117
|
+
avoidQuotes: true,
|
|
118
|
+
}],
|
|
119
|
+
|
|
120
|
+
// suggest using arrow functions as callbacks
|
|
121
|
+
"prefer-arrow-callback": ["error", {
|
|
122
|
+
allowNamedFunctions: false,
|
|
123
|
+
allowUnboundThis: true,
|
|
124
|
+
}],
|
|
125
|
+
|
|
126
|
+
// suggest using of const declaration for variables that are never modified after declared
|
|
127
|
+
"prefer-const": ["error", {
|
|
128
|
+
destructuring: "any",
|
|
129
|
+
ignoreReadBeforeAssign: true,
|
|
130
|
+
}],
|
|
131
|
+
|
|
132
|
+
// 优先使用数组和对象解构
|
|
133
|
+
// https://eslint.org/docs/rules/prefer-destructuring
|
|
134
|
+
"prefer-destructuring": "off",
|
|
135
|
+
// 'prefer-destructuring': ['error', {
|
|
136
|
+
// VariableDeclarator: {
|
|
137
|
+
// array: false,
|
|
138
|
+
// object: true,
|
|
139
|
+
// },
|
|
140
|
+
// AssignmentExpression: {
|
|
141
|
+
// array: true,
|
|
142
|
+
// object: false,
|
|
143
|
+
// },
|
|
144
|
+
// }, {
|
|
145
|
+
// enforceForRenamedProperties: false,
|
|
146
|
+
// }],
|
|
147
|
+
|
|
148
|
+
// disallow parseInt() in favor of binary, octal, and hexadecimal literals
|
|
149
|
+
// https://eslint.org/docs/rules/prefer-numeric-literals
|
|
150
|
+
"prefer-numeric-literals": "error",
|
|
151
|
+
|
|
152
|
+
// suggest using Reflect methods where applicable
|
|
153
|
+
// https://eslint.org/docs/rules/prefer-reflect
|
|
154
|
+
"prefer-reflect": "off",
|
|
155
|
+
|
|
156
|
+
// use rest parameters instead of arguments
|
|
157
|
+
// https://eslint.org/docs/rules/prefer-rest-params
|
|
158
|
+
"prefer-rest-params": "error",
|
|
159
|
+
|
|
160
|
+
// suggest using the spread syntax instead of .apply()
|
|
161
|
+
// https://eslint.org/docs/rules/prefer-spread
|
|
162
|
+
"prefer-spread": "error",
|
|
163
|
+
|
|
164
|
+
// suggest using template literals instead of string concatenation
|
|
165
|
+
// https://eslint.org/docs/rules/prefer-template
|
|
166
|
+
"prefer-template": "error",
|
|
167
|
+
|
|
168
|
+
// disallow generator functions that do not have yield
|
|
169
|
+
// https://eslint.org/docs/rules/require-yield
|
|
170
|
+
"require-yield": "error",
|
|
171
|
+
|
|
172
|
+
// 强制剩余和扩展运算符及其表达式之间有空格
|
|
173
|
+
// https://eslint.org/docs/rules/rest-spread-spacing
|
|
174
|
+
"rest-spread-spacing": ["error", "never"],
|
|
175
|
+
|
|
176
|
+
// import sorting
|
|
177
|
+
// https://eslint.org/docs/rules/sort-imports
|
|
178
|
+
"sort-imports": ["off", {
|
|
179
|
+
ignoreCase: false,
|
|
180
|
+
ignoreDeclarationSort: false,
|
|
181
|
+
ignoreMemberSort: false,
|
|
182
|
+
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
|
|
183
|
+
}],
|
|
184
|
+
|
|
185
|
+
// require a Symbol description
|
|
186
|
+
// https://eslint.org/docs/rules/symbol-description
|
|
187
|
+
"symbol-description": "error",
|
|
188
|
+
|
|
189
|
+
// 要求或禁止模板字符串中的嵌入表达式周围空格的使用
|
|
190
|
+
// https://eslint.org/docs/rules/template-curly-spacing
|
|
191
|
+
"template-curly-spacing": "error",
|
|
192
|
+
|
|
193
|
+
// 强制在 yield* 表达式中 * 周围使用空格
|
|
194
|
+
// https://eslint.org/docs/rules/yield-star-spacing
|
|
195
|
+
"yield-star-spacing": ["error", "after"],
|
|
196
|
+
},
|
|
197
|
+
};
|