@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
package/rules/base/style.js
CHANGED
|
@@ -1,445 +1,445 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
rules: {
|
|
3
|
-
// 强制在数组开括号后和闭括号前换行
|
|
4
|
-
'array-bracket-newline': 'off',
|
|
5
|
-
|
|
6
|
-
// 方括号内部两侧无空格-数组
|
|
7
|
-
'array-bracket-spacing': ['error', 'never'],
|
|
8
|
-
|
|
9
|
-
// 强制数组元素间换行
|
|
10
|
-
'array-element-newline': 'off',
|
|
11
|
-
|
|
12
|
-
// 单行代码块的大括号内部两侧有空格
|
|
13
|
-
'block-spacing': ['error', 'always'],
|
|
14
|
-
|
|
15
|
-
// 大括号换行风格:one true brace style 风格,且单行代码块可不换行
|
|
16
|
-
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
17
|
-
|
|
18
|
-
// 使用小驼峰命名风格
|
|
19
|
-
camelcase: 'off',
|
|
20
|
-
|
|
21
|
-
// 强制或禁止对注释的第一个字母大写
|
|
22
|
-
'capitalized-comments': 'off',
|
|
23
|
-
|
|
24
|
-
// 用逗号分隔的多行结构,始终加上最后一个逗号(单行不用)
|
|
25
|
-
'comma-dangle': ['error', 'always-multiline'],
|
|
26
|
-
|
|
27
|
-
// 逗号的前面无空格,后面有空格
|
|
28
|
-
'comma-spacing': ['error', { before: false, after: true }],
|
|
29
|
-
|
|
30
|
-
// 用逗号分隔的多行结构,将逗号放到行尾
|
|
31
|
-
'comma-style': ['error', 'last'],
|
|
32
|
-
|
|
33
|
-
// 方括号内部两侧无空格-计算属性
|
|
34
|
-
'computed-property-spacing': ['error', 'never'],
|
|
35
|
-
|
|
36
|
-
// 使用一致的 this 别名
|
|
37
|
-
'consistent-this': 'off',
|
|
38
|
-
|
|
39
|
-
// 在文件末尾保留一行空行
|
|
40
|
-
'eol-last': ['warn', 'always'],
|
|
41
|
-
|
|
42
|
-
// 函数名与调用它的括号间无空格
|
|
43
|
-
'func-call-spacing': ['error', 'never'],
|
|
44
|
-
|
|
45
|
-
// 要求函数名与赋值给它们的变量名或属性名相匹配
|
|
46
|
-
'func-name-matching': [
|
|
47
|
-
'off',
|
|
48
|
-
'always',
|
|
49
|
-
{
|
|
50
|
-
includeCommonJSModuleExports: false,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
|
|
54
|
-
// 要求或禁止命名的函数表达式
|
|
55
|
-
'func-names': 'off',
|
|
56
|
-
|
|
57
|
-
// 强制只能使用函数声明或函数表达式
|
|
58
|
-
'func-style': 'off',
|
|
59
|
-
|
|
60
|
-
// 在函数的小括号内使用一致的换行风格
|
|
61
|
-
'function-paren-newline': ['error', 'consistent'],
|
|
62
|
-
|
|
63
|
-
// 禁用指定的标识符
|
|
64
|
-
'id-blacklist': 'off',
|
|
65
|
-
|
|
66
|
-
// 强制标识符的最小和最大长度
|
|
67
|
-
'id-length': 'off',
|
|
68
|
-
|
|
69
|
-
// 要求标识符匹配一个指定的正则表达式
|
|
70
|
-
'id-match': 'off',
|
|
71
|
-
|
|
72
|
-
// 隐式返回的箭头函数体不要换行
|
|
73
|
-
// @reason 同 prettier 有冲突
|
|
74
|
-
'implicit-arrow-linebreak': ['off', 'beside'],
|
|
75
|
-
|
|
76
|
-
// 使用 2 个空格缩进
|
|
77
|
-
// @unessential
|
|
78
|
-
indent: [
|
|
79
|
-
'error',
|
|
80
|
-
2,
|
|
81
|
-
{
|
|
82
|
-
SwitchCase: 1,
|
|
83
|
-
VariableDeclarator: 1,
|
|
84
|
-
outerIIFEBody: 1,
|
|
85
|
-
// MemberExpression: null,
|
|
86
|
-
FunctionDeclaration: {
|
|
87
|
-
parameters: 1,
|
|
88
|
-
body: 1,
|
|
89
|
-
},
|
|
90
|
-
FunctionExpression: {
|
|
91
|
-
parameters: 1,
|
|
92
|
-
body: 1,
|
|
93
|
-
},
|
|
94
|
-
CallExpression: {
|
|
95
|
-
arguments: 1,
|
|
96
|
-
},
|
|
97
|
-
ArrayExpression: 1,
|
|
98
|
-
ObjectExpression: 1,
|
|
99
|
-
ImportDeclaration: 1,
|
|
100
|
-
flatTernaryExpressions: false,
|
|
101
|
-
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
|
|
102
|
-
ignoredNodes: [
|
|
103
|
-
'JSXElement',
|
|
104
|
-
'JSXElement > *',
|
|
105
|
-
'JSXAttribute',
|
|
106
|
-
'JSXIdentifier',
|
|
107
|
-
'JSXNamespacedName',
|
|
108
|
-
'JSXMemberExpression',
|
|
109
|
-
'JSXSpreadAttribute',
|
|
110
|
-
'JSXExpressionContainer',
|
|
111
|
-
'JSXOpeningElement',
|
|
112
|
-
'JSXClosingElement',
|
|
113
|
-
'JSXText',
|
|
114
|
-
'JSXEmptyExpression',
|
|
115
|
-
'JSXSpreadChild',
|
|
116
|
-
],
|
|
117
|
-
ignoreComments: false,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
|
|
121
|
-
// JSX 属性使用双引号,不要使用单引号
|
|
122
|
-
// @unessential
|
|
123
|
-
'jsx-quotes': ['error', 'prefer-double'],
|
|
124
|
-
|
|
125
|
-
// 定义对象字面量时,key, value 之间有且只有一个空格
|
|
126
|
-
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
|
127
|
-
|
|
128
|
-
// 关键字前后各一个空格
|
|
129
|
-
'keyword-spacing': [
|
|
130
|
-
'error',
|
|
131
|
-
{
|
|
132
|
-
before: true,
|
|
133
|
-
after: true,
|
|
134
|
-
overrides: {
|
|
135
|
-
return: { after: true },
|
|
136
|
-
throw: { after: true },
|
|
137
|
-
case: { after: true },
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
|
|
142
|
-
// 单行注释应单独一行写在被注释对象的上方,不要追加在某条语句的后面
|
|
143
|
-
'line-comment-position': [
|
|
144
|
-
'off',
|
|
145
|
-
{
|
|
146
|
-
position: 'above',
|
|
147
|
-
ignorePattern: '',
|
|
148
|
-
applyDefaultPatterns: true,
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
|
|
152
|
-
// 指定 unix 或 windows 风格的换行符
|
|
153
|
-
'linebreak-style': 'off',
|
|
154
|
-
|
|
155
|
-
// 类成员之间保留一个空行
|
|
156
|
-
'lines-between-class-members': ['off', 'always', { exceptAfterSingleLine: false }],
|
|
157
|
-
|
|
158
|
-
// 要求在注释周围有空行
|
|
159
|
-
'lines-around-comment': 'off',
|
|
160
|
-
|
|
161
|
-
// 控制语句的嵌套层级不要过深,不要超过 4 级
|
|
162
|
-
// @reason 适合做后置检查
|
|
163
|
-
'max-depth': ['off', 4],
|
|
164
|
-
|
|
165
|
-
// 单行最大字符数:100
|
|
166
|
-
'max-len': [
|
|
167
|
-
'warn',
|
|
168
|
-
100,
|
|
169
|
-
2,
|
|
170
|
-
{
|
|
171
|
-
ignoreUrls: true,
|
|
172
|
-
ignoreComments: false,
|
|
173
|
-
ignoreRegExpLiterals: true,
|
|
174
|
-
ignoreStrings: true,
|
|
175
|
-
ignoreTemplateLiterals: true,
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
|
|
179
|
-
// 文件最大行数:1000
|
|
180
|
-
// @reason 适合做后置检查
|
|
181
|
-
'max-lines': [
|
|
182
|
-
'off',
|
|
183
|
-
{
|
|
184
|
-
max: 1000,
|
|
185
|
-
skipBlankLines: true,
|
|
186
|
-
skipComments: true,
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
|
|
190
|
-
// 函数最大行数:80
|
|
191
|
-
// @reason 适合做后置检查
|
|
192
|
-
'max-lines-per-function': [
|
|
193
|
-
'off',
|
|
194
|
-
{
|
|
195
|
-
max: 80,
|
|
196
|
-
skipBlankLines: true,
|
|
197
|
-
skipComments: true,
|
|
198
|
-
IIFEs: true,
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
|
|
202
|
-
// 回调函数最大嵌套深度
|
|
203
|
-
'max-nested-callbacks': 'off',
|
|
204
|
-
|
|
205
|
-
// 函数参数数量上限
|
|
206
|
-
'max-params': ['off', 3],
|
|
207
|
-
|
|
208
|
-
// 函数块最多允许的的语句数量
|
|
209
|
-
'max-statements': ['off', 10],
|
|
210
|
-
|
|
211
|
-
// 每一行中所允许的最大语句数量
|
|
212
|
-
'max-statements-per-line': ['off', { max: 1 }],
|
|
213
|
-
|
|
214
|
-
// 多行注释的风格
|
|
215
|
-
'multiline-comment-style': ['off', 'starred-block'],
|
|
216
|
-
|
|
217
|
-
// 要求或禁止在三元操作数中间换行
|
|
218
|
-
'multiline-ternary': ['off', 'never'],
|
|
219
|
-
|
|
220
|
-
// 使用大驼峰风格命名类和构造函数
|
|
221
|
-
'new-cap': [
|
|
222
|
-
'error',
|
|
223
|
-
{
|
|
224
|
-
newIsCap: true,
|
|
225
|
-
newIsCapExceptions: [],
|
|
226
|
-
capIsNew: false,
|
|
227
|
-
capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
|
|
228
|
-
},
|
|
229
|
-
],
|
|
230
|
-
|
|
231
|
-
// 禁止在调用构造函数时省略小括号
|
|
232
|
-
'new-parens': 'error',
|
|
233
|
-
|
|
234
|
-
// 在长方法链式调用时进行换行
|
|
235
|
-
'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 4 }],
|
|
236
|
-
|
|
237
|
-
// 不要使用 new Array() 和 Array() 创建数组,除非为了构造某一长度的空数组。
|
|
238
|
-
'no-array-constructor': 'error',
|
|
239
|
-
|
|
240
|
-
// 不要使用按位操作符
|
|
241
|
-
'no-bitwise': 'warn',
|
|
242
|
-
|
|
243
|
-
// 禁用 continue 语句
|
|
244
|
-
'no-continue': 'off',
|
|
245
|
-
|
|
246
|
-
// 禁止行内注释
|
|
247
|
-
'no-inline-comments': 'off',
|
|
248
|
-
|
|
249
|
-
// 禁止 if 作为唯一语句出现在 else 中,此时应写成 else if
|
|
250
|
-
'no-lonely-if': 'error',
|
|
251
|
-
|
|
252
|
-
// 混合使用多种操作符时,用小括号包裹分组
|
|
253
|
-
'no-mixed-operators': [
|
|
254
|
-
'error',
|
|
255
|
-
{
|
|
256
|
-
groups: [
|
|
257
|
-
['%', '**'],
|
|
258
|
-
['%', '+'],
|
|
259
|
-
['%', '-'],
|
|
260
|
-
['%', '*'],
|
|
261
|
-
['%', '/'],
|
|
262
|
-
['**', '+'],
|
|
263
|
-
['**', '-'],
|
|
264
|
-
['**', '*'],
|
|
265
|
-
['**', '/'],
|
|
266
|
-
['&', '|', '^', '~', '<<', '>>', '>>>'],
|
|
267
|
-
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
|
268
|
-
['&&', '||'],
|
|
269
|
-
['in', 'instanceof'],
|
|
270
|
-
],
|
|
271
|
-
allowSamePrecedence: false,
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
|
|
275
|
-
// 不要混用空格和 tab
|
|
276
|
-
'no-mixed-spaces-and-tabs': 'error',
|
|
277
|
-
|
|
278
|
-
// 禁止连续赋值
|
|
279
|
-
'no-multi-assign': ['error'],
|
|
280
|
-
|
|
281
|
-
// 禁止出现多个(大于 2 个)连续空行
|
|
282
|
-
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
|
283
|
-
|
|
284
|
-
// 禁用否定的表达式
|
|
285
|
-
'no-negated-condition': 'off',
|
|
286
|
-
|
|
287
|
-
// 不要使用嵌套的三元表达式
|
|
288
|
-
'no-nested-ternary': 'error',
|
|
289
|
-
|
|
290
|
-
// 使用字面量创建对象
|
|
291
|
-
'no-new-object': 'error',
|
|
292
|
-
|
|
293
|
-
// 不要使用一元自增自减运算符
|
|
294
|
-
'no-plusplus': ['off', { allowForLoopAfterthoughts: true }],
|
|
295
|
-
|
|
296
|
-
// 禁用特定的语法
|
|
297
|
-
'no-restricted-syntax': 'off',
|
|
298
|
-
|
|
299
|
-
// 禁止使用 tab
|
|
300
|
-
'no-tabs': 'error',
|
|
301
|
-
|
|
302
|
-
// 禁用三元操作符
|
|
303
|
-
'no-ternary': 'off',
|
|
304
|
-
|
|
305
|
-
// 行尾不要留有空格
|
|
306
|
-
'no-trailing-spaces': [
|
|
307
|
-
'error',
|
|
308
|
-
{
|
|
309
|
-
skipBlankLines: false,
|
|
310
|
-
ignoreComments: false,
|
|
311
|
-
},
|
|
312
|
-
],
|
|
313
|
-
|
|
314
|
-
// 命名不要以下划线开头或结尾
|
|
315
|
-
'no-underscore-dangle': 'off',
|
|
316
|
-
|
|
317
|
-
// 避免不必要的三元表达式
|
|
318
|
-
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
|
|
319
|
-
|
|
320
|
-
// 禁止属性调用前有空格
|
|
321
|
-
'no-whitespace-before-property': 'error',
|
|
322
|
-
|
|
323
|
-
// 省略大括号的单行语句前不要换行
|
|
324
|
-
'nonblock-statement-body-position': ['error', 'beside', { overrides: {} }],
|
|
325
|
-
|
|
326
|
-
// 强制大括号内换行符的一致性
|
|
327
|
-
'object-curly-newline': 'off',
|
|
328
|
-
|
|
329
|
-
// 大括号内部两侧有空格
|
|
330
|
-
'object-curly-spacing': ['error', 'always'],
|
|
331
|
-
|
|
332
|
-
// 对象的属性需遵循一致的换行风格:即所有属性要么都换行,要么都写在一行
|
|
333
|
-
'object-property-newline': [
|
|
334
|
-
'error',
|
|
335
|
-
{
|
|
336
|
-
allowAllPropertiesOnSameLine: true,
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
|
|
340
|
-
// 一条声明语句声明一个变量
|
|
341
|
-
'one-var': ['error', 'never'],
|
|
342
|
-
|
|
343
|
-
// 一行声明一个变量
|
|
344
|
-
'one-var-declaration-per-line': ['error', 'always'],
|
|
345
|
-
|
|
346
|
-
// 尽可能使用简写形式的赋值操作符
|
|
347
|
-
'operator-assignment': ['warn', 'always'],
|
|
348
|
-
|
|
349
|
-
// 强制操作符使用一致的换行符
|
|
350
|
-
'operator-linebreak': 'off',
|
|
351
|
-
|
|
352
|
-
// 块的开始和结束不能是空行
|
|
353
|
-
'padded-blocks': ['warn', { blocks: 'never', classes: 'never', switches: 'never' }],
|
|
354
|
-
|
|
355
|
-
// 要求或禁止在语句间填充空行
|
|
356
|
-
'padding-line-between-statements': 'off',
|
|
357
|
-
|
|
358
|
-
// 使用扩展运算符替代 Object.assign
|
|
359
|
-
'prefer-object-spread': 'off',
|
|
360
|
-
|
|
361
|
-
// 对象字面量的属性名不要用引号包裹,除非包含特殊字符
|
|
362
|
-
'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }],
|
|
363
|
-
|
|
364
|
-
// 字符串优先使用单引号
|
|
365
|
-
quotes: ['error', 'single', { avoidEscape: true }],
|
|
366
|
-
|
|
367
|
-
// 使用 JSDoc 注释
|
|
368
|
-
'require-jsdoc': 'off',
|
|
369
|
-
|
|
370
|
-
// 使用分号
|
|
371
|
-
// @unessential
|
|
372
|
-
semi: ['error', 'always'],
|
|
373
|
-
|
|
374
|
-
// 分号的前面无空格,后面有空格
|
|
375
|
-
'semi-spacing': ['error', { before: false, after: true }],
|
|
376
|
-
|
|
377
|
-
// 分号必须写在行尾
|
|
378
|
-
// @unessential
|
|
379
|
-
'semi-style': ['error', 'last'],
|
|
380
|
-
|
|
381
|
-
// 要求对对象属性名排序
|
|
382
|
-
'sort-keys': ['off', 'asc', { caseSensitive: false, natural: true }],
|
|
383
|
-
|
|
384
|
-
// 要求对变量声明排序
|
|
385
|
-
'sort-vars': 'off',
|
|
386
|
-
|
|
387
|
-
// 块的左大括号前有一个空格
|
|
388
|
-
'space-before-blocks': 'error',
|
|
389
|
-
|
|
390
|
-
// 函数声明时,对于命名函数,参数的小括号前无空格;对于匿名函数和 async 箭头函数,参数的小括号前有空格
|
|
391
|
-
'space-before-function-paren': [
|
|
392
|
-
'error',
|
|
393
|
-
{
|
|
394
|
-
anonymous: 'always',
|
|
395
|
-
named: 'never',
|
|
396
|
-
asyncArrow: 'always',
|
|
397
|
-
},
|
|
398
|
-
],
|
|
399
|
-
|
|
400
|
-
// 小括号内部两侧无空格
|
|
401
|
-
'space-in-parens': ['error', 'never'],
|
|
402
|
-
|
|
403
|
-
// 中缀操作符两侧有空格
|
|
404
|
-
'space-infix-ops': 'error',
|
|
405
|
-
|
|
406
|
-
// 一元操作符两侧无空格,包括 -、+、--、++、!、!!
|
|
407
|
-
'space-unary-ops': [
|
|
408
|
-
'error',
|
|
409
|
-
{
|
|
410
|
-
words: true,
|
|
411
|
-
nonwords: false,
|
|
412
|
-
overrides: {},
|
|
413
|
-
},
|
|
414
|
-
],
|
|
415
|
-
|
|
416
|
-
// 注释内容和注释符之间需留有一个空格
|
|
417
|
-
'spaced-comment': [
|
|
418
|
-
'error',
|
|
419
|
-
'always',
|
|
420
|
-
{
|
|
421
|
-
line: {
|
|
422
|
-
exceptions: ['-', '+'],
|
|
423
|
-
markers: ['=', '!', '/'],
|
|
424
|
-
},
|
|
425
|
-
block: {
|
|
426
|
-
exceptions: ['-', '+'],
|
|
427
|
-
markers: ['=', '!'],
|
|
428
|
-
balanced: true,
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
],
|
|
432
|
-
|
|
433
|
-
// switch 的 case 和 default 子句冒号前面无空格,后面有空格
|
|
434
|
-
'switch-colon-spacing': ['error', { after: true, before: false }],
|
|
435
|
-
|
|
436
|
-
// 模板字符串的 tag 后面无空格
|
|
437
|
-
'template-tag-spacing': ['error', 'never'],
|
|
438
|
-
|
|
439
|
-
// 要求或禁止 Unicode 字节顺序标记 (BOM)
|
|
440
|
-
'unicode-bom': ['off', 'never'],
|
|
441
|
-
|
|
442
|
-
// 要求正则表达式被括号括起来
|
|
443
|
-
'wrap-regex': 'off',
|
|
444
|
-
},
|
|
445
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
rules: {
|
|
3
|
+
// 强制在数组开括号后和闭括号前换行
|
|
4
|
+
'array-bracket-newline': 'off',
|
|
5
|
+
|
|
6
|
+
// 方括号内部两侧无空格-数组
|
|
7
|
+
'array-bracket-spacing': ['error', 'never'],
|
|
8
|
+
|
|
9
|
+
// 强制数组元素间换行
|
|
10
|
+
'array-element-newline': 'off',
|
|
11
|
+
|
|
12
|
+
// 单行代码块的大括号内部两侧有空格
|
|
13
|
+
'block-spacing': ['error', 'always'],
|
|
14
|
+
|
|
15
|
+
// 大括号换行风格:one true brace style 风格,且单行代码块可不换行
|
|
16
|
+
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
|
17
|
+
|
|
18
|
+
// 使用小驼峰命名风格
|
|
19
|
+
camelcase: 'off',
|
|
20
|
+
|
|
21
|
+
// 强制或禁止对注释的第一个字母大写
|
|
22
|
+
'capitalized-comments': 'off',
|
|
23
|
+
|
|
24
|
+
// 用逗号分隔的多行结构,始终加上最后一个逗号(单行不用)
|
|
25
|
+
'comma-dangle': ['error', 'always-multiline'],
|
|
26
|
+
|
|
27
|
+
// 逗号的前面无空格,后面有空格
|
|
28
|
+
'comma-spacing': ['error', { before: false, after: true }],
|
|
29
|
+
|
|
30
|
+
// 用逗号分隔的多行结构,将逗号放到行尾
|
|
31
|
+
'comma-style': ['error', 'last'],
|
|
32
|
+
|
|
33
|
+
// 方括号内部两侧无空格-计算属性
|
|
34
|
+
'computed-property-spacing': ['error', 'never'],
|
|
35
|
+
|
|
36
|
+
// 使用一致的 this 别名
|
|
37
|
+
'consistent-this': 'off',
|
|
38
|
+
|
|
39
|
+
// 在文件末尾保留一行空行
|
|
40
|
+
'eol-last': ['warn', 'always'],
|
|
41
|
+
|
|
42
|
+
// 函数名与调用它的括号间无空格
|
|
43
|
+
'func-call-spacing': ['error', 'never'],
|
|
44
|
+
|
|
45
|
+
// 要求函数名与赋值给它们的变量名或属性名相匹配
|
|
46
|
+
'func-name-matching': [
|
|
47
|
+
'off',
|
|
48
|
+
'always',
|
|
49
|
+
{
|
|
50
|
+
includeCommonJSModuleExports: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
|
|
54
|
+
// 要求或禁止命名的函数表达式
|
|
55
|
+
'func-names': 'off',
|
|
56
|
+
|
|
57
|
+
// 强制只能使用函数声明或函数表达式
|
|
58
|
+
'func-style': 'off',
|
|
59
|
+
|
|
60
|
+
// 在函数的小括号内使用一致的换行风格
|
|
61
|
+
'function-paren-newline': ['error', 'consistent'],
|
|
62
|
+
|
|
63
|
+
// 禁用指定的标识符
|
|
64
|
+
'id-blacklist': 'off',
|
|
65
|
+
|
|
66
|
+
// 强制标识符的最小和最大长度
|
|
67
|
+
'id-length': 'off',
|
|
68
|
+
|
|
69
|
+
// 要求标识符匹配一个指定的正则表达式
|
|
70
|
+
'id-match': 'off',
|
|
71
|
+
|
|
72
|
+
// 隐式返回的箭头函数体不要换行
|
|
73
|
+
// @reason 同 prettier 有冲突
|
|
74
|
+
'implicit-arrow-linebreak': ['off', 'beside'],
|
|
75
|
+
|
|
76
|
+
// 使用 2 个空格缩进
|
|
77
|
+
// @unessential
|
|
78
|
+
indent: [
|
|
79
|
+
'error',
|
|
80
|
+
2,
|
|
81
|
+
{
|
|
82
|
+
SwitchCase: 1,
|
|
83
|
+
VariableDeclarator: 1,
|
|
84
|
+
outerIIFEBody: 1,
|
|
85
|
+
// MemberExpression: null,
|
|
86
|
+
FunctionDeclaration: {
|
|
87
|
+
parameters: 1,
|
|
88
|
+
body: 1,
|
|
89
|
+
},
|
|
90
|
+
FunctionExpression: {
|
|
91
|
+
parameters: 1,
|
|
92
|
+
body: 1,
|
|
93
|
+
},
|
|
94
|
+
CallExpression: {
|
|
95
|
+
arguments: 1,
|
|
96
|
+
},
|
|
97
|
+
ArrayExpression: 1,
|
|
98
|
+
ObjectExpression: 1,
|
|
99
|
+
ImportDeclaration: 1,
|
|
100
|
+
flatTernaryExpressions: false,
|
|
101
|
+
// list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
|
|
102
|
+
ignoredNodes: [
|
|
103
|
+
'JSXElement',
|
|
104
|
+
'JSXElement > *',
|
|
105
|
+
'JSXAttribute',
|
|
106
|
+
'JSXIdentifier',
|
|
107
|
+
'JSXNamespacedName',
|
|
108
|
+
'JSXMemberExpression',
|
|
109
|
+
'JSXSpreadAttribute',
|
|
110
|
+
'JSXExpressionContainer',
|
|
111
|
+
'JSXOpeningElement',
|
|
112
|
+
'JSXClosingElement',
|
|
113
|
+
'JSXText',
|
|
114
|
+
'JSXEmptyExpression',
|
|
115
|
+
'JSXSpreadChild',
|
|
116
|
+
],
|
|
117
|
+
ignoreComments: false,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
|
|
121
|
+
// JSX 属性使用双引号,不要使用单引号
|
|
122
|
+
// @unessential
|
|
123
|
+
'jsx-quotes': ['error', 'prefer-double'],
|
|
124
|
+
|
|
125
|
+
// 定义对象字面量时,key, value 之间有且只有一个空格
|
|
126
|
+
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
|
|
127
|
+
|
|
128
|
+
// 关键字前后各一个空格
|
|
129
|
+
'keyword-spacing': [
|
|
130
|
+
'error',
|
|
131
|
+
{
|
|
132
|
+
before: true,
|
|
133
|
+
after: true,
|
|
134
|
+
overrides: {
|
|
135
|
+
return: { after: true },
|
|
136
|
+
throw: { after: true },
|
|
137
|
+
case: { after: true },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
|
|
142
|
+
// 单行注释应单独一行写在被注释对象的上方,不要追加在某条语句的后面
|
|
143
|
+
'line-comment-position': [
|
|
144
|
+
'off',
|
|
145
|
+
{
|
|
146
|
+
position: 'above',
|
|
147
|
+
ignorePattern: '',
|
|
148
|
+
applyDefaultPatterns: true,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
|
|
152
|
+
// 指定 unix 或 windows 风格的换行符
|
|
153
|
+
'linebreak-style': 'off',
|
|
154
|
+
|
|
155
|
+
// 类成员之间保留一个空行
|
|
156
|
+
'lines-between-class-members': ['off', 'always', { exceptAfterSingleLine: false }],
|
|
157
|
+
|
|
158
|
+
// 要求在注释周围有空行
|
|
159
|
+
'lines-around-comment': 'off',
|
|
160
|
+
|
|
161
|
+
// 控制语句的嵌套层级不要过深,不要超过 4 级
|
|
162
|
+
// @reason 适合做后置检查
|
|
163
|
+
'max-depth': ['off', 4],
|
|
164
|
+
|
|
165
|
+
// 单行最大字符数:100
|
|
166
|
+
'max-len': [
|
|
167
|
+
'warn',
|
|
168
|
+
100,
|
|
169
|
+
2,
|
|
170
|
+
{
|
|
171
|
+
ignoreUrls: true,
|
|
172
|
+
ignoreComments: false,
|
|
173
|
+
ignoreRegExpLiterals: true,
|
|
174
|
+
ignoreStrings: true,
|
|
175
|
+
ignoreTemplateLiterals: true,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
|
|
179
|
+
// 文件最大行数:1000
|
|
180
|
+
// @reason 适合做后置检查
|
|
181
|
+
'max-lines': [
|
|
182
|
+
'off',
|
|
183
|
+
{
|
|
184
|
+
max: 1000,
|
|
185
|
+
skipBlankLines: true,
|
|
186
|
+
skipComments: true,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
|
|
190
|
+
// 函数最大行数:80
|
|
191
|
+
// @reason 适合做后置检查
|
|
192
|
+
'max-lines-per-function': [
|
|
193
|
+
'off',
|
|
194
|
+
{
|
|
195
|
+
max: 80,
|
|
196
|
+
skipBlankLines: true,
|
|
197
|
+
skipComments: true,
|
|
198
|
+
IIFEs: true,
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
|
|
202
|
+
// 回调函数最大嵌套深度
|
|
203
|
+
'max-nested-callbacks': 'off',
|
|
204
|
+
|
|
205
|
+
// 函数参数数量上限
|
|
206
|
+
'max-params': ['off', 3],
|
|
207
|
+
|
|
208
|
+
// 函数块最多允许的的语句数量
|
|
209
|
+
'max-statements': ['off', 10],
|
|
210
|
+
|
|
211
|
+
// 每一行中所允许的最大语句数量
|
|
212
|
+
'max-statements-per-line': ['off', { max: 1 }],
|
|
213
|
+
|
|
214
|
+
// 多行注释的风格
|
|
215
|
+
'multiline-comment-style': ['off', 'starred-block'],
|
|
216
|
+
|
|
217
|
+
// 要求或禁止在三元操作数中间换行
|
|
218
|
+
'multiline-ternary': ['off', 'never'],
|
|
219
|
+
|
|
220
|
+
// 使用大驼峰风格命名类和构造函数
|
|
221
|
+
'new-cap': [
|
|
222
|
+
'error',
|
|
223
|
+
{
|
|
224
|
+
newIsCap: true,
|
|
225
|
+
newIsCapExceptions: [],
|
|
226
|
+
capIsNew: false,
|
|
227
|
+
capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
|
|
231
|
+
// 禁止在调用构造函数时省略小括号
|
|
232
|
+
'new-parens': 'error',
|
|
233
|
+
|
|
234
|
+
// 在长方法链式调用时进行换行
|
|
235
|
+
'newline-per-chained-call': ['warn', { ignoreChainWithDepth: 4 }],
|
|
236
|
+
|
|
237
|
+
// 不要使用 new Array() 和 Array() 创建数组,除非为了构造某一长度的空数组。
|
|
238
|
+
'no-array-constructor': 'error',
|
|
239
|
+
|
|
240
|
+
// 不要使用按位操作符
|
|
241
|
+
'no-bitwise': 'warn',
|
|
242
|
+
|
|
243
|
+
// 禁用 continue 语句
|
|
244
|
+
'no-continue': 'off',
|
|
245
|
+
|
|
246
|
+
// 禁止行内注释
|
|
247
|
+
'no-inline-comments': 'off',
|
|
248
|
+
|
|
249
|
+
// 禁止 if 作为唯一语句出现在 else 中,此时应写成 else if
|
|
250
|
+
'no-lonely-if': 'error',
|
|
251
|
+
|
|
252
|
+
// 混合使用多种操作符时,用小括号包裹分组
|
|
253
|
+
'no-mixed-operators': [
|
|
254
|
+
'error',
|
|
255
|
+
{
|
|
256
|
+
groups: [
|
|
257
|
+
['%', '**'],
|
|
258
|
+
['%', '+'],
|
|
259
|
+
['%', '-'],
|
|
260
|
+
['%', '*'],
|
|
261
|
+
['%', '/'],
|
|
262
|
+
['**', '+'],
|
|
263
|
+
['**', '-'],
|
|
264
|
+
['**', '*'],
|
|
265
|
+
['**', '/'],
|
|
266
|
+
['&', '|', '^', '~', '<<', '>>', '>>>'],
|
|
267
|
+
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
|
|
268
|
+
['&&', '||'],
|
|
269
|
+
['in', 'instanceof'],
|
|
270
|
+
],
|
|
271
|
+
allowSamePrecedence: false,
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
|
|
275
|
+
// 不要混用空格和 tab
|
|
276
|
+
'no-mixed-spaces-and-tabs': 'error',
|
|
277
|
+
|
|
278
|
+
// 禁止连续赋值
|
|
279
|
+
'no-multi-assign': ['error'],
|
|
280
|
+
|
|
281
|
+
// 禁止出现多个(大于 2 个)连续空行
|
|
282
|
+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }],
|
|
283
|
+
|
|
284
|
+
// 禁用否定的表达式
|
|
285
|
+
'no-negated-condition': 'off',
|
|
286
|
+
|
|
287
|
+
// 不要使用嵌套的三元表达式
|
|
288
|
+
'no-nested-ternary': 'error',
|
|
289
|
+
|
|
290
|
+
// 使用字面量创建对象
|
|
291
|
+
'no-new-object': 'error',
|
|
292
|
+
|
|
293
|
+
// 不要使用一元自增自减运算符
|
|
294
|
+
'no-plusplus': ['off', { allowForLoopAfterthoughts: true }],
|
|
295
|
+
|
|
296
|
+
// 禁用特定的语法
|
|
297
|
+
'no-restricted-syntax': 'off',
|
|
298
|
+
|
|
299
|
+
// 禁止使用 tab
|
|
300
|
+
'no-tabs': 'error',
|
|
301
|
+
|
|
302
|
+
// 禁用三元操作符
|
|
303
|
+
'no-ternary': 'off',
|
|
304
|
+
|
|
305
|
+
// 行尾不要留有空格
|
|
306
|
+
'no-trailing-spaces': [
|
|
307
|
+
'error',
|
|
308
|
+
{
|
|
309
|
+
skipBlankLines: false,
|
|
310
|
+
ignoreComments: false,
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
|
|
314
|
+
// 命名不要以下划线开头或结尾
|
|
315
|
+
'no-underscore-dangle': 'off',
|
|
316
|
+
|
|
317
|
+
// 避免不必要的三元表达式
|
|
318
|
+
'no-unneeded-ternary': ['error', { defaultAssignment: false }],
|
|
319
|
+
|
|
320
|
+
// 禁止属性调用前有空格
|
|
321
|
+
'no-whitespace-before-property': 'error',
|
|
322
|
+
|
|
323
|
+
// 省略大括号的单行语句前不要换行
|
|
324
|
+
'nonblock-statement-body-position': ['error', 'beside', { overrides: {} }],
|
|
325
|
+
|
|
326
|
+
// 强制大括号内换行符的一致性
|
|
327
|
+
'object-curly-newline': 'off',
|
|
328
|
+
|
|
329
|
+
// 大括号内部两侧有空格
|
|
330
|
+
'object-curly-spacing': ['error', 'always'],
|
|
331
|
+
|
|
332
|
+
// 对象的属性需遵循一致的换行风格:即所有属性要么都换行,要么都写在一行
|
|
333
|
+
'object-property-newline': [
|
|
334
|
+
'error',
|
|
335
|
+
{
|
|
336
|
+
allowAllPropertiesOnSameLine: true,
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
|
|
340
|
+
// 一条声明语句声明一个变量
|
|
341
|
+
'one-var': ['error', 'never'],
|
|
342
|
+
|
|
343
|
+
// 一行声明一个变量
|
|
344
|
+
'one-var-declaration-per-line': ['error', 'always'],
|
|
345
|
+
|
|
346
|
+
// 尽可能使用简写形式的赋值操作符
|
|
347
|
+
'operator-assignment': ['warn', 'always'],
|
|
348
|
+
|
|
349
|
+
// 强制操作符使用一致的换行符
|
|
350
|
+
'operator-linebreak': 'off',
|
|
351
|
+
|
|
352
|
+
// 块的开始和结束不能是空行
|
|
353
|
+
'padded-blocks': ['warn', { blocks: 'never', classes: 'never', switches: 'never' }],
|
|
354
|
+
|
|
355
|
+
// 要求或禁止在语句间填充空行
|
|
356
|
+
'padding-line-between-statements': 'off',
|
|
357
|
+
|
|
358
|
+
// 使用扩展运算符替代 Object.assign
|
|
359
|
+
'prefer-object-spread': 'off',
|
|
360
|
+
|
|
361
|
+
// 对象字面量的属性名不要用引号包裹,除非包含特殊字符
|
|
362
|
+
'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }],
|
|
363
|
+
|
|
364
|
+
// 字符串优先使用单引号
|
|
365
|
+
quotes: ['error', 'single', { avoidEscape: true }],
|
|
366
|
+
|
|
367
|
+
// 使用 JSDoc 注释
|
|
368
|
+
'require-jsdoc': 'off',
|
|
369
|
+
|
|
370
|
+
// 使用分号
|
|
371
|
+
// @unessential
|
|
372
|
+
semi: ['error', 'always'],
|
|
373
|
+
|
|
374
|
+
// 分号的前面无空格,后面有空格
|
|
375
|
+
'semi-spacing': ['error', { before: false, after: true }],
|
|
376
|
+
|
|
377
|
+
// 分号必须写在行尾
|
|
378
|
+
// @unessential
|
|
379
|
+
'semi-style': ['error', 'last'],
|
|
380
|
+
|
|
381
|
+
// 要求对对象属性名排序
|
|
382
|
+
'sort-keys': ['off', 'asc', { caseSensitive: false, natural: true }],
|
|
383
|
+
|
|
384
|
+
// 要求对变量声明排序
|
|
385
|
+
'sort-vars': 'off',
|
|
386
|
+
|
|
387
|
+
// 块的左大括号前有一个空格
|
|
388
|
+
'space-before-blocks': 'error',
|
|
389
|
+
|
|
390
|
+
// 函数声明时,对于命名函数,参数的小括号前无空格;对于匿名函数和 async 箭头函数,参数的小括号前有空格
|
|
391
|
+
'space-before-function-paren': [
|
|
392
|
+
'error',
|
|
393
|
+
{
|
|
394
|
+
anonymous: 'always',
|
|
395
|
+
named: 'never',
|
|
396
|
+
asyncArrow: 'always',
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
|
|
400
|
+
// 小括号内部两侧无空格
|
|
401
|
+
'space-in-parens': ['error', 'never'],
|
|
402
|
+
|
|
403
|
+
// 中缀操作符两侧有空格
|
|
404
|
+
'space-infix-ops': 'error',
|
|
405
|
+
|
|
406
|
+
// 一元操作符两侧无空格,包括 -、+、--、++、!、!!
|
|
407
|
+
'space-unary-ops': [
|
|
408
|
+
'error',
|
|
409
|
+
{
|
|
410
|
+
words: true,
|
|
411
|
+
nonwords: false,
|
|
412
|
+
overrides: {},
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
|
|
416
|
+
// 注释内容和注释符之间需留有一个空格
|
|
417
|
+
'spaced-comment': [
|
|
418
|
+
'error',
|
|
419
|
+
'always',
|
|
420
|
+
{
|
|
421
|
+
line: {
|
|
422
|
+
exceptions: ['-', '+'],
|
|
423
|
+
markers: ['=', '!', '/'],
|
|
424
|
+
},
|
|
425
|
+
block: {
|
|
426
|
+
exceptions: ['-', '+'],
|
|
427
|
+
markers: ['=', '!'],
|
|
428
|
+
balanced: true,
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
|
|
433
|
+
// switch 的 case 和 default 子句冒号前面无空格,后面有空格
|
|
434
|
+
'switch-colon-spacing': ['error', { after: true, before: false }],
|
|
435
|
+
|
|
436
|
+
// 模板字符串的 tag 后面无空格
|
|
437
|
+
'template-tag-spacing': ['error', 'never'],
|
|
438
|
+
|
|
439
|
+
// 要求或禁止 Unicode 字节顺序标记 (BOM)
|
|
440
|
+
'unicode-bom': ['off', 'never'],
|
|
441
|
+
|
|
442
|
+
// 要求正则表达式被括号括起来
|
|
443
|
+
'wrap-regex': 'off',
|
|
444
|
+
},
|
|
445
|
+
};
|