@qiangzaifan/eslint-config-encode 0.0.0-stage → 1.0.0

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/.eslintrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ extends: [
3
+ './index',
4
+ ].map(require.resolve),
5
+ };
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 印客学院
4
+ Copyright (c) 2023 强仔 (modifications)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,286 @@
1
- # Temporary Holding Version
1
+ # @qiangzaifan/eslint-config-encode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > 强仔 JavaScript TypeScript Node 规范
4
+
5
+ 提供了多套配置文件以支持 `JavaScript`、`TypeScript`、`React`、`Vue`、`Node.js` 等多种项目类型。
6
+
7
+ ## JavaScript 项目 - @qiangzaifan/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 @qiangzaifan/eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import
21
+ ```
22
+
23
+ ### 配置
24
+
25
+ ```json
26
+ {
27
+ "extends": ["@qiangzaifan/eslint-config-encode"]
28
+ }
29
+ ```
30
+
31
+ ## JavaScript + React 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/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": ["@qiangzaifan/eslint-config-encode/react", "@qiangzaifan/eslint-config-encode/jsx-a11y"]
67
+ }
68
+ ```
69
+
70
+ ## JavaScript + Vue 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/eslint-config-encode/vue"]
93
+ }
94
+ ```
95
+
96
+ ## JavaScript (Node.js) 项目 - @qiangzaifan/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 @qiangzaifan/eslint-config-encode @babel/core @babel/eslint-parser eslint-plugin-import eslint-config-egg
111
+ ```
112
+
113
+ ### 配置
114
+
115
+ ```json
116
+ {
117
+ "extends": ["@qiangzaifan/eslint-config-encode/node"]
118
+ }
119
+ ```
120
+
121
+ ## TypeScript 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/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": "@qiangzaifan/eslint-config-encode/typescript",
151
+ "parserOptions": {
152
+ "project": "./tsconfig.eslint.json"
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## TypeScript + React 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/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": ["@qiangzaifan/eslint-config-encode/typescript/react", "@qiangzaifan/eslint-config-encode/jsx-a11y"]
194
+ }
195
+ ```
196
+
197
+ ## TypeScript + Vue 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/eslint-config-encode/typescript/vue"]
221
+ }
222
+ ```
223
+
224
+ ## TypeScript (Node.js) 项目 - @qiangzaifan/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 @qiangzaifan/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": ["@qiangzaifan/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": ["@qiangzaifan/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`,引用方式为在相应配置的 `@qiangzaifan/eslint-config-encode` 后面加上 `/essential`,如对 `JS React` 项目为 `@qiangzaifan/eslint-config-encode/essential/react`、对 `TS Vue` 项目为 `@qiangzaifan/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": "@qiangzaifan/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)。
package/es5.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ extends: [
3
+ './rules/base/best-practices',
4
+ './rules/base/possible-errors',
5
+ './rules/base/style',
6
+ './rules/base/variables',
7
+ './rules/es5',
8
+ ].map(require.resolve),
9
+ root: true,
10
+ };
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../es5',
4
+ './rules/set-style-to-warn',
5
+ './rules/blacklist',
6
+ ].map(require.resolve),
7
+ rules: {
8
+ // 逗号风格 - ES5 中不加最后一个逗号
9
+ // @unessential
10
+ 'comma-dangle': ['warn', 'never'],
11
+ },
12
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * essential 级别出口文件仅将会必要的规则设置为 error 级别
3
+ */
4
+
5
+ module.exports = {
6
+ extends: [
7
+ '../index',
8
+ './rules/set-style-to-warn',
9
+ './rules/blacklist',
10
+ './rules/es6-blacklist',
11
+ ].map(require.resolve),
12
+ };
@@ -0,0 +1,76 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../react',
4
+ './rules/set-style-to-warn',
5
+ './rules/blacklist',
6
+ './rules/es6-blacklist',
7
+ ].map(require.resolve),
8
+ rules: {
9
+ // 标签的属性有多行时,结束标签需另起一行
10
+ // @unessential
11
+ 'react/jsx-closing-bracket-location': ['warn', 'line-aligned'],
12
+
13
+ // JSX 语法闭合标签的缩进和换行
14
+ // @unessential
15
+ 'react/jsx-closing-tag-location': 'warn',
16
+
17
+ // JSX 行内属性间仅有一个空格
18
+ // @unessential
19
+ 'react/jsx-props-no-multi-spaces': 'warn',
20
+
21
+ // JSX 属性的大括号内部两侧无空格
22
+ // @unessential
23
+ 'react/jsx-curly-spacing': ['warn', 'never', { allowMultiline: true }],
24
+
25
+ // JSX 属性使用 2 个空格缩进
26
+ // @unessential
27
+ 'react/jsx-indent-props': ['off', 2],
28
+
29
+ // 标签属性的换行,如果标签有多个属性,且存在换行,则每个属性都需要换行独占一行
30
+ // @unessential
31
+ 'react/jsx-max-props-per-line': ['warn', { maximum: 1, when: 'multiline' }],
32
+
33
+ // 禁止使用已经废弃的方法
34
+ // @unessential
35
+ 'react/no-deprecated': 'warn',
36
+
37
+ // 多行的 JSX 标签需用小括号包裹
38
+ // @unessential
39
+ 'react/jsx-wrap-multilines': [
40
+ 'warn',
41
+ {
42
+ declaration: true,
43
+ assignment: true,
44
+ return: true,
45
+ arrow: true,
46
+ },
47
+ ],
48
+
49
+ // 设置第一个属性的位置。multiline-multiprop:如果JSX标签占用多行并且有多个属性,则第一个属性应始终放在新行上
50
+ // @unessential
51
+ 'react/jsx-first-prop-new-line': ['warn', 'multiline-multiprop'],
52
+
53
+ // 不要在 JSX 属性的等号两边加空格
54
+ // @unessential
55
+ 'react/jsx-equals-spacing': ['warn', 'never'],
56
+
57
+ // JSX 使用 2 个空格缩进
58
+ // @unessential
59
+ 'react/jsx-indent': ['off', 2],
60
+
61
+ // 不要使用 findDOMNode,严格模式下已经弃用
62
+ // @unessential
63
+ 'react/no-find-dom-node': 'warn',
64
+
65
+ // 自闭合标签的斜线前有且仅有一个空格
66
+ // @unessential
67
+ 'react/jsx-tag-spacing': [
68
+ 'warn',
69
+ {
70
+ closingSlash: 'never',
71
+ beforeSelfClosing: 'always',
72
+ afterOpening: 'never',
73
+ },
74
+ ],
75
+ },
76
+ };
@@ -0,0 +1,48 @@
1
+ module.exports = {
2
+ rules: {
3
+ // 统一在点号之前换行
4
+ // @unessential
5
+ 'dot-location': ['warn', 'property'],
6
+
7
+ // 禁止使用 eval
8
+ // @unessential 部分场景必须使用 eval
9
+ 'no-eval': 'warn',
10
+
11
+ // 禁止使用类 eval 的方法,如 setTimeout 传入字符串
12
+ // @unessential
13
+ 'no-implied-eval': 'warn',
14
+
15
+ // 禁止使用 javascript:url,如 location.href = 'javascript:void(0)';
16
+ // @unessential
17
+ 'no-script-url': 'warn',
18
+
19
+ // 禁止变量与外层作用域已存在的变量同名
20
+ // @unessential
21
+ 'no-shadow': 'warn',
22
+
23
+ // 禁止出现多个连续空格
24
+ // @unessential
25
+ 'no-multi-spaces': [
26
+ 'warn',
27
+ {
28
+ ignoreEOLComments: false,
29
+ },
30
+ ],
31
+
32
+ // 使用 2 个空格缩进
33
+ // @unessential
34
+ indent: 'off',
35
+
36
+ // 使用分号
37
+ // @unessential
38
+ semi: 'off',
39
+
40
+ // 分号必须写在行尾
41
+ // @unessential
42
+ 'semi-style': 'off',
43
+
44
+ // 不要直接在对象上调用 Object.prototypes 上的方法
45
+ // @unessential
46
+ 'no-prototype-builtins': 'warn',
47
+ },
48
+ };
@@ -0,0 +1,62 @@
1
+ module.exports = {
2
+ rules: {
3
+ // 箭头函数的箭头前后各留一个空格
4
+ // @unessential
5
+ 'arrow-spacing': ['warn', { before: true, after: true }],
6
+
7
+ // generator 函数的 * 号前面无空格,后面有一个空格
8
+ // @unessential
9
+ 'generator-star-spacing': ['warn', { before: false, after: true }],
10
+
11
+ // 避免箭头函数与比较操作符产生混淆
12
+ // @unessential
13
+ 'no-confusing-arrow': 'warn',
14
+
15
+ // 回调函数使用箭头函数而不是匿名函数
16
+ // @unessential
17
+ 'prefer-arrow-callback': [
18
+ 'warn',
19
+ {
20
+ allowNamedFunctions: false,
21
+ allowUnboundThis: true,
22
+ },
23
+ ],
24
+
25
+ // 优先使用 const,只有当变量会被重新赋值时才使用 let
26
+ // @unessential
27
+ 'prefer-const': [
28
+ 'warn',
29
+ {
30
+ destructuring: 'any',
31
+ ignoreReadBeforeAssign: true,
32
+ },
33
+ ],
34
+
35
+ // 模板字符串中的大括号内部两侧无空格
36
+ // @unessential
37
+ 'template-curly-spacing': 'warn',
38
+
39
+ // yield* 表达式的 * 号前面无空格,后面有一个空格
40
+ // @unessential
41
+ 'yield-star-spacing': ['warn', 'after'],
42
+
43
+ // import 语句需要放到模块的最上方
44
+ // @unessential
45
+ 'import/first': 'warn',
46
+
47
+ // 使用对象属性和方法的简写语法
48
+ // @unessential
49
+ 'object-shorthand': [
50
+ 'warn',
51
+ 'always',
52
+ {
53
+ ignoreConstructors: false,
54
+ avoidQuotes: true,
55
+ },
56
+ ],
57
+
58
+ // 使用 const 或 let 声明变量,不要使用 var
59
+ // @unessential
60
+ 'no-var': 'warn',
61
+ },
62
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 将 error 级别的 style 规则降级为 warn
3
+ */
4
+
5
+ // 将传入 config 中 error 级别规则都改为 warn 级别
6
+ function setErrorRulesToWarn(configPath) {
7
+ const config = require(configPath);
8
+ const { rules } = config;
9
+
10
+ for (const ruleName in rules) {
11
+ if (Object.prototype.hasOwnProperty.call(rules, ruleName)) {
12
+ const ruleValue = rules[ruleName];
13
+ if (Array.isArray(ruleValue)) {
14
+ // 'array-bracket-spacing': [ 'error', 'never' ] 这种规则写法
15
+ if (ruleValue[0] === 'error') {
16
+ ruleValue[0] = 'warn';
17
+ }
18
+ } else if (ruleValue === 'error') {
19
+ // 'new-parens': 'error' 这种规则写法
20
+ rules[ruleName] = 'warn';
21
+ }
22
+ }
23
+ }
24
+
25
+ return {
26
+ rules,
27
+ };
28
+ }
29
+
30
+ module.exports = setErrorRulesToWarn('../../rules/base/style.js');
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ rules: {
3
+ // 使用 2 个空格缩进
4
+ // @unessential
5
+ '@typescript-eslint/indent': 'off',
6
+
7
+ // 使用分号
8
+ // @unessential
9
+ '@typescript-eslint/semi': 'off',
10
+
11
+ '@typescript-eslint/adjacent-overload-signatures': 'warn',
12
+
13
+ '@typescript-eslint/no-parameter-properties': 'warn',
14
+ },
15
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../index',
4
+ '../../rules/typescript',
5
+ '../rules/ts-blacklist',
6
+ ].map(require.resolve),
7
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../react',
4
+ '../../rules/typescript',
5
+ '../rules/ts-blacklist',
6
+ ].map(require.resolve),
7
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ extends: [
3
+ './index',
4
+ '../../rules/vue', // vue 要置于最后,因为里面用了 vue-parser
5
+ ].map(require.resolve),
6
+ parserOptions: {
7
+ parser: '@typescript-eslint/parser',
8
+ },
9
+ };
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ extends: [
3
+ '../vue',
4
+ './rules/set-style-to-warn',
5
+ './rules/blacklist',
6
+ './rules/es6-blacklist',
7
+ ].map(require.resolve),
8
+ };
package/index.js ADDED
@@ -0,0 +1,23 @@
1
+ module.exports = {
2
+ extends: [
3
+ './rules/base/best-practices',
4
+ './rules/base/possible-errors',
5
+ './rules/base/style',
6
+ './rules/base/variables',
7
+ './rules/base/es6',
8
+ './rules/base/strict',
9
+ './rules/imports',
10
+ ].map(require.resolve),
11
+ parser: '@babel/eslint-parser',
12
+ parserOptions: {
13
+ requireConfigFile: false,
14
+ ecmaVersion: 2020,
15
+ sourceType: 'module',
16
+ ecmaFeatures: {
17
+ globalReturn: false,
18
+ impliedStrict: true,
19
+ jsx: true,
20
+ },
21
+ },
22
+ root: true,
23
+ };
package/jsx-a11y.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ extends: [
3
+ './rules/jsx-a11y',
4
+ ].map(require.resolve),
5
+ };
package/node.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ extends: [
3
+ './index',
4
+ './rules/node',
5
+ ].map(require.resolve),
6
+ };