-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eslintrc.json
More file actions
288 lines (287 loc) · 11.2 KB
/
Copy path.eslintrc.json
File metadata and controls
288 lines (287 loc) · 11.2 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Use this file as a starting point for your project's .eslintrc.
// Copy this file, and add rule overrides as needed.
//
// Window 安装方法 eslit-aribnb安装地址https://www.npmjs.com/package/eslint-config-airbnb
//
// Mac 安装方法 转载地址 https://blog.csdn.net/m0_37068028/article/details/78548148
// (
// export PKG=eslint-config-airbnb;
// npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
// )
// eslint + airbnb + prettier 维护代码风格
// npm i eslint eslint-config-airbnb eslint-config-prettier eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier babel-eslint babel-plugin-import --save-dev
{
"extends": [
"airbnb",
"plugin:prettier/recommended"
],
// 默认情况下,ESLint 会在所有父级目录里寻找配置文件,一直到根目录。如果你想要你所有项目都遵循一个特定的约定时,这将会很有用,
// 但有时候会导致意想不到的结果。为了将 ESLint 限制到一个特定的项目,在你项目根目录下的 package.json 文件或者 .eslintrc.* 文件里的
// eslintConfig 字段下设置 "root": true。ESLint 一旦发现配置文件中有 "root": true,它就会停止在父级目录中寻找。
"root": true,
// 脚本在执行期间访问的额外的全局变量
// 当访问未定义的变量时,no-undef 规则将发出警告。如果你想在一个文件里使用全局变量,推荐你定义这些全局变量,这样 ESLint 就不会发出警告了。你可以使用注释或在配置文件中定义全局变量。
"globals": {
"window": true,
"document": true,
"$": true,
// 可从外部导入
"Cesium": "readonly",
"L": "readonly"
},
// 设置插件
"plugins": [],
// 设置解析器选项(必须设置这个属性)
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"parser": "babel-eslint",
//配置解析es6
"ecmaFeatures": {
"arrowFunctions": true,
"classes": true,
"modules": true,
"defaultParams": true
}
},
// 启用的规则及各自的错误级别
"rules": {
"prefer-const": 0, //首选const
// 禁止用console
"no-console": "warn",
//强制 getter 函数中出现 return 语句
"getter-return": "error",
//禁止与 -0 进行比较
"no-compare-neg-zero": "error",
//禁止条件表达式中出现赋值操作符
"no-cond-assign": "error",
//禁止在条件中使用常量表达式
"no-constant-condition": "error",
//禁止在正则表达式中使用控制字符
"no-control-regex": "off",
// 禁用 debugger
"no-debugger": "warn",
//禁止 function 定义中出现重名参数
"no-dupe-args": "error",
// 禁止对象字面量中出现重复的 key
"no-dupe-keys": "error",
// 禁止出现重复的 case 标签
"no-duplicate-case": "error",
// 禁止出现空语句块
"no-empty": "error",
// 禁止在正则表达式中使用空字符集
"no-empty-character-class": "off",
// 禁止对 catch 子句的参数重新赋值
"no-ex-assign": "off",
// 禁止不必要的布尔转换
"no-extra-boolean-cast": "off",
// 禁止对 function 声明重新赋值
"no-func-assign": "off",
// 禁止在嵌套的块中出现变量声明或 function 声明
"no-inner-declarations": "off",
// 禁止 RegExp 构造函数中存在无效的正则表达式字符串
"no-invalid-regexp": "error",
// 禁止不规则的空白
"no-irregular-whitespace": "off",
// 禁止把全局对象作为函数调用
"no-obj-calls": "error",
// 禁止正则表达式字面量中出现多个空格
"no-regex-spaces": "off",
// 禁用稀疏数组
"no-sparse-arrays": "error",
// 禁止在常规字符串中出现模板字面量占位符语法
"no-template-curly-in-string": "error",
// 禁止出现令人困惑的多行表达式
"no-unexpected-multiline": "off",
// 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
"no-unreachable": "error",
// 禁止在 finally 语句块中出现控制流语句
"no-unsafe-finally": "error",
// 禁止对关系运算符的左操作数使用否定操作符
"no-unsafe-negation": "error",
// 禁止由于 await 或 yield的使用而可能导致出现竞态条件的赋值
"require-atomic-updates": "error",
// 要求使用 isNaN() 检查 NaN
"use-isnan": "error",
// 强制 typeof 表达式与有效的字符串进行比较
"valid-typeof": "off",
// 强制 getter 和 setter 在对象中成对出现
"accessor-pairs": "off",
// 强制数组方法的回调函数中有 return 语句
"array-callback-return": "off",
// 强制把变量的使用限制在其定义的作用域范围内
"block-scoped-var": "error",
// 强制类方法使用 this
"class-methods-use-this": "off",
// 要求 return 语句要么总是指定返回的值,要么不指定
"consistent-return": "off",
// 强制所有控制语句使用一致的括号风格
"curly": "error",
// 要求 switch 语句中有 default 分支
"default-case": "error",
// 强制在点号之前和之后一致的换行
"dot-location": "off",
// 强制尽可能地使用点号
"dot-notation": "off",
// 要求使用 === 和 !==
"eqeqeq": "error",
// 要求 for-in 循环中有一个 if 语句
"guard-for-in": "off",
// 强制每个文件中包含的的类的最大数量
"max-classes-per-file": "off",
// 禁用 alert、confirm 和 prompt
"no-alert": "error",
// 禁用 arguments.caller 或 arguments.callee
"no-caller": "off",
// 不允许在 case 子句中使用词法声明
"no-case-declarations": "off",
// 禁止 if 语句中 return 语句之后有 else 块
"no-else-return": "off",
// 禁止出现空函数
"no-empty-function": "off",
// 禁止使用空解构模式
"no-empty-pattern": "off",
// 禁止在没有类型检查操作符的情况下与 null 进行比较
"no-eq-null": "error",
// 禁用 eval()
"no-eval": "error",
// 禁止扩展原生类型
"no-extend-native": "off",
// 禁止不必要的 .bind() 调用
"no-extra-bind": "error",
// 禁用不必要的标签
"no-extra-label": "error",
// 禁止 case 语句落空
"no-fallthrough": "error",
// 禁止数字字面量中使用前导和末尾小数点
"no-floating-decimal": "error",
// 禁止使用短符号进行类型转换
"no-implicit-coercion": "off",
// 禁止在全局范围内使用变量声明和 function 声明
"no-implicit-globals": "error",
// 禁止使用类似 eval() 的方法
"no-implied-eval": "error",
// 禁止 this 关键字出现在类和类对象之外
"no-invalid-this": "error",
// 禁用 __iterator__ 属性
"no-iterator": "error",
// 禁用标签语句
"no-labels": "error",
// 禁用不必要的嵌套块
"no-lone-blocks": "error",
// 禁止在循环语句中出现包含不安全引用的函数声明
"no-loop-func": "off",
// 禁用魔术数字
"no-magic-numbers": "off",
// 禁止使用多个空格
"no-multi-spaces": "off",
// 禁止使用多行字符串
"no-multi-str": "off",
// 禁止使用 new 以避免产生副作用
"no-new": "off",
// 禁止对 Function 对象使用 new 操作符
"no-new-func": "off",
// 禁止对 String,Number 和 Boolean 使用 new 操作符
"no-new-wrappers": "off",
// 禁用八进制字面量
"no-octal": "error",
// 禁止在字符串中使用八进制转义序列
"no-octal-escape": "error",
// 禁止对 function 的参数进行重新赋值
"no-param-reassign": "off",
// 禁用 __proto__ 属性
"no-proto": "off",
// 禁止多次声明同一变量
"no-redeclare": "error",
// 禁止使用对象的某些属性
"no-restricted-properties": "off",
// 禁止在 return 语句中使用赋值语句
"no-return-assign": "error",
// 禁止自我赋值
"no-self-assign": "error",
// 禁止自身比较
"no-self-compare": "error",
// 不允许使用逗号操作符
"no-sequences": "off",
//限制可以被抛出的异常
"no-throw-literal": "error",
// 禁用一成不变的循环条件
"no-unmodified-loop-condition": "error",
// 禁止未使用过的表达式
"no-unused-expressions": "error",
// 禁用未使用过的标签
"no-unused-labels": "off",
// 禁用不必要的 .call() 和 .apply()
"no-useless-call": "error",
// 禁止不必要的 catch 子句
"no-useless-catch": "error",
// 禁止没有必要的字符拼接
"no-useless-concat": "error",
// 禁用不必要的转义
"no-useless-escape": "error",
// 禁止多余的 return 语句
"no-useless-return": "off",
// 禁止使用void操作符
"no-void": "error",
// 禁用警告注释
"no-warning-comments": "error",
// 禁用 with 语句
"no-with": "error",
// 建议在正则表达式中使用命名捕获组
"prefer-named-capture-group": "off",
// 要求使用 Error 对象作为 Promise 拒绝的原因
"prefer-promise-reject-errors": "off",
// 要求必须有基数
"radix": "off",
// 禁止使用不带 await 表达式的 async 函数
"require-await": "error",
// 强制在 RegExp 上使用 u 标志
"require-unicode-regexp": "off",
// 要求将变量声明放在它们作用域的顶部
"vars-on-top": "error",
// 需要把立即执行的函数包裹起来
"wrap-iife": "off",
// 要求或者禁止Yoda条件
"yoda": "off",
// 使用严格模式指令
"strict": "error",
// 要求或禁止声明中的初始化
"init-declarations": "off",
// 禁止删除变量
"no-delete-var": "off",
// 不允许标签与变量同名
"no-label-var": "error",
// 禁止变量声明与外层作用域的变量同名
"no-shadow": "off",
// 禁用未声明的变量,除非它们在 /*global */ 注释中被提到
"no-undef": "error",
// 禁止将变量初始化为 undefined
"no-undef-init": "off",
// 禁止将 undefined 作为标识符
"no-undefined": "off",
// 禁止未使用过的变量
"no-unused-vars": "error",
// 禁止定义前使用
"no-use-before-define": "error",
// 禁止空的构造函数
"no-useless-constructor": "off",
"import/no-cycle": "off",
"no-prototype-builtins": "off",
"func-names": "off",
"no-plusplus": "off",
"no-underscore-dangle": "off",
"no-restricted-syntax": "off",
"prefer-destructuring": "off",
"import/prefer-default-export": "off",
"prefer-rest-params": "off",
// 禁止将Object.assign转为...符号
"prefer-object-spread": "off",
"no-restricted-globals": "off"
},
// 指定你想启用的环境
"env": {
"browser": true,
"es6": true,
"node": true
}
}