@houheaven/eslint-config-helper 2.1.0 → 3.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/README.md +155 -149
- package/exports.js +26 -0
- package/lib/html.js +88 -13
- package/lib/javascript-es5.js +43 -10
- package/lib/javascript-es6.js +51 -11
- package/lib/supports/support-es5.js +25 -0
- package/lib/supports/support-es6.js +35 -0
- package/lib/supports/support-html.js +41 -0
- package/lib/{support/import-support.js → supports/support-import.js} +16 -11
- package/lib/supports/support-typescript.js +34 -0
- package/lib/supports/support-vue2.js +46 -0
- package/lib/supports/support-vue3-ts.js +65 -0
- package/lib/supports/support-vue3.js +46 -0
- package/lib/typescript.js +54 -24
- package/lib/vue2.js +51 -13
- package/lib/vue3.js +95 -14
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +0 -15
- package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/stylistic.js +24 -0
- package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +1 -0
- package/package.json +17 -43
- package/lib/configs/format-prettier.js +0 -478
- package/lib/format-es5.js +0 -23
- package/lib/format-es6.js +0 -25
- package/lib/format-html.js +0 -23
- package/lib/format-import.js +0 -23
- package/lib/format-typescript.js +0 -28
- package/lib/format-vue2.js +0 -23
- package/lib/format-vue3.js +0 -23
- package/lib/import.js +0 -26
- package/lib/support/es5-support.js +0 -29
- package/lib/support/es6-support.js +0 -39
- package/lib/support/html-support.js +0 -38
- package/lib/support/import-bugfix.js +0 -65
- package/lib/support/typescript-support.js +0 -27
- package/lib/support/vue2-support.js +0 -43
- package/lib/support/vue3-support.js +0 -43
- package/lib/support/vue3-ts-support.js +0 -51
- package/lib/utils/utils.js +0 -2
- package/lib/vue3-ts.js +0 -32
package/README.md
CHANGED
|
@@ -1,211 +1,217 @@
|
|
|
1
1
|
|
|
2
2
|
# @houheaven/eslint-config-helper
|
|
3
3
|
|
|
4
|
-
> Eslint
|
|
5
|
-
> 主要功能是处理
|
|
4
|
+
> Eslint 规则助手,基于 Eslint Flat Config 的规则集。
|
|
5
|
+
> 主要功能是处理 Javascript、Typescript、Vue、HTML 中的语法校验、代码格式化。
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
- 内置
|
|
12
|
-
- 内置 `@
|
|
13
|
-
- 内置
|
|
14
|
-
-
|
|
8
|
+
## 功能
|
|
9
|
+
|
|
10
|
+
- 项目依赖于 `Eslint v9`,提供 JS 代码的校验规则
|
|
11
|
+
- 内置 `@stylistic/eslint-plugin`,提供 JS、TS 代码格式化的校验规则
|
|
12
|
+
- 内置 `@typescript-eslint/eslint-plugin`,提供 TS 代码的校验规则
|
|
13
|
+
- 内置 `eslint-plugin-import`,提供 import 的校验规则
|
|
14
|
+
- 内置 `eslint-plugin-vue`,提供 Vue 代码的校验规则
|
|
15
|
+
- 内置 `@html-eslint/eslint-plugin`,提供 html 文件的解析和校验规则
|
|
16
|
+
- 内置 `eslint-plugin-html`,提供 html 文件中 <script> 的 JS 解析能力
|
|
15
17
|
|
|
16
18
|
|
|
17
19
|
## 安装
|
|
18
20
|
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add -D @houheaven/eslint-config-helper@next
|
|
21
23
|
```
|
|
22
24
|
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
该包默认导出一个对象,包含以下内容:
|
|
28
|
+
|
|
29
|
+
- `configs`:开箱即用的预设配置,绑定了文件拓展名
|
|
30
|
+
- `supports`:提供特定文件的文件解析和校验规则,不与文件拓展名绑定
|
|
31
|
+
|
|
32
|
+
### configs 预设配置列表
|
|
33
|
+
| 属性名 | 功能说明 | * 已绑定文件 |
|
|
34
|
+
| ------------------ | ------------------------------------------- | --------------------- |
|
|
35
|
+
| configs.es5 | 校验 JS(Es5) 代码 | `.js` `.mjs` `.cjs` |
|
|
36
|
+
| configs.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
|
|
37
|
+
| configs.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
|
|
38
|
+
| configs.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
|
|
39
|
+
| configs.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
|
|
40
|
+
| configs.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
41
|
+
| configs.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
|
|
42
|
+
| configs.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
|
|
43
|
+
|
|
44
|
+
### supports 功能列表
|
|
45
|
+
| 属性名 | 功能说明 | * 适用文件 |
|
|
46
|
+
| ------------------- | ------------------------------------------- | --------------------- |
|
|
47
|
+
| supports.es5 | 校验 JS(Es5) 代码 | `.js` `.mjs` `.cjs` |
|
|
48
|
+
| supports.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
|
|
49
|
+
| supports.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
|
|
50
|
+
| supports.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
|
|
51
|
+
| supports.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
|
|
52
|
+
| supports.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
53
|
+
| supports.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
|
|
54
|
+
| supports.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
|
|
55
|
+
|
|
56
|
+
|
|
23
57
|
## 用法
|
|
24
58
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
| @houheaven/eslint-config-helper/typescript | `语法校验` `代码格式化` | `ts` |
|
|
33
|
-
| @houheaven/eslint-config-helper/import | `语法校验` `代码格式化` | `js/es6` `ts` `vue2` `vue3` |
|
|
34
|
-
| @houheaven/eslint-config-helper/vue2 | `语法校验` `代码格式化` | `vue2` |
|
|
35
|
-
| @houheaven/eslint-config-helper/vue3 | `语法校验` `代码格式化` | `vue3` |
|
|
36
|
-
| @houheaven/eslint-config-helper/vue3-ts | `语法校验` `代码格式化` | `vue3` `ts` |
|
|
37
|
-
| @houheaven/eslint-config-helper/html | `语法校验` `代码格式化` | `html` |
|
|
38
|
-
| @houheaven/eslint-config-helper/format-es6 | `代码格式化` | `js/es6` `mjs` `cjs` |
|
|
39
|
-
| @houheaven/eslint-config-helper/format-es5 | `代码格式化` | `js/es5` `mjs` `cjs` |
|
|
40
|
-
| @houheaven/eslint-config-helper/format-typescript | `代码格式化` | `ts` |
|
|
41
|
-
| @houheaven/eslint-config-helper/format-import | `代码格式化` | `js/es6` `ts` `vue2` `vue3` |
|
|
42
|
-
| @houheaven/eslint-config-helper/format-vue2 | `代码格式化` | `vue2` |
|
|
43
|
-
| @houheaven/eslint-config-helper/format-vue3 | `代码格式化` | `vue3` |
|
|
44
|
-
| @houheaven/eslint-config-helper/format-html | `代码格式化` | `html` |
|
|
45
|
-
|
|
46
|
-
在 Eslint 配置文件 `.eslintrc.js` 中 `"extends"` 规则集继承数组中添加以上规则集,即可使其生效。
|
|
59
|
+
方式 1:ESM
|
|
60
|
+
- `package.json` 设置 `type: "module"`
|
|
61
|
+
- 在项目根目录创建 `eslint.config.js`
|
|
62
|
+
|
|
63
|
+
方式 2:
|
|
64
|
+
- 在项目根目录创建 `eslint.config.mjs`
|
|
65
|
+
|
|
47
66
|
|
|
48
67
|
### Javascript(ES5)
|
|
49
68
|
|
|
69
|
+
校验文件范围:`.js`
|
|
70
|
+
|
|
50
71
|
```js
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
73
|
+
|
|
74
|
+
export default [
|
|
75
|
+
...hhEslintConfigHelper.configs.es5,
|
|
76
|
+
];
|
|
56
77
|
```
|
|
57
78
|
|
|
58
|
-
### Javascript(ES6
|
|
79
|
+
### Javascript(ES6+)
|
|
80
|
+
|
|
81
|
+
校验文件范围:`.js`
|
|
59
82
|
|
|
60
83
|
```js
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
84
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
85
|
+
|
|
86
|
+
export default [
|
|
87
|
+
...hhEslintConfigHelper.configs.es6,
|
|
88
|
+
];
|
|
67
89
|
```
|
|
68
90
|
|
|
69
91
|
### Typescript
|
|
70
92
|
|
|
93
|
+
校验文件范围:`.ts` `.js`
|
|
94
|
+
|
|
71
95
|
```js
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
96
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
97
|
+
|
|
98
|
+
export default [
|
|
99
|
+
...hhEslintConfigHelper.configs.es6,
|
|
100
|
+
...hhEslintConfigHelper.configs.typescript,
|
|
101
|
+
];
|
|
79
102
|
```
|
|
80
103
|
|
|
81
104
|
### Vue2
|
|
82
105
|
|
|
106
|
+
校验文件范围:`.vue` `.js`
|
|
107
|
+
|
|
83
108
|
```js
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
109
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
110
|
+
|
|
111
|
+
export default [
|
|
112
|
+
...hhEslintConfigHelper.configs.es6,
|
|
113
|
+
...hhEslintConfigHelper.configs.vue2,
|
|
114
|
+
];
|
|
91
115
|
```
|
|
92
116
|
|
|
93
117
|
### Vue3
|
|
94
118
|
|
|
95
|
-
|
|
96
|
-
module.exports = {
|
|
97
|
-
extends: [
|
|
98
|
-
"@houheaven/eslint-config-helper/es6",
|
|
99
|
-
"@houheaven/eslint-config-helper/import",
|
|
100
|
-
"@houheaven/eslint-config-helper/vue3"
|
|
101
|
-
]
|
|
102
|
-
};
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Vue3 + Typescript
|
|
119
|
+
校验文件范围:`.vue` `.js`
|
|
106
120
|
|
|
107
121
|
```js
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
]
|
|
115
|
-
};
|
|
122
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
123
|
+
|
|
124
|
+
export default [
|
|
125
|
+
...hhEslintConfigHelper.configs.es6,
|
|
126
|
+
...hhEslintConfigHelper.configs.vue3,
|
|
127
|
+
];
|
|
116
128
|
```
|
|
117
129
|
|
|
118
|
-
###
|
|
130
|
+
### Vue3 + TypeScript(推荐)
|
|
131
|
+
|
|
132
|
+
校验文件范围:`.vue` `.ts` `.js`
|
|
119
133
|
|
|
120
134
|
```js
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
136
|
+
|
|
137
|
+
export default [
|
|
138
|
+
...hhEslintConfigHelper.configs.es6,
|
|
139
|
+
...hhEslintConfigHelper.configs.typescript,
|
|
140
|
+
...hhEslintConfigHelper.configs.vue3Ts,
|
|
141
|
+
];
|
|
126
142
|
```
|
|
127
143
|
|
|
128
144
|
### html + ES5
|
|
129
145
|
|
|
146
|
+
校验文件范围:`.html` `.js`
|
|
147
|
+
|
|
130
148
|
```js
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
150
|
+
|
|
151
|
+
export default [
|
|
152
|
+
...hhEslintConfigHelper.configs.es5,
|
|
153
|
+
...hhEslintConfigHelper.configs.htmlEs5,
|
|
154
|
+
];
|
|
137
155
|
```
|
|
138
156
|
|
|
139
157
|
### html + ES6
|
|
140
158
|
|
|
159
|
+
校验文件范围:`.html` `.js`
|
|
160
|
+
|
|
141
161
|
```js
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
162
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
163
|
+
|
|
164
|
+
export default [
|
|
165
|
+
...hhEslintConfigHelper.configs.es6,
|
|
166
|
+
...hhEslintConfigHelper.configs.htmlEs6,
|
|
167
|
+
];
|
|
149
168
|
```
|
|
150
169
|
|
|
170
|
+
### 自定义覆盖
|
|
151
171
|
|
|
152
|
-
|
|
172
|
+
```js
|
|
173
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
174
|
+
|
|
175
|
+
export default [
|
|
176
|
+
...hhEslintConfigHelper.configs.es6,
|
|
177
|
+
{
|
|
178
|
+
files: ["src/example.js"],
|
|
179
|
+
rules: {
|
|
180
|
+
"no-console": "off",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
```
|
|
153
185
|
|
|
154
|
-
|
|
186
|
+
### supports 应用场景
|
|
155
187
|
|
|
156
188
|
```js
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
"arrow-spacing": ["warn", {
|
|
174
|
-
before: true,
|
|
175
|
-
after: true,
|
|
176
|
-
}],
|
|
177
|
-
|
|
178
|
-
// typescript 规则
|
|
179
|
-
"@typescript-eslint/consistent-type-definitions": ["warn", "interface"],
|
|
180
|
-
"@typescript-eslint/triple-slash-reference": ["error", {
|
|
181
|
-
lib: "always",
|
|
182
|
-
path: "never",
|
|
183
|
-
types: "prefer-import",
|
|
184
|
-
}],
|
|
185
|
-
|
|
186
|
-
// import 规则
|
|
187
|
-
"import/first": "error",
|
|
188
|
-
"import/no-unresolved": ["error", {
|
|
189
|
-
commonjs: true,
|
|
190
|
-
caseSensitive: true,
|
|
191
|
-
}],
|
|
192
|
-
|
|
193
|
-
// Vue2 规则
|
|
194
|
-
"vue/eqeqeq": ["error", "always", { null: "ignore" }],
|
|
195
|
-
"vue/custom-event-name-casing": ["warn", "kebab-case"],
|
|
196
|
-
"vue/no-multiple-template-root": "error",
|
|
197
|
-
|
|
198
|
-
// Vue3 规则
|
|
199
|
-
"vue/define-emits-declaration": ["error", "type-based"],
|
|
200
|
-
"vue/next-tick-style": ["warn", "promise"],
|
|
201
|
-
|
|
202
|
-
// html 规则
|
|
203
|
-
"@html-eslint/require-title": "error",
|
|
204
|
-
"@html-eslint/no-duplicate-id": "error",
|
|
205
|
-
}
|
|
206
|
-
};
|
|
189
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
190
|
+
|
|
191
|
+
export default [
|
|
192
|
+
{
|
|
193
|
+
files: ["**/*.vue"],
|
|
194
|
+
...hhEslintConfigHelper.supports.vue3,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
files: ["src/example.js"],
|
|
198
|
+
...hhEslintConfigHelper.supports.es6,
|
|
199
|
+
rules: {
|
|
200
|
+
...hhEslintConfigHelper.supports.es6.rules,
|
|
201
|
+
"no-console": "off",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
];
|
|
207
205
|
```
|
|
208
206
|
|
|
207
|
+
## 环境要求
|
|
208
|
+
|
|
209
|
+
- Node.js >= 18
|
|
210
|
+
- ESLint ^9.0.0 || ^10.0.0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
## 相关文档
|
|
214
|
+
|
|
209
215
|
- 查看 [`Eslint 规则文档`](https://www.npmjs.com/package/eslint)
|
|
210
216
|
- 查看 [`eslint-plugin-import 规则文档`](https://www.npmjs.com/package/eslint-plugin-import)
|
|
211
217
|
- 查看 [`eslint-plugin-vue 规则文档`](https://eslint.vuejs.org/rules/)
|
package/exports.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import es5 from "./lib/javascript-es5.js";
|
|
3
|
+
import es6 from "./lib/javascript-es6.js";
|
|
4
|
+
import typescript from "./lib/typescript.js";
|
|
5
|
+
import html from "./lib/html.js";
|
|
6
|
+
import vue2 from "./lib/vue2.js";
|
|
7
|
+
import vue3 from "./lib/vue3.js";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
configs: {
|
|
11
|
+
...es5.configs,
|
|
12
|
+
...es6.configs,
|
|
13
|
+
...typescript.configs,
|
|
14
|
+
...html.configs,
|
|
15
|
+
...vue2.configs,
|
|
16
|
+
...vue3.configs,
|
|
17
|
+
},
|
|
18
|
+
supports: {
|
|
19
|
+
...es5.supports,
|
|
20
|
+
...es6.supports,
|
|
21
|
+
...typescript.supports,
|
|
22
|
+
...html.supports,
|
|
23
|
+
...vue2.supports,
|
|
24
|
+
...vue3.supports,
|
|
25
|
+
},
|
|
26
|
+
};
|
package/lib/html.js
CHANGED
|
@@ -5,22 +5,97 @@
|
|
|
5
5
|
// - @html-eslint/eslint-plugin 定制规则
|
|
6
6
|
// ===============================================================================
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
"
|
|
20
|
-
|
|
8
|
+
import utils from "@houheaven/eslint-config-helper-core";
|
|
9
|
+
import supportHtml from "./supports/support-html.js";
|
|
10
|
+
import supportEs5 from "./supports/support-es5.js";
|
|
11
|
+
import supportEs6 from "./supports/support-es6.js";
|
|
12
|
+
import supportImport from "./supports/support-import.js";
|
|
13
|
+
|
|
14
|
+
// 基础配置
|
|
15
|
+
const htmlCommonConfig = {
|
|
16
|
+
files: ["**/*.html", "**/*.htm", "**/*.php"],
|
|
17
|
+
linterOptions: {
|
|
18
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
19
|
+
reportUnusedDisableDirectives: "warn",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// 基础支持:校验 html、ES5 规则
|
|
24
|
+
const supportHtmlEs5 = {
|
|
25
|
+
plugins: {
|
|
26
|
+
...supportHtml.plugins,
|
|
27
|
+
...supportEs5.plugins,
|
|
28
|
+
},
|
|
29
|
+
languageOptions: {
|
|
30
|
+
...supportHtml.languageOptions,
|
|
31
|
+
...supportEs5.languageOptions,
|
|
32
|
+
},
|
|
33
|
+
settings: {
|
|
34
|
+
...supportHtml.settings,
|
|
35
|
+
},
|
|
21
36
|
// 规则
|
|
22
37
|
rules: {
|
|
38
|
+
// Eslint 基础规则
|
|
39
|
+
...utils.rules.es5,
|
|
23
40
|
// html 规则
|
|
41
|
+
...supportHtml.rules,
|
|
24
42
|
...utils.rules.html,
|
|
25
43
|
},
|
|
26
44
|
};
|
|
45
|
+
|
|
46
|
+
// 基础支持:校验 html、ES6 规则
|
|
47
|
+
const supportHtmlEs6 = {
|
|
48
|
+
plugins: {
|
|
49
|
+
...supportHtml.plugins,
|
|
50
|
+
...supportEs6.plugins,
|
|
51
|
+
...supportImport.plugins,
|
|
52
|
+
},
|
|
53
|
+
languageOptions: {
|
|
54
|
+
...supportHtml.languageOptions,
|
|
55
|
+
...supportEs6.languageOptions,
|
|
56
|
+
},
|
|
57
|
+
settings: {
|
|
58
|
+
...supportHtml.settings,
|
|
59
|
+
...supportImport.settings,
|
|
60
|
+
},
|
|
61
|
+
// 规则
|
|
62
|
+
rules: {
|
|
63
|
+
// Eslint 基础规则
|
|
64
|
+
...utils.rules.es5,
|
|
65
|
+
...utils.rules.es6,
|
|
66
|
+
// eslint-plugin-import 规则
|
|
67
|
+
...utils.rules.import,
|
|
68
|
+
// html 规则
|
|
69
|
+
...supportHtml.rules,
|
|
70
|
+
...utils.rules.html,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 预设配置:校验 html 文件的 html、ES5 规则
|
|
75
|
+
const htmlEs5Config = {
|
|
76
|
+
name: "@houheaven/eslint-config-helper/html-es5",
|
|
77
|
+
...htmlCommonConfig,
|
|
78
|
+
...supportHtmlEs5,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// 预设配置:校验 html 文件的 html、ES6 规则
|
|
82
|
+
const htmlEs6Config = {
|
|
83
|
+
name: "@houheaven/eslint-config-helper/html-es6",
|
|
84
|
+
...htmlCommonConfig,
|
|
85
|
+
...supportHtmlEs6,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
supports: {
|
|
90
|
+
htmlEs5: supportHtmlEs5,
|
|
91
|
+
htmlEs6: supportHtmlEs6,
|
|
92
|
+
},
|
|
93
|
+
configs: {
|
|
94
|
+
htmlEs5: [
|
|
95
|
+
htmlEs5Config,
|
|
96
|
+
],
|
|
97
|
+
htmlEs6: [
|
|
98
|
+
htmlEs6Config,
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
};
|
package/lib/javascript-es5.js
CHANGED
|
@@ -5,21 +5,54 @@
|
|
|
5
5
|
// - Eslint ES5 定制规则
|
|
6
6
|
// ==========================================================
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import utils from "@houheaven/eslint-config-helper-core";
|
|
9
|
+
import supportEs5 from "./supports/support-es5.js";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
"
|
|
11
|
+
// 基础配置
|
|
12
|
+
const jsCommonConfig = {
|
|
13
|
+
files: [
|
|
14
|
+
// js 文件
|
|
15
|
+
"**/*.js",
|
|
16
|
+
// Nodejs CommonJS 模块文件
|
|
17
|
+
"**/*.cjs",
|
|
18
|
+
// Nodejs ESM 模块文件
|
|
19
|
+
"**/*.mjs",
|
|
19
20
|
],
|
|
21
|
+
linterOptions: {
|
|
22
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
23
|
+
reportUnusedDisableDirectives: "warn",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 基础支持:校验 ES5 规则
|
|
28
|
+
const supportJsEs5 = {
|
|
29
|
+
plugins: {
|
|
30
|
+
...supportEs5.plugins,
|
|
31
|
+
},
|
|
32
|
+
languageOptions: {
|
|
33
|
+
...supportEs5.languageOptions,
|
|
34
|
+
},
|
|
20
35
|
// 规则
|
|
21
36
|
rules: {
|
|
22
37
|
// Eslint ES5 规则
|
|
23
38
|
...utils.rules.es5,
|
|
24
39
|
},
|
|
25
40
|
};
|
|
41
|
+
|
|
42
|
+
// 预设配置:校验 js 文件的 ES5 规则
|
|
43
|
+
const jsEs5Config = {
|
|
44
|
+
name: "@houheaven/eslint-config-helper/es5",
|
|
45
|
+
...jsCommonConfig,
|
|
46
|
+
...supportJsEs5,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
supports: {
|
|
51
|
+
es5: supportJsEs5,
|
|
52
|
+
},
|
|
53
|
+
configs: {
|
|
54
|
+
es5: [
|
|
55
|
+
jsEs5Config,
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
package/lib/javascript-es6.js
CHANGED
|
@@ -4,25 +4,65 @@
|
|
|
4
4
|
// ----------------------------------------------------------
|
|
5
5
|
// - Eslint ES5 定制规则
|
|
6
6
|
// - Eslint ES6+ 定制规则
|
|
7
|
+
// - eslint-plugin-import 定制规则
|
|
7
8
|
// ==========================================================
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
import utils from "@houheaven/eslint-config-helper-core";
|
|
11
|
+
import supportEs6 from "./supports/support-es6.js";
|
|
12
|
+
import supportImport from "./supports/support-import.js";
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
"
|
|
14
|
+
// 基础配置
|
|
15
|
+
const jsCommonConfig = {
|
|
16
|
+
files: [
|
|
17
|
+
// js 文件
|
|
18
|
+
"**/*.js",
|
|
19
|
+
// Nodejs CommonJS 模块文件
|
|
20
|
+
"**/*.cjs",
|
|
21
|
+
// Nodejs ESM 模块文件
|
|
22
|
+
"**/*.mjs",
|
|
21
23
|
],
|
|
24
|
+
linterOptions: {
|
|
25
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
26
|
+
reportUnusedDisableDirectives: "warn",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// 基础支持:校验 ES5、ES6、import 规则
|
|
31
|
+
const supportJsEs6 = {
|
|
32
|
+
plugins: {
|
|
33
|
+
...supportImport.plugins,
|
|
34
|
+
...supportEs6.plugins,
|
|
35
|
+
},
|
|
36
|
+
languageOptions: {
|
|
37
|
+
...supportEs6.languageOptions,
|
|
38
|
+
},
|
|
39
|
+
settings: {
|
|
40
|
+
...supportImport.settings,
|
|
41
|
+
},
|
|
22
42
|
// 规则
|
|
23
43
|
rules: {
|
|
24
44
|
// Eslint ES6 规则
|
|
25
45
|
...utils.rules.es5,
|
|
26
46
|
...utils.rules.es6,
|
|
47
|
+
// eslint-plugin-import 规则
|
|
48
|
+
...utils.rules.import,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 预设配置:校验 js 文件的 ES5、ES6、import 规则
|
|
53
|
+
const jsEs6Config = {
|
|
54
|
+
name: "@houheaven/eslint-config-helper/es6",
|
|
55
|
+
...jsCommonConfig,
|
|
56
|
+
...supportJsEs6,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
supports: {
|
|
61
|
+
es6: supportJsEs6,
|
|
62
|
+
},
|
|
63
|
+
configs: {
|
|
64
|
+
es6: [
|
|
65
|
+
jsEs6Config,
|
|
66
|
+
],
|
|
27
67
|
},
|
|
28
68
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/support-es5
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - 解析 ES5 语法
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
import globals from "globals";
|
|
9
|
+
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
10
|
+
|
|
11
|
+
const supportEs5 = {
|
|
12
|
+
plugins: {
|
|
13
|
+
"@stylistic": pluginStylistic,
|
|
14
|
+
},
|
|
15
|
+
languageOptions: {
|
|
16
|
+
sourceType: "script", // 指定代码的来源类型,"script"(默认)表示 ESLint 会在全局作用域的脚本上下文中解析代码
|
|
17
|
+
ecmaVersion: 5, // 指定 ECMAScript 版本,5 表示 ECMAScript 5
|
|
18
|
+
globals: {
|
|
19
|
+
...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
20
|
+
...globals.jquery, // jQuery 环境,启用 jQuery 环境的全局变量和作用域规则($、jQuery 等)
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default supportEs5;
|