@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/.editorconfig
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# http://editorconfig.org
|
|
2
|
-
root = true
|
|
3
|
-
|
|
4
|
-
[*]
|
|
5
|
-
indent_style = space
|
|
6
|
-
indent_size = 2
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
charset = utf-8
|
|
9
|
-
trim_trailing_whitespace = true
|
|
10
|
-
insert_final_newline = true
|
|
11
|
-
|
|
12
|
-
[*.md]
|
|
13
|
-
trim_trailing_whitespace = false
|
|
14
|
-
|
|
15
|
-
[makefile]
|
|
16
|
-
indent_style = tab
|
|
17
|
-
indent_size = 4
|
|
1
|
+
# http://editorconfig.org
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
indent_style = space
|
|
6
|
+
indent_size = 2
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
charset = utf-8
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
insert_final_newline = true
|
|
11
|
+
|
|
12
|
+
[*.md]
|
|
13
|
+
trim_trailing_whitespace = false
|
|
14
|
+
|
|
15
|
+
[makefile]
|
|
16
|
+
indent_style = tab
|
|
17
|
+
indent_size = 4
|
package/.eslintignore
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
# 忽略目录
|
|
2
|
-
node_modules/
|
|
3
|
-
build/
|
|
4
|
-
dist/
|
|
5
|
-
zip/
|
|
6
|
-
demo/
|
|
7
|
-
coverage/
|
|
8
|
-
vendor/
|
|
9
|
-
lib/
|
|
10
|
-
sea-modules/
|
|
11
|
-
APP-META/
|
|
12
|
-
test/fixtures/
|
|
13
|
-
|
|
14
|
-
# 忽略文件
|
|
15
|
-
**/*.min.js
|
|
16
|
-
**/*-min.js
|
|
17
|
-
**/*.bundle.js
|
|
1
|
+
# 忽略目录
|
|
2
|
+
node_modules/
|
|
3
|
+
build/
|
|
4
|
+
dist/
|
|
5
|
+
zip/
|
|
6
|
+
demo/
|
|
7
|
+
coverage/
|
|
8
|
+
vendor/
|
|
9
|
+
lib/
|
|
10
|
+
sea-modules/
|
|
11
|
+
APP-META/
|
|
12
|
+
test/fixtures/
|
|
13
|
+
|
|
14
|
+
# 忽略文件
|
|
15
|
+
**/*.min.js
|
|
16
|
+
**/*-min.js
|
|
17
|
+
**/*.bundle.js
|
package/.eslintrc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
'./index',
|
|
4
|
-
].map(require.resolve),
|
|
5
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: [
|
|
3
|
+
'./index',
|
|
4
|
+
].map(require.resolve),
|
|
5
|
+
};
|
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
# eslint-config-encode
|
|
2
|
-
|
|
3
|
-
> 印客学院 JavaScript TypeScript Node 规范
|
|
4
|
-
|
|
5
|
-
提供了多套配置文件以支持 `JavaScript`、`TypeScript`、`React`、`Vue`、`Node.js` 等多种项目类型。
|
|
6
|
-
|
|
7
|
-
## JavaScript 项目 - eslint-config-encode
|
|
8
|
-
|
|
9
|
-
针对未使用 `React` 或 `Vue` 的原生 `JavaScript` 项目,使用 `ESLint` 原生规则和 [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import) 规则,使用 [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser) 作为 `parser`,是本包的默认配置。
|
|
10
|
-
|
|
11
|
-
### 依赖
|
|
12
|
-
|
|
13
|
-
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.16.0
|
|
14
|
-
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.16.3
|
|
15
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
16
|
-
|
|
17
|
-
### 安装
|
|
18
|
-
|
|
19
|
-
```shell
|
|
20
|
-
npm i -D eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 配置
|
|
24
|
-
|
|
25
|
-
```json
|
|
26
|
-
{
|
|
27
|
-
"extends": ["eslint-config-encode"]
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## JavaScript + React 项目 - eslint-config-encode/react
|
|
32
|
-
|
|
33
|
-
针对 JS React 项目,继承了默认配置,并启用了 [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) 和 [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks) 的规则。
|
|
34
|
-
|
|
35
|
-
### 依赖
|
|
36
|
-
|
|
37
|
-
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.16.0
|
|
38
|
-
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.16.3
|
|
39
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
40
|
-
- [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react)@^7.17.0
|
|
41
|
-
- [eslint-plugin-react-hooks](https://www.npmjs.com/package/)@^4.2.0
|
|
42
|
-
- [eslint-plugin-jsx-a11y](https://www.npmjs.com/package/eslint-plugin-jsx-a11y)@^6.3.1(可选)
|
|
43
|
-
|
|
44
|
-
### 安装
|
|
45
|
-
|
|
46
|
-
```shell
|
|
47
|
-
npm i -D eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import eslint-plugin-react eslint-plugin-react-hooks
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 配置
|
|
51
|
-
|
|
52
|
-
```json
|
|
53
|
-
{
|
|
54
|
-
"extends": ["eslint-config-encode/react"]
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
如果需要无障碍能力:
|
|
59
|
-
|
|
60
|
-
```shell
|
|
61
|
-
npm i -D eslint-plugin-jsx-a11y
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
```json
|
|
65
|
-
{
|
|
66
|
-
"extends": ["eslint-config-encode/react", "eslint-config-encode/jsx-a11y"]
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## JavaScript + Vue 项目 - eslint-config-encode/vue
|
|
71
|
-
|
|
72
|
-
针对 `JS Vue` 的项目,继承了默认配置,并启用了 [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue) 插件的规则,使用 [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser) 作为 parser。
|
|
73
|
-
|
|
74
|
-
### 依赖
|
|
75
|
-
|
|
76
|
-
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.16.0
|
|
77
|
-
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.16.3
|
|
78
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
79
|
-
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)@^7.0.0
|
|
80
|
-
- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)@^7.3.0
|
|
81
|
-
|
|
82
|
-
### 安装
|
|
83
|
-
|
|
84
|
-
```shell
|
|
85
|
-
npm i -D eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import vue-eslint-parser eslint-plugin-vue
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### 配置
|
|
89
|
-
|
|
90
|
-
```json
|
|
91
|
-
{
|
|
92
|
-
"extends": ["eslint-config-encode/vue"]
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## JavaScript (Node.js) 项目 - eslint-config-encode/node
|
|
97
|
-
|
|
98
|
-
针对 Node.js 项目,继承了默认配置和 [eslint-config-egg 的规则](https://github.com/eggjs/eslint-config-egg/blob/master/lib/rules/node.js),规则由 ESLint 原生规则和 [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node) 提供。
|
|
99
|
-
|
|
100
|
-
### 依赖
|
|
101
|
-
|
|
102
|
-
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.16.0
|
|
103
|
-
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.16.3
|
|
104
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
105
|
-
- [eslint-config-egg](https://www.npmjs.com/package/eslint-config-egg)@^10.0.0
|
|
106
|
-
|
|
107
|
-
### 安装
|
|
108
|
-
|
|
109
|
-
```shell
|
|
110
|
-
npm i -D eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import eslint-config-egg
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### 配置
|
|
114
|
-
|
|
115
|
-
```json
|
|
116
|
-
{
|
|
117
|
-
"extends": ["eslint-config-encode/node"]
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## TypeScript 项目 - eslint-config-encode/typescript
|
|
122
|
-
|
|
123
|
-
针对未使用 `React` 或 `Vue` 的 `TypeScript` 项目,继承了默认配置,并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则,使用 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 作为 parser。
|
|
124
|
-
|
|
125
|
-
### 依赖
|
|
126
|
-
|
|
127
|
-
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^5.0.0
|
|
128
|
-
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^5.0.0
|
|
129
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
130
|
-
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@2
|
|
131
|
-
|
|
132
|
-
### 安装
|
|
133
|
-
|
|
134
|
-
```shell
|
|
135
|
-
npm i -D eslint-config-encode @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### 配置
|
|
139
|
-
|
|
140
|
-
```json
|
|
141
|
-
{
|
|
142
|
-
"extends": ["eslint-config-encode/typescript"]
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
需保证项目已安装 `typescript` 依赖,另外如果项目的 `TS` 配置文件不是 `./tsconfig.json`,则需要设置 `.eslintrc` 中的 [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) 字段 ,例如:
|
|
147
|
-
|
|
148
|
-
```json
|
|
149
|
-
{
|
|
150
|
-
"extends": "eslint-config-encode/typescript",
|
|
151
|
-
"parserOptions": {
|
|
152
|
-
"project": "./tsconfig.eslint.json"
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## TypeScript + React 项目 - eslint-config-encode/typescript/react
|
|
158
|
-
|
|
159
|
-
针对 `TS React` 项目,继承了 `JS React` 的配置,并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则,使用 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 作为 parser。
|
|
160
|
-
|
|
161
|
-
### 依赖
|
|
162
|
-
|
|
163
|
-
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^5.0.0
|
|
164
|
-
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^5.0.0
|
|
165
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
166
|
-
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@2
|
|
167
|
-
- [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react)@^7.17.0
|
|
168
|
-
- [eslint-plugin-react-hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)@^4.2.0
|
|
169
|
-
- [eslint-plugin-jsx-a11y](https://www.npmjs.com/package/eslint-plugin-jsx-a11y)@^6.3.1(可选)
|
|
170
|
-
|
|
171
|
-
### 安装
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
npm i -D eslint-config-encode @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript eslint-plugin-react eslint-plugin-react-hooks
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### 配置
|
|
178
|
-
|
|
179
|
-
```json
|
|
180
|
-
{
|
|
181
|
-
"extends": ["eslint-config-encode/typescript/react"]
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
如果需要无障碍能力:
|
|
186
|
-
|
|
187
|
-
```shell
|
|
188
|
-
npm i -D eslint-plugin-jsx-a11y
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
```json
|
|
192
|
-
{
|
|
193
|
-
"extends": ["eslint-config-encode/typescript/react", "eslint-config-encode/jsx-a11y"]
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## TypeScript + Vue 项目 - eslint-config-encode/typescript/vue
|
|
198
|
-
|
|
199
|
-
针对 `TS Vue` 项目,继承了 `JS Vue` 的配置,并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则,使用 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 作为 `parser`。
|
|
200
|
-
|
|
201
|
-
### 依赖
|
|
202
|
-
|
|
203
|
-
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^5.0.0
|
|
204
|
-
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^5.0.0
|
|
205
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
206
|
-
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@2
|
|
207
|
-
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)@^7.0.0
|
|
208
|
-
- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)@^7.3.0
|
|
209
|
-
|
|
210
|
-
### 安装
|
|
211
|
-
|
|
212
|
-
```shell
|
|
213
|
-
npm i -D eslint-config-encode @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript vue-eslint-parser eslint-plugin-vue
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
### 配置
|
|
217
|
-
|
|
218
|
-
```json
|
|
219
|
-
{
|
|
220
|
-
"extends": ["eslint-config-encode/typescript/vue"]
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## TypeScript (Node.js) 项目 - eslint-config-encode/typescript/node
|
|
225
|
-
|
|
226
|
-
针对未使用 `React` 和 `Vue` 的 `TypeScript(Node)` 项目,继承了 `JS Node.js` 配置,并启用了 [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin) 插件的规则,使用 [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) 作为 parser。
|
|
227
|
-
|
|
228
|
-
### 依赖
|
|
229
|
-
|
|
230
|
-
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^5.0.0
|
|
231
|
-
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^5.0.0
|
|
232
|
-
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.25.3
|
|
233
|
-
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@2
|
|
234
|
-
- [eslint-config-egg](https://www.npmjs.com/package/eslint-config-egg)@^10.0.0
|
|
235
|
-
|
|
236
|
-
### 安装
|
|
237
|
-
|
|
238
|
-
```
|
|
239
|
-
npm i -D eslint-config-encode @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript eslint-config-egg
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### 配置
|
|
243
|
-
|
|
244
|
-
```json
|
|
245
|
-
{
|
|
246
|
-
"extends": ["eslint-config-encode/typescript/node"]
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## 配合 Prettier 使用
|
|
251
|
-
|
|
252
|
-
如果你的项目使用 [Prettier](https://prettier.io/) 进行代码格式化,本包的一些规则可能会跟 Prettier 格式化结果有冲突,[例如这条规则](https://github.com/typescript-eslint/typescript-eslint/issues/372)。为了避免冲突,你需要手动安装 [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) 和 [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier):
|
|
253
|
-
|
|
254
|
-
### 安装
|
|
255
|
-
|
|
256
|
-
```sh
|
|
257
|
-
npm install --save-dev eslint-config-prettier eslint-plugin-prettier
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### 配置
|
|
261
|
-
|
|
262
|
-
并修改 `.eslintrc` 的 `extends` 配置,增加 `prettier`,如下(以 TS React 项目为例):
|
|
263
|
-
|
|
264
|
-
```json
|
|
265
|
-
{
|
|
266
|
-
"extends": ["eslint-config-encode/typescript/react", "prettier"]
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
了解更多请阅读 [Prettier - Integrating with Linters](https://prettier.io/docs/en/integrating-with-linters.html)。
|
|
271
|
-
|
|
272
|
-
## 将风格问题降级
|
|
273
|
-
|
|
274
|
-
为了保证一致的编码风格,本包中大量风格相关的规则被设为了 `error` 级别,以引起开发者的足够重视。如果你觉得风格问题不足以是 `error` 级别(有些用户根据 ESLint error 进行流程卡点),本包还提供了一套名为 'essential' 的配置文件,这套配置将所有风格问题降级为 `warn` 级别,仅将必要问题报告为 `error`,引用方式为在相应配置的 `eslint-config-encode` 后面加上 `/essential`,如对 `JS React` 项目为 `eslint-config-encode/essential/react`、对 `TS Vue` 项目为 `eslint-config-encode/essential/typescript/vue`
|
|
275
|
-
|
|
276
|
-
## 了解更多
|
|
277
|
-
|
|
278
|
-
- 如果你对 ESLint 还不熟悉,可以阅读官网的 [Getting Started](https://eslint.org/docs/user-guide/getting-started) 快速入门。
|
|
279
|
-
- 了解如何为 IDE 配置 ESLint,可以参考官网的 [Integrations](http://eslint.org/docs/user-guide/integrations)。
|
|
280
|
-
- 了解如何在继承本包的基础上对项目 ESLint 进行个性化配置,可参考官网的 [Configuring ESLint](https://eslint.org/docs/user-guide/configuring)。下面简介下 ESLint 配置中的几个常用字段:
|
|
281
|
-
- `extends`: 继承一组规则集。`"extends": "eslint-config-encode",` 表示继承本包定义的规则配置。
|
|
282
|
-
- `rules`: 配置规则,这里定义的规则会覆盖 `extends` 的规则。如果觉得本包开启的某条规则过于严格,你可以暂时在这里将其关闭。
|
|
283
|
-
- `parser`: 设置 ESLint 的解析器。ESLint 使用 espree 作为默认的解析器,可以通过这个参数指定其他的解析器。比如指定为 [@babel/eslint-parser](https://npmjs.com/package/@babel/eslint-parser),以解析 Babel 支持但 ESLint 默认解析器不支持的语法(本包不同配置文件使用的解析器可在简介表格中的「依赖 parser」一列查看)。
|
|
284
|
-
- `globals`: 指定代码中可能用到的全局变量,以免全局变量被 [no-undef](http://eslint.org/docs/rules/no-undef) 规则报错。
|
|
285
|
-
- `env`: 指定代码的运行环境,每个环境预定义了一组对应的全局变量,本包已开启的环境有 browser、node、jquery、es6 及几个测试框架的环境。
|
|
286
|
-
- 了解常用的 ESLint 命令,如 `--fix`、`--ext`,可参考官网的 [Command Line Interface](http://eslint.org/docs/user-guide/command-line-interface)。
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var hero = {
|
|
2
|
-
firstName: 'Kevin',
|
|
3
|
-
lastName: 'Flynn',
|
|
4
|
-
};
|
|
1
|
+
var hero = {
|
|
2
|
+
firstName: 'Kevin',
|
|
3
|
+
lastName: 'Flynn',
|
|
4
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
let foo = [1,2]
|
|
2
|
-
console.log(foo);
|
|
3
|
-
eval('alert(1)');
|
|
1
|
+
let foo = [1,2]
|
|
2
|
+
console.log(foo);
|
|
3
|
+
eval('alert(1)');
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
// 'no-var'
|
|
2
|
-
var fs = require('fs');
|
|
3
|
-
|
|
4
|
-
// 'node/prefer-global/buffer'
|
|
5
|
-
// 'quotes'
|
|
6
|
-
const { Buffer } = require("buffer");
|
|
7
|
-
// 'node/no-new-require'
|
|
8
|
-
// 'new-cap'
|
|
9
|
-
const util = new require('util');
|
|
10
|
-
|
|
11
|
-
// 'no-console'
|
|
12
|
-
console.log(util);
|
|
13
|
-
// 'semi'
|
|
14
|
-
// 'no-unused-vars'
|
|
15
|
-
const b = Buffer.alloc(16)
|
|
16
|
-
|
|
17
|
-
// 'node/prefer-promises/fs'
|
|
18
|
-
fs.readFile('../node.ts', 'utf-8', (err, data) => {
|
|
19
|
-
// 'no-console'
|
|
20
|
-
console.log(err, data);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
exports = fs;
|
|
1
|
+
// 'no-var'
|
|
2
|
+
var fs = require('fs');
|
|
3
|
+
|
|
4
|
+
// 'node/prefer-global/buffer'
|
|
5
|
+
// 'quotes'
|
|
6
|
+
const { Buffer } = require("buffer");
|
|
7
|
+
// 'node/no-new-require'
|
|
8
|
+
// 'new-cap'
|
|
9
|
+
const util = new require('util');
|
|
10
|
+
|
|
11
|
+
// 'no-console'
|
|
12
|
+
console.log(util);
|
|
13
|
+
// 'semi'
|
|
14
|
+
// 'no-unused-vars'
|
|
15
|
+
const b = Buffer.alloc(16)
|
|
16
|
+
|
|
17
|
+
// 'node/prefer-promises/fs'
|
|
18
|
+
fs.readFile('../node.ts', 'utf-8', (err, data) => {
|
|
19
|
+
// 'no-console'
|
|
20
|
+
console.log(err, data);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
exports = fs;
|
|
24
24
|
// 'eol-last'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export default () => {
|
|
4
|
-
return (
|
|
5
|
-
<p>hello, world</p>
|
|
6
|
-
)
|
|
7
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export default () => {
|
|
4
|
+
return (
|
|
5
|
+
<p>hello, world</p>
|
|
6
|
+
)
|
|
7
|
+
}
|