-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.eslintrc.js
150 lines (147 loc) · 5.36 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* 自定义的ESLint配置项
* 规则中文 @see http://eslint.cn/docs/user-guide/configuring
* 规则英文 @see https://eslint.org/docs/user-guide/configuring
*
* 使用注释自定义规则 @see https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments
*/
module.exports = {
// 以此规则集为基础
extends: [
// 规则解释 @see https://alloyteam.github.io/eslint-config-alloy/
// 默认规则 @see https://github.com/AlloyTeam/eslint-config-alloy/blob/master/index.js
'eslint-config-alloy',
// 默认规则 @see https://github.com/AlloyTeam/eslint-config-alloy/blob/master/react.js
'eslint-config-alloy/react'
],
// 检查html文件(或tpl文件)中的JS
plugins: [
'html'
],
settings: {
'html/html-extensions': ['.html', '.tpl'],
// 'html/indent': '+4'
},
// 定义一些初始的全局可用变量
globals: {
jQuery: false,
$: false,
layer: false,
Handlebars: false,
Bloodhound: false
},
// parserOptions: {
// ecmaFeatures: {
// jsx: true
// }
// },
// 自定义的规则
rules: {
// 必须使用 === 或 !==,禁止使用 == 或 !=,与 null 比较时除外
// @warn 在异步接口返回时不确定参数是数值还是字符串,有时可利用这个类型转换
'eqeqeq': 'warn',
// 禁止在 if 代码块内出现函数声明
// @off 在for循环中会经常使用定义var for(var i = 0; i < 10; ++i)
'no-inner-declarations': 'off',
// switch 的 case 内有变量定义的时候,必须使用大括号将 case 内变成一个代码块
// @off 太严格
'no-case-declarations': 'off',
// 禁止使用 !! ~ 等难以理解的运算符
// @off 有些时候会用到 if (!!abc) '' + 100 +new Date() 等
'no-implicit-coercion': 'off',
// 禁止在全局作用域下定义变量或申明函数
// @off 太严格
'no-implicit-globals': 'off',
// 禁止使用没必要的 {} 作为代码块
// @off 有时候需要用代码块做逻辑区分
'no-lone-blocks': 'off',
// 禁止出现 location.href = 'javascript:void(0)';
// @off 有时候需要用便捷的 javascript:;
'no-script-url': 'off',
// 对象字面量只有一行时,大括号内的首尾必须有空格
// @off 没有必要限制
'object-curly-spacing': 'off',
// 禁止对函数的参数重新赋值
// @warn 警示即可
'no-param-reassign': 'warn',
// 文件最后一行必须有一个空行
// @error 应该在文件末尾保持一个换行
'eol-last': 'error',
// 代码块嵌套的深度禁止超过 10 层
// @warn 有些特殊情况会出现 警示即可
'max-depth': [
'warn',
10
],
// 禁止函数的循环复杂度超过 100
// @error 最大值可以宽松点
'complexity': [
'error',
{
max: 100
}
],
// 定义过的变量必须使用
// @warn 多文件互相引用时 偶尔会出现无引用的情况
'no-unused-vars': [
'warn',
{
vars: 'all',
args: 'none',
caughtErrors: 'none',
ignoreRestSiblings: true
}
],
// 在ES5中需使用var
// @off 没有必要限制
'no-var': 'off',
// 禁止使用未定义的变量 建议将相关变量在上方 globals 配置项中配置
// @warn 警示即可
'no-undef': 'warn',
// 函数的参数禁止超过10个
// @warn 警示即可
'max-params': ['warn', 10],
// 回调函数嵌套禁止超过 5 层
// @warn 警示即可
'max-nested-callbacks': ['warn', 5],
// 循环内的函数中不能出现循环体条件语句中定义的变量
// @warn 警示即可
'no-loop-func': 'warn',
// Promise 的 reject 中必须传入 Error 对象
// @off 不需要限制
'prefer-promise-reject-errors': 'off',
// 变量声明时尽量使用一个var声明连续的多个
// @warn 警示即可
'one-var': [
'error',
'consecutive'
],
// 变量申明必须每行一个
// @error 赋值时保证处于一行即可
'one-var-declaration-per-line': [
'error',
'initializations'
],
// 禁止使用已废弃的 api
// @off 不需要限制
'react/no-deprecated': 'off',
// 禁止使用字符串 ref
// @warn 警告即可
'react/no-string-refs': 'warn',
// 必须使用 Class 的形式创建组件
// @warn 警告即可
'react/prefer-es6-class': [
'warn',
'always'
],
// 禁止在 componentDidUpdate 里面使用 setState
// @warn 警告即可
'react/no-did-update-set-state': 'warn',
// 组件内方法必须按照一定规则排序
// @off 不需要限制
'react/sort-comp': 'off',
// jsx 的 props 缩进必须为四个空格
// @off 不需要限制
// 'react/jsx-indent-props': 'off',
}
};