eslint-config-hcl 0.0.3-alpha.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/LICENSE +1 -0
- package/README.md +219 -0
- package/essential/es5.js +15 -0
- package/essential/index.js +11 -0
- package/essential/rules/blacklist.js +48 -0
- package/essential/rules/es6-blacklist.js +62 -0
- package/essential/rules/set-style-to-warn.js +26 -0
- package/essential/rules/ts-blacklist.js +15 -0
- package/essential/typescript/index.js +28 -0
- package/essential/typescript/vue.js +28 -0
- package/essential/vue.js +11 -0
- package/index.js +58 -0
- package/package.json +65 -0
- package/rules/base/best-practices.js +284 -0
- package/rules/base/es6.js +168 -0
- package/rules/base/possible-errors.js +126 -0
- package/rules/base/strict.js +6 -0
- package/rules/base/style.js +445 -0
- package/rules/base/variables.js +37 -0
- package/rules/es5.js +11 -0
- package/rules/imports.js +158 -0
- package/rules/typescript.js +775 -0
- package/rules/vue.js +94 -0
- package/typescript/index.js +39 -0
- package/typescript/vue.js +29 -0
- package/vue.js +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# eslint-config-hcl
|
|
2
|
+
|
|
3
|
+
> 基于 ESLint 9 扁平配置的基础通用 JavaScript、TypeScript、Vue 编码规范
|
|
4
|
+
|
|
5
|
+
支持配套的 [eslint 可共享配置](https://www.npmjs.com/package/markdownlint#optionsconfig)。
|
|
6
|
+
|
|
7
|
+
提供了多套配置文件以支持 `JavaScript`、`TypeScript`、`Vue` 等多种项目类型。
|
|
8
|
+
|
|
9
|
+
## JavaScript 项目 - eslint-config-hcl
|
|
10
|
+
|
|
11
|
+
针对未使用 `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`,是本包的默认配置。
|
|
12
|
+
|
|
13
|
+
### 依赖
|
|
14
|
+
|
|
15
|
+
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.24.0
|
|
16
|
+
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.24.5
|
|
17
|
+
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.31.0
|
|
18
|
+
|
|
19
|
+
### 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @babel/core @babel/eslint-parser eslint-plugin-import --save-dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
安装本包:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install eslint-config-hcl --save-dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 配置
|
|
32
|
+
|
|
33
|
+
配置文件 `eslint.config.js`,内容如下:
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
// eslint.config.js
|
|
37
|
+
import eslintConfigHcl from 'eslint-config-hcl';
|
|
38
|
+
|
|
39
|
+
export default [
|
|
40
|
+
...eslintConfigHcl,
|
|
41
|
+
// 你的自定义配置
|
|
42
|
+
];
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## JavaScript + Vue 项目 - eslint-config-hcl/vue
|
|
46
|
+
|
|
47
|
+
针对 `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。
|
|
48
|
+
|
|
49
|
+
### 依赖
|
|
50
|
+
|
|
51
|
+
- [@babel/core](https://www.npmjs.com/package/@babel/core)@^7.24.0
|
|
52
|
+
- [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)@^7.24.5
|
|
53
|
+
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.31.0
|
|
54
|
+
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)@^9.4.3
|
|
55
|
+
- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)@^9.33.0
|
|
56
|
+
|
|
57
|
+
### 安装
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @babel/core @babel/eslint-parser eslint-plugin-import vue-eslint-parser eslint-plugin-vue --save-dev
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
安装本包:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install eslint-config-hcl --save-dev
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 配置
|
|
70
|
+
|
|
71
|
+
配置文件 `eslint.config.js`,内容如下:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// eslint.config.js
|
|
75
|
+
import eslintConfigHclVue from 'eslint-config-hcl/vue';
|
|
76
|
+
|
|
77
|
+
export default [
|
|
78
|
+
...eslintConfigHclVue,
|
|
79
|
+
// 你的自定义配置
|
|
80
|
+
];
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## TypeScript 项目 - eslint-config-hcl/typescript
|
|
84
|
+
|
|
85
|
+
针对未使用 `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。
|
|
86
|
+
|
|
87
|
+
### 依赖
|
|
88
|
+
|
|
89
|
+
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^8.5.0
|
|
90
|
+
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^8.5.0
|
|
91
|
+
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.31.0
|
|
92
|
+
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@^4.0.0
|
|
93
|
+
|
|
94
|
+
### 安装
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript --save-dev
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
安装本包:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npm install eslint-config-hcl --save-dev
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 配置
|
|
107
|
+
|
|
108
|
+
配置文件 `eslint.config.js`,内容如下:
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
// eslint.config.js
|
|
112
|
+
import eslintConfigHclTS from 'eslint-config-hcl/typescript';
|
|
113
|
+
|
|
114
|
+
export default [
|
|
115
|
+
...eslintConfigHclTS,
|
|
116
|
+
// 你的自定义配置
|
|
117
|
+
];
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
需保证项目已安装 `typescript` 依赖,另外如果项目的 `TS` 配置文件不是 `./tsconfig.json`,则需要设置 `languageOptions.parserOptions.project` 字段 ,例如:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// eslint.config.js
|
|
124
|
+
import eslintConfigHclTS from 'eslint-config-hcl/typescript';
|
|
125
|
+
|
|
126
|
+
export default [
|
|
127
|
+
...eslintConfigHclTS,
|
|
128
|
+
{
|
|
129
|
+
languageOptions: {
|
|
130
|
+
parserOptions: {
|
|
131
|
+
project: './tsconfig.eslint.json',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## TypeScript + Vue 项目 - eslint-config-hcl/typescript/vue
|
|
139
|
+
|
|
140
|
+
针对 `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`。
|
|
141
|
+
|
|
142
|
+
### 依赖
|
|
143
|
+
|
|
144
|
+
- [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)@^8.5.0
|
|
145
|
+
- [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)@^8.5.0
|
|
146
|
+
- [eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)@^2.31.0
|
|
147
|
+
- [eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript)@^4.0.0
|
|
148
|
+
- [vue-eslint-parser](https://www.npmjs.com/package/vue-eslint-parser)@^9.4.3
|
|
149
|
+
- [eslint-plugin-vue](https://www.npmjs.com/package/eslint-plugin-vue)@^9.33.0
|
|
150
|
+
|
|
151
|
+
### 安装
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-import-resolver-typescript vue-eslint-parser eslint-plugin-vue --save-dev
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
安装本包:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm install eslint-config-hcl --save-dev
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 配置
|
|
164
|
+
|
|
165
|
+
配置文件 `eslint.config.js`,内容如下:
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
// eslint.config.js
|
|
169
|
+
import eslintConfigHclTSVue from 'eslint-config-hcl/typescript/vue';
|
|
170
|
+
|
|
171
|
+
export default [
|
|
172
|
+
...eslintConfigHclTSVue,
|
|
173
|
+
// 你的自定义配置
|
|
174
|
+
];
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## 配合 Prettier 使用
|
|
178
|
+
|
|
179
|
+
如果你的项目使用 [Prettier](https://prettier.io/) 进行代码格式化,本包的一些规则可能会跟 Prettier 格式化结果有冲突,[例如这条规则](https://github.com/typescript-eslint/typescript-eslint/issues/372)。为了避免冲突,你需要手动安装 [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier):
|
|
180
|
+
|
|
181
|
+
### 安装
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm install eslint-config-prettier --save-dev
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 配置
|
|
188
|
+
|
|
189
|
+
并修改 `eslint.config.js`,在配置数组中增加 `prettier` 配置(需放在最后,以覆盖冲突规则):
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
// eslint.config.js
|
|
193
|
+
import eslintConfigHclTSVue from 'eslint-config-hcl/typescript/vue';
|
|
194
|
+
|
|
195
|
+
export default [
|
|
196
|
+
...eslintConfigHclTSVue,
|
|
197
|
+
// 放在最后,以覆盖冲突规则
|
|
198
|
+
'prettier',
|
|
199
|
+
// 你的自定义配置
|
|
200
|
+
];
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
了解更多请阅读 [Prettier - Integrating with Linters](https://prettier.io/docs/en/integrating-with-linters.html)。
|
|
204
|
+
|
|
205
|
+
## 将风格问题降级
|
|
206
|
+
|
|
207
|
+
为了保证一致的编码风格,本包中大量风格相关的规则被设为了 `error` 级别,以引起开发者的足够重视。如果你觉得风格问题不足以是 `error` 级别(有些用户根据 ESLint error 进行流程卡点),本包还提供了一套名为 'essential' 的配置文件,这套配置将所有风格问题降级为 `warn` 级别,仅将必要问题报告为 `error`,引用方式为在相应配置的 `eslint-config` 后面加上 `/essential`,如对 `JS Vue` 项目为 `eslint-config/essential/Vue`、对 `TS Vue` 项目为 `eslint-config/essential/typescript/vue`
|
|
208
|
+
|
|
209
|
+
## 了解更多
|
|
210
|
+
|
|
211
|
+
- 如果你对 ESLint 还不熟悉,可以阅读官网的 [Getting Started](https://eslint.org/docs/user-guide/getting-started) 快速入门。
|
|
212
|
+
- 了解如何为 IDE 配置 ESLint,可以参考官网的 [Integrations](http://eslint.org/docs/user-guide/integrations)。
|
|
213
|
+
- 了解如何在继承本包的基础上对项目 ESLint 进行个性化配置,可参考官网的 [Configuring ESLint](https://eslint.org/docs/user-guide/configuring)。下面简介下 ESLint 配置中的几个常用字段:
|
|
214
|
+
- `extends`: 继承一组规则集。`"extends": "eslint-config",` 表示继承本包定义的规则配置。
|
|
215
|
+
- `rules`: 配置规则,这里定义的规则会覆盖 `extends` 的规则。如果觉得本包开启的某条规则过于严格,你可以暂时在这里将其关闭。
|
|
216
|
+
- `parser`: 设置 ESLint 的解析器。ESLint 使用 Espree 作为默认的解析器,可以通过这个参数指定其他的解析器。比如指定为 [@babel/eslint-parser](https://npmjs.com/package/@babel/eslint-parser),以解析 Babel 支持但 ESLint 默认解析器不支持的语法(本包不同配置文件使用的解析器可在简介表格中的「依赖 parser」一列查看)。
|
|
217
|
+
- `globals`: 指定代码中可能用到的全局变量,以免全局变量被 [no-undef](http://eslint.org/docs/rules/no-undef) 规则报错。
|
|
218
|
+
- `env`: 指定代码的运行环境,每个环境预定义了一组对应的全局变量,本包已开启的环境有 browser、node、jquery、es6 及几个测试框架的环境。
|
|
219
|
+
- 了解常用的 ESLint 命令,如 `--fix`、`--ext`,可参考官网的 [Command Line Interface](http://eslint.org/docs/user-guide/command-line-interface)。
|
package/essential/es5.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import es5Config from '../es5.js';
|
|
2
|
+
import setStyleToWarn from './rules/set-style-to-warn.js';
|
|
3
|
+
import blacklist from './rules/blacklist.js';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
...es5Config,
|
|
7
|
+
setStyleToWarn,
|
|
8
|
+
blacklist,
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.js'],
|
|
11
|
+
rules: {
|
|
12
|
+
'comma-dangle': ['warn', 'never'],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import baseConfig from '../index.js';
|
|
2
|
+
import setStyleToWarn from './rules/set-style-to-warn.js';
|
|
3
|
+
import blacklist from './rules/blacklist.js';
|
|
4
|
+
import es6Blacklist from './rules/es6-blacklist.js';
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
...baseConfig,
|
|
8
|
+
setStyleToWarn,
|
|
9
|
+
blacklist,
|
|
10
|
+
es6Blacklist,
|
|
11
|
+
];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export default {
|
|
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
|
+
export default {
|
|
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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将 error 级别的 style 规则降级为 warn
|
|
3
|
+
*/
|
|
4
|
+
import styleRules from '../../rules/base/style.js';
|
|
5
|
+
|
|
6
|
+
// 将传入 config 中 error 级别规则都改为 warn 级别
|
|
7
|
+
function setErrorRulesToWarn(config) {
|
|
8
|
+
const rules = { ...config.rules };
|
|
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
|
+
if (ruleValue[0] === 'error') {
|
|
15
|
+
rules[ruleName] = ['warn', ...ruleValue.slice(1)];
|
|
16
|
+
}
|
|
17
|
+
} else if (ruleValue === 'error') {
|
|
18
|
+
rules[ruleName] = 'warn';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { rules };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default setErrorRulesToWarn(styleRules);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default {
|
|
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/parameter-properties': 'warn',
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import essentialConfig from '../index.js';
|
|
2
|
+
import tsRules from '../../rules/typescript.js';
|
|
3
|
+
import tsBlacklist from '../rules/ts-blacklist.js';
|
|
4
|
+
// // 显式导入并注册 @typescript-eslint
|
|
5
|
+
import tsParser from '@typescript-eslint/parser';
|
|
6
|
+
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
|
7
|
+
import importPlugin from 'eslint-plugin-import';
|
|
8
|
+
|
|
9
|
+
export default [
|
|
10
|
+
...essentialConfig,
|
|
11
|
+
{
|
|
12
|
+
files: ['**/*.{ts}'],
|
|
13
|
+
languageOptions: {
|
|
14
|
+
parser: tsParser,
|
|
15
|
+
parserOptions: {
|
|
16
|
+
project: './tsconfig.json',
|
|
17
|
+
createDefaultProgram: true,
|
|
18
|
+
extraFileExtensions: ['.vue'],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
plugins: {
|
|
22
|
+
'@typescript-eslint': tsPlugin,
|
|
23
|
+
import: importPlugin,
|
|
24
|
+
},
|
|
25
|
+
...tsRules,
|
|
26
|
+
},
|
|
27
|
+
tsBlacklist,
|
|
28
|
+
];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import tsEssentialConfig from './index.js';
|
|
2
|
+
import vueRules from '../../rules/vue.js';
|
|
3
|
+
|
|
4
|
+
import tsParser from '@typescript-eslint/parser';
|
|
5
|
+
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
|
6
|
+
import vuePlugin from 'eslint-plugin-vue';
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
...tsEssentialConfig,
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.vue'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
parser: vuePlugin.parser,
|
|
14
|
+
parserOptions: {
|
|
15
|
+
parser: tsParser,
|
|
16
|
+
ecmaVersion: 2022,
|
|
17
|
+
sourceType: 'module',
|
|
18
|
+
project: './tsconfig.json',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
plugins: {
|
|
22
|
+
'@typescript-eslint': tsPlugin,
|
|
23
|
+
'vue': vuePlugin,
|
|
24
|
+
},
|
|
25
|
+
// vue 要置于最后,因为里面用了 vue-parser 插件,需要在 ts 规则之后执行
|
|
26
|
+
...vueRules,
|
|
27
|
+
},
|
|
28
|
+
];
|
package/essential/vue.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import vueConfig from '../vue.js';
|
|
2
|
+
import setStyleToWarn from './rules/set-style-to-warn.js';
|
|
3
|
+
import blacklist from './rules/blacklist.js';
|
|
4
|
+
import es6Blacklist from './rules/es6-blacklist.js';
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
...vueConfig,
|
|
8
|
+
setStyleToWarn,
|
|
9
|
+
blacklist,
|
|
10
|
+
es6Blacklist,
|
|
11
|
+
];
|
package/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import babelParser from '@babel/eslint-parser';
|
|
2
|
+
import importPlugin from 'eslint-plugin-import';
|
|
3
|
+
|
|
4
|
+
import bestPracticesRules from './rules/base/best-practices.js';
|
|
5
|
+
import possibleErrorsRules from './rules/base/possible-errors.js';
|
|
6
|
+
import styleRules from './rules/base/style.js';
|
|
7
|
+
import variablesRules from './rules/base/variables.js';
|
|
8
|
+
import es6Rules from './rules/base/es6.js';
|
|
9
|
+
import strictRules from './rules/base/strict.js';
|
|
10
|
+
import importsRules from './rules/imports.js';
|
|
11
|
+
|
|
12
|
+
export default [
|
|
13
|
+
{
|
|
14
|
+
languageOptions: {
|
|
15
|
+
parser: babelParser,
|
|
16
|
+
parserOptions: {
|
|
17
|
+
requireConfigFile: false,
|
|
18
|
+
ecmaVersion: 2022,
|
|
19
|
+
sourceType: 'module',
|
|
20
|
+
ecmaFeatures: {
|
|
21
|
+
globalReturn: false,
|
|
22
|
+
impliedStrict: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
plugins: {
|
|
27
|
+
import: importPlugin,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
32
|
+
...bestPracticesRules,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
36
|
+
...possibleErrorsRules,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
40
|
+
...styleRules,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
44
|
+
...variablesRules,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
48
|
+
...es6Rules,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
52
|
+
...strictRules,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
files: ['**/*.{js,mjs,cjs}'],
|
|
56
|
+
...importsRules,
|
|
57
|
+
},
|
|
58
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eslint-config-hcl",
|
|
3
|
+
"version": "0.0.3-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "基于 ESLint 9 扁平配置的基础通用 JavaScript、TypeScript、Vue 编码规范",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"author": "hechenglong <1104907547@qq.com>",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js",
|
|
11
|
+
"./typescript": "./typescript/index.js",
|
|
12
|
+
"./typescript/vue": "./typescript/vue.js",
|
|
13
|
+
"./vue": "./vue.js",
|
|
14
|
+
"./es5": "./essential/es5.js",
|
|
15
|
+
"./essential": "./essential/index.js",
|
|
16
|
+
"./essential/vue": "./essential/vue.js",
|
|
17
|
+
"./essential/typescript": "./essential/typescript/index.js",
|
|
18
|
+
"./essential/typescript/vue": "./essential/typescript/vue.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"typescript/",
|
|
23
|
+
"vue.js",
|
|
24
|
+
"essential/",
|
|
25
|
+
"rules/"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"eslint",
|
|
29
|
+
"javascript",
|
|
30
|
+
"typescript",
|
|
31
|
+
"vue",
|
|
32
|
+
"lint"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint ./",
|
|
36
|
+
"test": "mocha ./__tests__/*.test.js --timeout 5000",
|
|
37
|
+
"print-config": "eslint --print-config ./index.js > ./print-config.json"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"registry": "https://registry.npmjs.org/",
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/15272410401/front-end-coding-specification#readme",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/15272410401/front-end-coding-specification.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/15272410401/front-end-coding-specification/issues"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.24.0",
|
|
53
|
+
"@babel/eslint-parser": "^7.24.5",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.5.0",
|
|
55
|
+
"@typescript-eslint/parser": "^8.5.0",
|
|
56
|
+
"eslint": "^9.39.5",
|
|
57
|
+
"eslint-import-resolver-typescript": "^4.0.0",
|
|
58
|
+
"eslint-plugin-import": "^2.31.0",
|
|
59
|
+
"eslint-plugin-vue": "^9.33.0",
|
|
60
|
+
"mocha": "^11.7.6",
|
|
61
|
+
"typescript": "^6.0.3",
|
|
62
|
+
"vue-eslint-parser": "^9.4.3"
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "2cf5f56362c04886dc8f937985cabd5794615f4d"
|
|
65
|
+
}
|