@huangjunsen/eslint-config 1.0.0 → 1.0.2
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/.editorconfig +17 -17
- package/.eslintignore +17 -17
- package/.eslintrc.js +5 -5
- package/CHANGELOG.md +7 -0
- package/README.md +0 -286
- package/__tests__/fixtures/es5.js +4 -4
- package/__tests__/fixtures/index.js +3 -3
- package/__tests__/fixtures/node.js +23 -23
- package/__tests__/fixtures/react-display-name.js +7 -7
- package/__tests__/fixtures/react.jsx +132 -132
- package/__tests__/fixtures/ts-import-a.ts +3 -3
- package/__tests__/fixtures/ts-import-b.ts +3 -3
- package/__tests__/fixtures/ts-node.ts +19 -19
- package/__tests__/fixtures/ts-react.tsx +27 -27
- package/__tests__/fixtures/ts-vue.vue +36 -36
- package/__tests__/fixtures/ts.ts +17 -17
- package/__tests__/fixtures/vue.vue +16 -16
- package/__tests__/validate-js-configs.test.js +259 -259
- package/es5.js +10 -10
- package/essential/es5.js +12 -12
- package/essential/index.js +12 -12
- package/essential/react.js +76 -76
- package/essential/rules/blacklist.js +48 -48
- package/essential/rules/es6-blacklist.js +62 -62
- package/essential/rules/set-style-to-warn.js +30 -30
- package/essential/rules/ts-blacklist.js +15 -15
- package/essential/typescript/index.js +7 -7
- package/essential/typescript/react.js +7 -7
- package/essential/typescript/vue.js +9 -9
- package/essential/vue.js +8 -8
- package/flat/index.js +32 -0
- package/flat/react.js +19 -0
- package/flat/typescript.js +15 -0
- package/flat/vue.js +12 -0
- package/index.js +23 -23
- package/jsx-a11y.js +5 -5
- package/node.js +6 -6
- package/package.json +28 -10
- package/react.js +11 -11
- package/rules/base/best-practices.js +284 -284
- package/rules/base/es6.js +168 -168
- package/rules/base/possible-errors.js +126 -126
- package/rules/base/strict.js +6 -6
- package/rules/base/style.js +445 -445
- package/rules/base/variables.js +48 -48
- package/rules/es5.js +11 -11
- package/rules/imports.js +167 -167
- package/rules/jsx-a11y.js +23 -23
- package/rules/node.js +11 -11
- package/rules/react.js +354 -354
- package/rules/vue.js +96 -96
- package/typescript/node.js +6 -6
- package/typescript/react.js +6 -6
- package/typescript/vue.js +10 -10
- package/vue.js +10 -10
- package/LICENSE +0 -21
|
@@ -1,284 +1,284 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
rules: {
|
|
3
|
-
// 强制 getter 和 setter 在对象中成对出现
|
|
4
|
-
'accessor-pairs': 'off',
|
|
5
|
-
|
|
6
|
-
// 某些数组方法的回调函数中必须包含 return 语句
|
|
7
|
-
'array-callback-return': ['error', { allowImplicit: true }],
|
|
8
|
-
|
|
9
|
-
// 把 var 语句看作是在块级作用域范围之内,不能在块外使用
|
|
10
|
-
'block-scoped-var': 'error',
|
|
11
|
-
|
|
12
|
-
// 强制类的方法使用 this
|
|
13
|
-
'class-methods-use-this': [
|
|
14
|
-
'off',
|
|
15
|
-
{
|
|
16
|
-
exceptMethods: [],
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
|
|
20
|
-
// 设置圈复杂度最大值
|
|
21
|
-
// @reason IDE 插件会把大段代码标红,影响编码体验,此类问题适合做后置检查
|
|
22
|
-
complexity: ['off', 10],
|
|
23
|
-
|
|
24
|
-
// 要求 return 语句要么总是指定返回的值,要么不指定
|
|
25
|
-
'consistent-return': 'off',
|
|
26
|
-
|
|
27
|
-
// 多行语句必须用大括号包裹,单行语句推荐用大括号包裹
|
|
28
|
-
curly: ['error', 'multi-line'],
|
|
29
|
-
|
|
30
|
-
// switch 语句需要始终包含 default 分支
|
|
31
|
-
'default-case': ['warn', { commentPattern: '^no default$' }],
|
|
32
|
-
|
|
33
|
-
// 统一在点号之前换行
|
|
34
|
-
// @unessential
|
|
35
|
-
'dot-location': ['error', 'property'],
|
|
36
|
-
|
|
37
|
-
// 优先使用 . 访问对象的属性
|
|
38
|
-
'dot-notation': ['error', { allowKeywords: true }],
|
|
39
|
-
|
|
40
|
-
// 使用严格相等运算符
|
|
41
|
-
eqeqeq: ['warn', 'always', { null: 'ignore' }],
|
|
42
|
-
|
|
43
|
-
// for-in 循环中需要对 key 进行验证
|
|
44
|
-
'guard-for-in': 'warn',
|
|
45
|
-
|
|
46
|
-
// enforce a maximum number of classes per file
|
|
47
|
-
'max-classes-per-file': 'off',
|
|
48
|
-
|
|
49
|
-
// 禁止使用 alert
|
|
50
|
-
'no-alert': 'warn',
|
|
51
|
-
|
|
52
|
-
// 禁止使用 arguments.caller 和 arguments.callee
|
|
53
|
-
'no-caller': 'error',
|
|
54
|
-
|
|
55
|
-
// case 或 default 字句出现词法声明时,必须用块包裹
|
|
56
|
-
'no-case-declarations': 'error',
|
|
57
|
-
|
|
58
|
-
// 禁止使用看起来像除法的正则表达式
|
|
59
|
-
'no-div-regex': 'off',
|
|
60
|
-
|
|
61
|
-
// 如果一个 if 语句的结果总是返回一个 return 语句,那么最后的 else 是不必要的
|
|
62
|
-
// @reason 很多人习惯写 else return
|
|
63
|
-
'no-else-return': 'off',
|
|
64
|
-
|
|
65
|
-
// 不要出现空函数
|
|
66
|
-
'no-empty-function': [
|
|
67
|
-
'error',
|
|
68
|
-
{
|
|
69
|
-
allow: ['arrowFunctions', 'functions', 'methods'],
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
|
|
73
|
-
// 不要在解构中出现空模式,即 {} 或 []
|
|
74
|
-
'no-empty-pattern': 'error',
|
|
75
|
-
|
|
76
|
-
// 与 null 的比较必须使用严格等于操作符
|
|
77
|
-
'no-eq-null': 'off',
|
|
78
|
-
|
|
79
|
-
// 禁止使用 eval
|
|
80
|
-
// @unessential 部分场景必须使用 eval
|
|
81
|
-
'no-eval': 'error',
|
|
82
|
-
|
|
83
|
-
// 禁止扩展原生对象
|
|
84
|
-
'no-extend-native': 'error',
|
|
85
|
-
|
|
86
|
-
// 禁止不必要的 .bind() 调用
|
|
87
|
-
'no-extra-bind': 'error',
|
|
88
|
-
|
|
89
|
-
// 禁止不必要的 label
|
|
90
|
-
'no-extra-label': 'error',
|
|
91
|
-
|
|
92
|
-
// 不要让 case 语句落空
|
|
93
|
-
'no-fallthrough': 'error',
|
|
94
|
-
|
|
95
|
-
// 不要省略小数点前或小数点后的 0
|
|
96
|
-
'no-floating-decimal': 'error',
|
|
97
|
-
|
|
98
|
-
// 禁止对原生对象或只读的全局对象进行赋值
|
|
99
|
-
'no-global-assign': ['error', { exceptions: [] }],
|
|
100
|
-
|
|
101
|
-
// 禁止使用较短的符号实现类型转换
|
|
102
|
-
'no-implicit-coercion': [
|
|
103
|
-
'off',
|
|
104
|
-
{
|
|
105
|
-
boolean: false,
|
|
106
|
-
number: true,
|
|
107
|
-
string: true,
|
|
108
|
-
allow: [],
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
|
|
112
|
-
// 禁止在全局范围使用变量和函数声明
|
|
113
|
-
// @reason 这条在 "parserOptions": { "sourceType": "module" } 下不起作用
|
|
114
|
-
'no-implicit-globals': 'off',
|
|
115
|
-
|
|
116
|
-
// 禁止使用类 eval 的方法,如 setTimeout 传入字符串
|
|
117
|
-
// @unessential
|
|
118
|
-
'no-implied-eval': 'error',
|
|
119
|
-
|
|
120
|
-
// 禁止在 class 外使用 this
|
|
121
|
-
'no-invalid-this': 'off',
|
|
122
|
-
|
|
123
|
-
// 禁止使用 __iterator__ 属性
|
|
124
|
-
'no-iterator': 'error',
|
|
125
|
-
|
|
126
|
-
// 不要使用 label
|
|
127
|
-
'no-labels': ['warn', { allowLoop: false, allowSwitch: false }],
|
|
128
|
-
|
|
129
|
-
// 禁止使用不必要的代码块
|
|
130
|
-
'no-lone-blocks': 'error',
|
|
131
|
-
|
|
132
|
-
// 禁止在循环中的函数内出现外部作用域中定义且会发生变化的变量,以防止闭包副作用
|
|
133
|
-
'no-loop-func': 'error',
|
|
134
|
-
|
|
135
|
-
// 禁用魔术数字
|
|
136
|
-
'no-magic-numbers': [
|
|
137
|
-
'off',
|
|
138
|
-
{
|
|
139
|
-
ignore: [],
|
|
140
|
-
ignoreArrayIndexes: true,
|
|
141
|
-
enforceConst: true,
|
|
142
|
-
detectObjects: false,
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
|
|
146
|
-
// 禁止出现多个连续空格
|
|
147
|
-
// @unessential
|
|
148
|
-
'no-multi-spaces': [
|
|
149
|
-
'error',
|
|
150
|
-
{
|
|
151
|
-
ignoreEOLComments: false,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
|
|
155
|
-
// 禁止使用多行字符串
|
|
156
|
-
'no-multi-str': 'error',
|
|
157
|
-
|
|
158
|
-
// 禁止单独 new 一个构造函数而不用于赋值或比较
|
|
159
|
-
'no-new': 'error',
|
|
160
|
-
|
|
161
|
-
// 不要使用 Function 构造函数创建函数
|
|
162
|
-
'no-new-func': 'error',
|
|
163
|
-
|
|
164
|
-
// 不要使用 new Number/String/Boolean
|
|
165
|
-
'no-new-wrappers': 'error',
|
|
166
|
-
|
|
167
|
-
// 禁用八进制字面量
|
|
168
|
-
'no-octal': 'error',
|
|
169
|
-
|
|
170
|
-
// 禁止在字符串字面量中使用八进制转义序列,如 var foo = 'Copyright \251';
|
|
171
|
-
'no-octal-escape': 'error',
|
|
172
|
-
|
|
173
|
-
// 不要修改函数参数
|
|
174
|
-
'no-param-reassign': [
|
|
175
|
-
'warn',
|
|
176
|
-
{
|
|
177
|
-
props: true,
|
|
178
|
-
ignorePropertyModificationsFor: [
|
|
179
|
-
'acc', // for reduce accumulators
|
|
180
|
-
'e', // for e.returnvalue
|
|
181
|
-
'ctx', // for Koa routing
|
|
182
|
-
'draft', // for immer
|
|
183
|
-
'req', // for Express requests
|
|
184
|
-
'request', // for Express requests
|
|
185
|
-
'res', // for Express responses
|
|
186
|
-
'response', // for Express responses
|
|
187
|
-
'$scope', // for Angular 1 scopes
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
|
|
192
|
-
// 禁止使用 __proto__ 属性
|
|
193
|
-
'no-proto': 'error',
|
|
194
|
-
|
|
195
|
-
// 不要重复声明变量和函数
|
|
196
|
-
'no-redeclare': 'error',
|
|
197
|
-
|
|
198
|
-
// 禁止使用某些对象的某些属性
|
|
199
|
-
'no-restricted-properties': 'off',
|
|
200
|
-
|
|
201
|
-
// 禁止在 return 语句中赋值
|
|
202
|
-
'no-return-assign': ['error', 'always'],
|
|
203
|
-
|
|
204
|
-
// 禁止不必要的 return await
|
|
205
|
-
'no-return-await': 'off',
|
|
206
|
-
|
|
207
|
-
// 禁止使用 javascript:url,如 location.href = 'javascript:void(0)';
|
|
208
|
-
// @unessential
|
|
209
|
-
'no-script-url': 'error',
|
|
210
|
-
|
|
211
|
-
// 禁止自我赋值
|
|
212
|
-
'no-self-assign': 'error',
|
|
213
|
-
|
|
214
|
-
// 禁止自我比较
|
|
215
|
-
'no-self-compare': 'error',
|
|
216
|
-
|
|
217
|
-
// 禁止使用逗号操作符,除非用于 for 循环条件或明确用小括号包裹
|
|
218
|
-
'no-sequences': 'error',
|
|
219
|
-
|
|
220
|
-
// 不要抛出字面量异常
|
|
221
|
-
'no-throw-literal': 'warn',
|
|
222
|
-
|
|
223
|
-
// 禁用不变的循环条件
|
|
224
|
-
'no-unmodified-loop-condition': 'off',
|
|
225
|
-
|
|
226
|
-
// 禁止出现未使用的表达式
|
|
227
|
-
'no-unused-expressions': [
|
|
228
|
-
'error',
|
|
229
|
-
{
|
|
230
|
-
allowShortCircuit: true,
|
|
231
|
-
allowTernary: true,
|
|
232
|
-
allowTaggedTemplates: true,
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
|
|
236
|
-
// 禁止未使用的标签
|
|
237
|
-
'no-unused-labels': 'error',
|
|
238
|
-
|
|
239
|
-
// 禁用不必要的 .call() 和 .apply()
|
|
240
|
-
'no-useless-call': 'off',
|
|
241
|
-
|
|
242
|
-
// 禁用不必要的 catch
|
|
243
|
-
'no-useless-catch': 'error',
|
|
244
|
-
|
|
245
|
-
// 禁止不必要的字符串拼接
|
|
246
|
-
'no-useless-concat': 'error',
|
|
247
|
-
|
|
248
|
-
// 禁止不必要的转义字符
|
|
249
|
-
'no-useless-escape': 'error',
|
|
250
|
-
|
|
251
|
-
// 禁止多余的 return; 语句
|
|
252
|
-
'no-useless-return': 'error',
|
|
253
|
-
|
|
254
|
-
// 不要使用 void 运算符
|
|
255
|
-
'no-void': 'error',
|
|
256
|
-
|
|
257
|
-
// 禁止在注释中使用特定的警告术语
|
|
258
|
-
'no-warning-comments': ['off', { terms: ['todo', 'fixme'], location: 'start' }],
|
|
259
|
-
|
|
260
|
-
// 禁止使用 with
|
|
261
|
-
'no-with': 'error',
|
|
262
|
-
|
|
263
|
-
// Promise 的 reject 需要传入 Error 对象
|
|
264
|
-
'prefer-promise-reject-errors': ['warn', { allowEmptyReject: true }],
|
|
265
|
-
|
|
266
|
-
// 使用 parseInt() 方法时总是带上基数
|
|
267
|
-
radix: 'warn',
|
|
268
|
-
|
|
269
|
-
// 禁止使用不带 await 表达式的 async 函数
|
|
270
|
-
'require-await': 'off',
|
|
271
|
-
|
|
272
|
-
// 强制正则使用 u 参数
|
|
273
|
-
'require-unicode-regexp': 'off',
|
|
274
|
-
|
|
275
|
-
// 要求所有的 var 声明出现在它们所在的作用域顶部
|
|
276
|
-
'vars-on-top': 'off',
|
|
277
|
-
|
|
278
|
-
// 将立即执行函数表达式(IIFE)用小括号包裹
|
|
279
|
-
'wrap-iife': ['error', 'any', { functionPrototypeMethods: false }],
|
|
280
|
-
|
|
281
|
-
// 使用 color === 'red' 而不是 'red' === color
|
|
282
|
-
yoda: 'warn',
|
|
283
|
-
},
|
|
284
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
// 强制 getter 和 setter 在对象中成对出现
|
|
4
|
+
'accessor-pairs': 'off',
|
|
5
|
+
|
|
6
|
+
// 某些数组方法的回调函数中必须包含 return 语句
|
|
7
|
+
'array-callback-return': ['error', { allowImplicit: true }],
|
|
8
|
+
|
|
9
|
+
// 把 var 语句看作是在块级作用域范围之内,不能在块外使用
|
|
10
|
+
'block-scoped-var': 'error',
|
|
11
|
+
|
|
12
|
+
// 强制类的方法使用 this
|
|
13
|
+
'class-methods-use-this': [
|
|
14
|
+
'off',
|
|
15
|
+
{
|
|
16
|
+
exceptMethods: [],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
// 设置圈复杂度最大值
|
|
21
|
+
// @reason IDE 插件会把大段代码标红,影响编码体验,此类问题适合做后置检查
|
|
22
|
+
complexity: ['off', 10],
|
|
23
|
+
|
|
24
|
+
// 要求 return 语句要么总是指定返回的值,要么不指定
|
|
25
|
+
'consistent-return': 'off',
|
|
26
|
+
|
|
27
|
+
// 多行语句必须用大括号包裹,单行语句推荐用大括号包裹
|
|
28
|
+
curly: ['error', 'multi-line'],
|
|
29
|
+
|
|
30
|
+
// switch 语句需要始终包含 default 分支
|
|
31
|
+
'default-case': ['warn', { commentPattern: '^no default$' }],
|
|
32
|
+
|
|
33
|
+
// 统一在点号之前换行
|
|
34
|
+
// @unessential
|
|
35
|
+
'dot-location': ['error', 'property'],
|
|
36
|
+
|
|
37
|
+
// 优先使用 . 访问对象的属性
|
|
38
|
+
'dot-notation': ['error', { allowKeywords: true }],
|
|
39
|
+
|
|
40
|
+
// 使用严格相等运算符
|
|
41
|
+
eqeqeq: ['warn', 'always', { null: 'ignore' }],
|
|
42
|
+
|
|
43
|
+
// for-in 循环中需要对 key 进行验证
|
|
44
|
+
'guard-for-in': 'warn',
|
|
45
|
+
|
|
46
|
+
// enforce a maximum number of classes per file
|
|
47
|
+
'max-classes-per-file': 'off',
|
|
48
|
+
|
|
49
|
+
// 禁止使用 alert
|
|
50
|
+
'no-alert': 'warn',
|
|
51
|
+
|
|
52
|
+
// 禁止使用 arguments.caller 和 arguments.callee
|
|
53
|
+
'no-caller': 'error',
|
|
54
|
+
|
|
55
|
+
// case 或 default 字句出现词法声明时,必须用块包裹
|
|
56
|
+
'no-case-declarations': 'error',
|
|
57
|
+
|
|
58
|
+
// 禁止使用看起来像除法的正则表达式
|
|
59
|
+
'no-div-regex': 'off',
|
|
60
|
+
|
|
61
|
+
// 如果一个 if 语句的结果总是返回一个 return 语句,那么最后的 else 是不必要的
|
|
62
|
+
// @reason 很多人习惯写 else return
|
|
63
|
+
'no-else-return': 'off',
|
|
64
|
+
|
|
65
|
+
// 不要出现空函数
|
|
66
|
+
'no-empty-function': [
|
|
67
|
+
'error',
|
|
68
|
+
{
|
|
69
|
+
allow: ['arrowFunctions', 'functions', 'methods'],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
// 不要在解构中出现空模式,即 {} 或 []
|
|
74
|
+
'no-empty-pattern': 'error',
|
|
75
|
+
|
|
76
|
+
// 与 null 的比较必须使用严格等于操作符
|
|
77
|
+
'no-eq-null': 'off',
|
|
78
|
+
|
|
79
|
+
// 禁止使用 eval
|
|
80
|
+
// @unessential 部分场景必须使用 eval
|
|
81
|
+
'no-eval': 'error',
|
|
82
|
+
|
|
83
|
+
// 禁止扩展原生对象
|
|
84
|
+
'no-extend-native': 'error',
|
|
85
|
+
|
|
86
|
+
// 禁止不必要的 .bind() 调用
|
|
87
|
+
'no-extra-bind': 'error',
|
|
88
|
+
|
|
89
|
+
// 禁止不必要的 label
|
|
90
|
+
'no-extra-label': 'error',
|
|
91
|
+
|
|
92
|
+
// 不要让 case 语句落空
|
|
93
|
+
'no-fallthrough': 'error',
|
|
94
|
+
|
|
95
|
+
// 不要省略小数点前或小数点后的 0
|
|
96
|
+
'no-floating-decimal': 'error',
|
|
97
|
+
|
|
98
|
+
// 禁止对原生对象或只读的全局对象进行赋值
|
|
99
|
+
'no-global-assign': ['error', { exceptions: [] }],
|
|
100
|
+
|
|
101
|
+
// 禁止使用较短的符号实现类型转换
|
|
102
|
+
'no-implicit-coercion': [
|
|
103
|
+
'off',
|
|
104
|
+
{
|
|
105
|
+
boolean: false,
|
|
106
|
+
number: true,
|
|
107
|
+
string: true,
|
|
108
|
+
allow: [],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
|
|
112
|
+
// 禁止在全局范围使用变量和函数声明
|
|
113
|
+
// @reason 这条在 "parserOptions": { "sourceType": "module" } 下不起作用
|
|
114
|
+
'no-implicit-globals': 'off',
|
|
115
|
+
|
|
116
|
+
// 禁止使用类 eval 的方法,如 setTimeout 传入字符串
|
|
117
|
+
// @unessential
|
|
118
|
+
'no-implied-eval': 'error',
|
|
119
|
+
|
|
120
|
+
// 禁止在 class 外使用 this
|
|
121
|
+
'no-invalid-this': 'off',
|
|
122
|
+
|
|
123
|
+
// 禁止使用 __iterator__ 属性
|
|
124
|
+
'no-iterator': 'error',
|
|
125
|
+
|
|
126
|
+
// 不要使用 label
|
|
127
|
+
'no-labels': ['warn', { allowLoop: false, allowSwitch: false }],
|
|
128
|
+
|
|
129
|
+
// 禁止使用不必要的代码块
|
|
130
|
+
'no-lone-blocks': 'error',
|
|
131
|
+
|
|
132
|
+
// 禁止在循环中的函数内出现外部作用域中定义且会发生变化的变量,以防止闭包副作用
|
|
133
|
+
'no-loop-func': 'error',
|
|
134
|
+
|
|
135
|
+
// 禁用魔术数字
|
|
136
|
+
'no-magic-numbers': [
|
|
137
|
+
'off',
|
|
138
|
+
{
|
|
139
|
+
ignore: [],
|
|
140
|
+
ignoreArrayIndexes: true,
|
|
141
|
+
enforceConst: true,
|
|
142
|
+
detectObjects: false,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
|
|
146
|
+
// 禁止出现多个连续空格
|
|
147
|
+
// @unessential
|
|
148
|
+
'no-multi-spaces': [
|
|
149
|
+
'error',
|
|
150
|
+
{
|
|
151
|
+
ignoreEOLComments: false,
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
|
|
155
|
+
// 禁止使用多行字符串
|
|
156
|
+
'no-multi-str': 'error',
|
|
157
|
+
|
|
158
|
+
// 禁止单独 new 一个构造函数而不用于赋值或比较
|
|
159
|
+
'no-new': 'error',
|
|
160
|
+
|
|
161
|
+
// 不要使用 Function 构造函数创建函数
|
|
162
|
+
'no-new-func': 'error',
|
|
163
|
+
|
|
164
|
+
// 不要使用 new Number/String/Boolean
|
|
165
|
+
'no-new-wrappers': 'error',
|
|
166
|
+
|
|
167
|
+
// 禁用八进制字面量
|
|
168
|
+
'no-octal': 'error',
|
|
169
|
+
|
|
170
|
+
// 禁止在字符串字面量中使用八进制转义序列,如 var foo = 'Copyright \251';
|
|
171
|
+
'no-octal-escape': 'error',
|
|
172
|
+
|
|
173
|
+
// 不要修改函数参数
|
|
174
|
+
'no-param-reassign': [
|
|
175
|
+
'warn',
|
|
176
|
+
{
|
|
177
|
+
props: true,
|
|
178
|
+
ignorePropertyModificationsFor: [
|
|
179
|
+
'acc', // for reduce accumulators
|
|
180
|
+
'e', // for e.returnvalue
|
|
181
|
+
'ctx', // for Koa routing
|
|
182
|
+
'draft', // for immer
|
|
183
|
+
'req', // for Express requests
|
|
184
|
+
'request', // for Express requests
|
|
185
|
+
'res', // for Express responses
|
|
186
|
+
'response', // for Express responses
|
|
187
|
+
'$scope', // for Angular 1 scopes
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
|
|
192
|
+
// 禁止使用 __proto__ 属性
|
|
193
|
+
'no-proto': 'error',
|
|
194
|
+
|
|
195
|
+
// 不要重复声明变量和函数
|
|
196
|
+
'no-redeclare': 'error',
|
|
197
|
+
|
|
198
|
+
// 禁止使用某些对象的某些属性
|
|
199
|
+
'no-restricted-properties': 'off',
|
|
200
|
+
|
|
201
|
+
// 禁止在 return 语句中赋值
|
|
202
|
+
'no-return-assign': ['error', 'always'],
|
|
203
|
+
|
|
204
|
+
// 禁止不必要的 return await
|
|
205
|
+
'no-return-await': 'off',
|
|
206
|
+
|
|
207
|
+
// 禁止使用 javascript:url,如 location.href = 'javascript:void(0)';
|
|
208
|
+
// @unessential
|
|
209
|
+
'no-script-url': 'error',
|
|
210
|
+
|
|
211
|
+
// 禁止自我赋值
|
|
212
|
+
'no-self-assign': 'error',
|
|
213
|
+
|
|
214
|
+
// 禁止自我比较
|
|
215
|
+
'no-self-compare': 'error',
|
|
216
|
+
|
|
217
|
+
// 禁止使用逗号操作符,除非用于 for 循环条件或明确用小括号包裹
|
|
218
|
+
'no-sequences': 'error',
|
|
219
|
+
|
|
220
|
+
// 不要抛出字面量异常
|
|
221
|
+
'no-throw-literal': 'warn',
|
|
222
|
+
|
|
223
|
+
// 禁用不变的循环条件
|
|
224
|
+
'no-unmodified-loop-condition': 'off',
|
|
225
|
+
|
|
226
|
+
// 禁止出现未使用的表达式
|
|
227
|
+
'no-unused-expressions': [
|
|
228
|
+
'error',
|
|
229
|
+
{
|
|
230
|
+
allowShortCircuit: true,
|
|
231
|
+
allowTernary: true,
|
|
232
|
+
allowTaggedTemplates: true,
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
|
|
236
|
+
// 禁止未使用的标签
|
|
237
|
+
'no-unused-labels': 'error',
|
|
238
|
+
|
|
239
|
+
// 禁用不必要的 .call() 和 .apply()
|
|
240
|
+
'no-useless-call': 'off',
|
|
241
|
+
|
|
242
|
+
// 禁用不必要的 catch
|
|
243
|
+
'no-useless-catch': 'error',
|
|
244
|
+
|
|
245
|
+
// 禁止不必要的字符串拼接
|
|
246
|
+
'no-useless-concat': 'error',
|
|
247
|
+
|
|
248
|
+
// 禁止不必要的转义字符
|
|
249
|
+
'no-useless-escape': 'error',
|
|
250
|
+
|
|
251
|
+
// 禁止多余的 return; 语句
|
|
252
|
+
'no-useless-return': 'error',
|
|
253
|
+
|
|
254
|
+
// 不要使用 void 运算符
|
|
255
|
+
'no-void': 'error',
|
|
256
|
+
|
|
257
|
+
// 禁止在注释中使用特定的警告术语
|
|
258
|
+
'no-warning-comments': ['off', { terms: ['todo', 'fixme'], location: 'start' }],
|
|
259
|
+
|
|
260
|
+
// 禁止使用 with
|
|
261
|
+
'no-with': 'error',
|
|
262
|
+
|
|
263
|
+
// Promise 的 reject 需要传入 Error 对象
|
|
264
|
+
'prefer-promise-reject-errors': ['warn', { allowEmptyReject: true }],
|
|
265
|
+
|
|
266
|
+
// 使用 parseInt() 方法时总是带上基数
|
|
267
|
+
radix: 'warn',
|
|
268
|
+
|
|
269
|
+
// 禁止使用不带 await 表达式的 async 函数
|
|
270
|
+
'require-await': 'off',
|
|
271
|
+
|
|
272
|
+
// 强制正则使用 u 参数
|
|
273
|
+
'require-unicode-regexp': 'off',
|
|
274
|
+
|
|
275
|
+
// 要求所有的 var 声明出现在它们所在的作用域顶部
|
|
276
|
+
'vars-on-top': 'off',
|
|
277
|
+
|
|
278
|
+
// 将立即执行函数表达式(IIFE)用小括号包裹
|
|
279
|
+
'wrap-iife': ['error', 'any', { functionPrototypeMethods: false }],
|
|
280
|
+
|
|
281
|
+
// 使用 color === 'red' 而不是 'red' === color
|
|
282
|
+
yoda: 'warn',
|
|
283
|
+
},
|
|
284
|
+
};
|