@houheaven/eslint-config-helper 2.1.2 → 3.1.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.
Files changed (51) hide show
  1. package/README.md +177 -143
  2. package/exports.js +29 -0
  3. package/lib/html.js +88 -13
  4. package/lib/javascript-es5.js +43 -11
  5. package/lib/javascript-es6.js +51 -11
  6. package/lib/react.js +118 -0
  7. package/lib/supports/support-es5.js +25 -0
  8. package/lib/supports/support-es6.js +35 -0
  9. package/lib/supports/support-html.js +41 -0
  10. package/lib/{support/import-support.js → supports/support-import.js} +16 -11
  11. package/lib/supports/support-react-jsx.js +58 -0
  12. package/lib/supports/support-react-tsx.js +119 -0
  13. package/lib/supports/support-typescript.js +34 -0
  14. package/lib/supports/support-vue2.js +46 -0
  15. package/lib/supports/support-vue3-ts.js +65 -0
  16. package/lib/supports/support-vue3.js +46 -0
  17. package/lib/typescript.js +54 -24
  18. package/lib/vue2.js +51 -13
  19. package/lib/vue3.js +95 -14
  20. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/_deprecated.js +29 -0
  21. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/class-component.js +170 -0
  22. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/dom.js +140 -0
  23. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/fixable.js +239 -0
  24. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/jsx.js +147 -0
  25. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/prop-types.js +128 -0
  26. package/node_modules/@houheaven/eslint-config-helper-core/rules/react/suggestion.js +42 -0
  27. package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/_deprecated.js +19 -0
  28. package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/fixable.js +228 -0
  29. package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/other.js +19 -0
  30. package/node_modules/@houheaven/eslint-config-helper-core/summary.js +9 -1
  31. package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +28 -0
  32. package/package.json +17 -40
  33. package/lib/configs/format-prettier.js +0 -478
  34. package/lib/format-es5.js +0 -23
  35. package/lib/format-es6.js +0 -25
  36. package/lib/format-html.js +0 -23
  37. package/lib/format-import.js +0 -23
  38. package/lib/format-typescript.js +0 -28
  39. package/lib/format-vue2.js +0 -23
  40. package/lib/format-vue3.js +0 -23
  41. package/lib/import.js +0 -26
  42. package/lib/support/es5-support.js +0 -32
  43. package/lib/support/es6-support.js +0 -42
  44. package/lib/support/html-support.js +0 -46
  45. package/lib/support/import-bugfix.js +0 -65
  46. package/lib/support/typescript-support.js +0 -27
  47. package/lib/support/vue2-support.js +0 -43
  48. package/lib/support/vue3-support.js +0 -43
  49. package/lib/support/vue3-ts-support.js +0 -51
  50. package/lib/utils/utils.js +0 -2
  51. package/lib/vue3-ts.js +0 -32
package/README.md CHANGED
@@ -1,220 +1,252 @@
1
1
 
2
2
  # @houheaven/eslint-config-helper
3
3
 
4
- > Eslint 规则助手,基于 Eslint Legacy Config 的规则集。
4
+ > Eslint 规则助手,基于 Eslint Flat Config 的规则集。
5
5
  > 主要功能是处理 Javascript、Typescript、Vue、HTML 中的语法校验、代码格式化。
6
6
 
7
7
 
8
8
  ## 功能
9
9
 
10
- - 项目依赖于 `Eslint v8`,提供 JS 代码的校验规则
10
+ - 项目依赖于 `Eslint v9`,提供 JS 代码的校验规则
11
11
  - 内置 `@stylistic/eslint-plugin`,提供 JS、TS 代码格式化的校验规则
12
12
  - 内置 `@typescript-eslint/eslint-plugin`,提供 TS 代码的校验规则
13
13
  - 内置 `eslint-plugin-import`,提供 import 的校验规则
14
14
  - 内置 `eslint-plugin-vue`,提供 Vue 代码的校验规则
15
+ - 内置 `eslint-plugin-react`,提供 React 代码的校验规则
16
+ - 内置 `eslint-plugin-react-hooks`,提供 React Hooks 的校验规则
15
17
  - 内置 `@html-eslint/eslint-plugin`,提供 html 文件的解析和校验规则
16
18
  - 内置 `eslint-plugin-html`,提供 html 文件中 <script> 的 JS 解析能力
17
19
 
18
20
 
19
21
  ## 安装
20
22
 
21
- ```sh
22
- # 方式一
23
- npm install --dev @houheaven/eslint-config-helper@legacy
24
-
25
- # 方式二
26
- npm install --dev @houheaven/eslint-config-helper@v2
23
+ ```bash
24
+ pnpm add -D @houheaven/eslint-config-helper@next
27
25
  ```
28
26
 
27
+ ## API
28
+
29
+ 该包默认导出一个对象,包含以下内容:
30
+
31
+ - `configs`:开箱即用的预设配置,绑定了文件拓展名
32
+ - `supports`:提供特定文件的文件解析和校验规则,不与文件拓展名绑定
33
+
34
+ ### configs 预设配置列表
35
+ | 属性名 | 功能说明 | * 已绑定文件 |
36
+ | ------------------ | ------------------------------------------- | --------------------- |
37
+ | configs.es5 | 校验 JS(Es5) 代码 | `.js` `.mjs` `.cjs` |
38
+ | configs.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
39
+ | configs.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
40
+ | configs.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
41
+ | configs.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
42
+ | configs.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
43
+ | configs.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
44
+ | configs.reactTsx | 校验 React + TS + JS(Es6+)+ import 代码 | `.tsx` |
45
+ | configs.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
46
+ | configs.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
47
+
48
+ ### supports 功能列表
49
+ | 属性名 | 功能说明 | * 适用文件 |
50
+ | ------------------- | ------------------------------------------- | --------------------- |
51
+ | supports.es5 | 校验 JS(Es5) 代码 | `.js` `.mjs` `.cjs` |
52
+ | supports.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
53
+ | supports.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
54
+ | supports.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
55
+ | supports.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
56
+ | supports.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
57
+ | supports.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
58
+ | supports.reactTsx | 校验 React + TS + JS(Es6+)+ import 代码 | `.tsx` |
59
+ | supports.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
60
+ | supports.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
61
+
62
+
29
63
  ## 用法
30
64
 
31
- 我们提供了多种规则集,每个规则集只能处理单一场景,为了处理复杂场景,可以将多个规则集组合使用。
32
-
33
- | 规则集名称 | 功能说明 | 适用场景 |
34
- | ------ | ------ | ------ |
35
- | @houheaven/eslint-config-helper | `语法校验` `代码格式化` | `js/es6` `mjs` `cjs` |
36
- | @houheaven/eslint-config-helper/es6 | `语法校验` `代码格式化` | `js/es6` `mjs` `cjs` |
37
- | @houheaven/eslint-config-helper/es5 | `语法校验` `代码格式化` | `js/es5` `mjs` `cjs` |
38
- | @houheaven/eslint-config-helper/typescript | `语法校验` `代码格式化` | `ts` |
39
- | @houheaven/eslint-config-helper/import | `语法校验` `代码格式化` | `js/es6` `ts` `vue2` `vue3` |
40
- | @houheaven/eslint-config-helper/vue2 | `语法校验` `代码格式化` | `vue2` |
41
- | @houheaven/eslint-config-helper/vue3 | `语法校验` `代码格式化` | `vue3` |
42
- | @houheaven/eslint-config-helper/vue3-ts | `语法校验` `代码格式化` | `vue3` `ts` |
43
- | @houheaven/eslint-config-helper/html | `语法校验` `代码格式化` | `html` |
44
- | @houheaven/eslint-config-helper/format-es6 | `代码格式化` | `js/es6` `mjs` `cjs` |
45
- | @houheaven/eslint-config-helper/format-es5 | `代码格式化` | `js/es5` `mjs` `cjs` |
46
- | @houheaven/eslint-config-helper/format-typescript | `代码格式化` | `ts` |
47
- | @houheaven/eslint-config-helper/format-import | `代码格式化` | `js/es6` `ts` `vue2` `vue3` |
48
- | @houheaven/eslint-config-helper/format-vue2 | `代码格式化` | `vue2` |
49
- | @houheaven/eslint-config-helper/format-vue3 | `代码格式化` | `vue3` |
50
- | @houheaven/eslint-config-helper/format-html | `代码格式化` | `html` |
51
-
52
- 在 Eslint 配置文件 `.eslintrc.js` 中 `"extends"` 规则集继承数组中添加以上规则集,即可使其生效。
65
+ 方式 1:ESM
66
+ - `package.json` 设置 `type: "module"`
67
+ - 在项目根目录创建 `eslint.config.js`
68
+
69
+ 方式 2:
70
+ - 在项目根目录创建 `eslint.config.mjs`
71
+
53
72
 
54
73
  ### Javascript(ES5)
55
74
 
75
+ 校验文件范围:`.js`
76
+
56
77
  ```js
57
- module.exports = {
58
- extends: [
59
- "@houheaven/eslint-config-helper/es5"
60
- ]
61
- };
78
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
79
+
80
+ export default [
81
+ ...hhEslintConfigHelper.configs.es5,
82
+ ];
62
83
  ```
63
84
 
64
- ### Javascript(ES6)
85
+ ### Javascript(ES6+)
86
+
87
+ 校验文件范围:`.js`
65
88
 
66
89
  ```js
67
- module.exports = {
68
- extends: [
69
- "@houheaven/eslint-config-helper/es6",
70
- "@houheaven/eslint-config-helper/import"
71
- ]
72
- };
90
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
91
+
92
+ export default [
93
+ ...hhEslintConfigHelper.configs.es6,
94
+ ];
73
95
  ```
74
96
 
75
97
  ### Typescript
76
98
 
99
+ 校验文件范围:`.ts` `.js`
100
+
77
101
  ```js
78
- module.exports = {
79
- extends: [
80
- "@houheaven/eslint-config-helper/es6",
81
- "@houheaven/eslint-config-helper/import",
82
- "@houheaven/eslint-config-helper/typescript"
83
- ]
84
- };
102
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
103
+
104
+ export default [
105
+ ...hhEslintConfigHelper.configs.es6,
106
+ ...hhEslintConfigHelper.configs.typescript,
107
+ ];
85
108
  ```
86
109
 
87
110
  ### Vue2
88
111
 
112
+ 校验文件范围:`.vue` `.js`
113
+
89
114
  ```js
90
- module.exports = {
91
- extends: [
92
- "@houheaven/eslint-config-helper/es6",
93
- "@houheaven/eslint-config-helper/import",
94
- "@houheaven/eslint-config-helper/vue2"
95
- ]
96
- };
115
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
116
+
117
+ export default [
118
+ ...hhEslintConfigHelper.configs.es6,
119
+ ...hhEslintConfigHelper.configs.vue2,
120
+ ];
97
121
  ```
98
122
 
99
123
  ### Vue3
100
124
 
125
+ 校验文件范围:`.vue` `.js`
126
+
127
+ ```js
128
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
129
+
130
+ export default [
131
+ ...hhEslintConfigHelper.configs.es6,
132
+ ...hhEslintConfigHelper.configs.vue3,
133
+ ];
134
+ ```
135
+
136
+ ### Vue3 + TypeScript(推荐)
137
+
138
+ 校验文件范围:`.vue` `.ts` `.js`
139
+
101
140
  ```js
102
- module.exports = {
103
- extends: [
104
- "@houheaven/eslint-config-helper/es6",
105
- "@houheaven/eslint-config-helper/import",
106
- "@houheaven/eslint-config-helper/vue3"
107
- ]
108
- };
141
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
142
+
143
+ export default [
144
+ ...hhEslintConfigHelper.configs.es6,
145
+ ...hhEslintConfigHelper.configs.typescript,
146
+ ...hhEslintConfigHelper.configs.vue3Ts,
147
+ ];
109
148
  ```
110
149
 
111
- ### Vue3 + Typescript
150
+ ### React(JSX)
151
+
152
+ 校验文件范围:`.jsx`
112
153
 
113
154
  ```js
114
- module.exports = {
115
- extends: [
116
- "@houheaven/eslint-config-helper/es6",
117
- "@houheaven/eslint-config-helper/import",
118
- "@houheaven/eslint-config-helper/typescript",
119
- "@houheaven/eslint-config-helper/vue3-ts"
120
- ]
121
- };
155
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
156
+
157
+ export default [
158
+ ...hhEslintConfigHelper.configs.reactJsx,
159
+ ];
122
160
  ```
123
161
 
124
- ### html
162
+ ### React + TypeScript(TSX,推荐)
163
+
164
+ 校验文件范围:`.tsx`
125
165
 
126
166
  ```js
127
- module.exports = {
128
- extends: [
129
- "@houheaven/eslint-config-helper/html"
130
- ]
131
- };
167
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
168
+
169
+ export default [
170
+ ...hhEslintConfigHelper.configs.reactTsx,
171
+ ];
132
172
  ```
133
173
 
134
174
  ### html + ES5
135
175
 
176
+ 校验文件范围:`.html` `.js`
177
+
136
178
  ```js
137
- module.exports = {
138
- extends: [
139
- "@houheaven/eslint-config-helper/es5",
140
- "@houheaven/eslint-config-helper/html"
141
- ]
142
- };
179
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
180
+
181
+ export default [
182
+ ...hhEslintConfigHelper.configs.es5,
183
+ ...hhEslintConfigHelper.configs.htmlEs5,
184
+ ];
143
185
  ```
144
186
 
145
187
  ### html + ES6
146
188
 
189
+ 校验文件范围:`.html` `.js`
190
+
147
191
  ```js
148
- module.exports = {
149
- extends: [
150
- "@houheaven/eslint-config-helper/es6",
151
- "@houheaven/eslint-config-helper/import",
152
- "@houheaven/eslint-config-helper/html"
153
- ]
154
- };
192
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
193
+
194
+ export default [
195
+ ...hhEslintConfigHelper.configs.es6,
196
+ ...hhEslintConfigHelper.configs.htmlEs6,
197
+ ];
155
198
  ```
156
199
 
200
+ ### 自定义覆盖
157
201
 
158
- ## 修改 Eslint 规则
202
+ ```js
203
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
204
+
205
+ export default [
206
+ ...hhEslintConfigHelper.configs.es6,
207
+ {
208
+ files: ["src/example.js"],
209
+ rules: {
210
+ "no-console": "off",
211
+ },
212
+ },
213
+ ];
214
+ ```
159
215
 
160
- 在 Eslint 配置文件中的 `"rules"` 里添加规则。
216
+ ### supports 应用场景
161
217
 
162
218
  ```js
163
- // .eslintrc.js
164
-
165
- module.exports = {
166
- // eslint 其他配置
167
- // ……
168
- rules: {
169
- // ES5 规则
170
- "quotes": ["warn", "double"],
171
- "no-multiple-empty-lines": ["warn", {
172
- max: 2,
173
- maxBOF: 1,
174
- maxEOF: 1
175
- }],
176
-
177
- // ES6 规则
178
- "no-var": "warn",
179
- "arrow-spacing": ["warn", {
180
- before: true,
181
- after: true,
182
- }],
183
-
184
- // typescript 规则
185
- "@typescript-eslint/consistent-type-definitions": ["warn", "interface"],
186
- "@typescript-eslint/triple-slash-reference": ["error", {
187
- lib: "always",
188
- path: "never",
189
- types: "prefer-import",
190
- }],
191
-
192
- // import 规则
193
- "import/first": "error",
194
- "import/no-unresolved": ["error", {
195
- commonjs: true,
196
- caseSensitive: true,
197
- }],
198
-
199
- // Vue2 规则
200
- "vue/eqeqeq": ["error", "always", { null: "ignore" }],
201
- "vue/custom-event-name-casing": ["warn", "kebab-case"],
202
- "vue/no-multiple-template-root": "error",
203
-
204
- // Vue3 规则
205
- "vue/define-emits-declaration": ["error", "type-based"],
206
- "vue/next-tick-style": ["warn", "promise"],
207
-
208
- // html 规则
209
- "@html-eslint/require-title": "error",
210
- "@html-eslint/no-duplicate-id": "error",
211
- }
212
- };
219
+ import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
220
+
221
+ export default [
222
+ {
223
+ files: ["**/*.vue"],
224
+ ...hhEslintConfigHelper.supports.vue3,
225
+ },
226
+ {
227
+ files: ["src/example.js"],
228
+ ...hhEslintConfigHelper.supports.es6,
229
+ rules: {
230
+ ...hhEslintConfigHelper.supports.es6.rules,
231
+ "no-console": "off",
232
+ },
233
+ },
234
+ ];
213
235
  ```
214
236
 
237
+ ## 环境要求
238
+
239
+ - Node.js >= 18
240
+ - ESLint ^9.0.0 || ^10.0.0
241
+
242
+
243
+ ## 相关文档
244
+
215
245
  - 查看 [`Eslint 规则文档`](https://www.npmjs.com/package/eslint)
216
246
  - 查看 [`eslint-plugin-import 规则文档`](https://www.npmjs.com/package/eslint-plugin-import)
217
247
  - 查看 [`eslint-plugin-vue 规则文档`](https://eslint.vuejs.org/rules/)
248
+ - 查看 [`eslint-plugin-react 规则文档`](https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules)
249
+ - 查看 [`eslint-plugin-react-hooks 规则文档`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
218
250
  - 查看 [`@html-eslint 规则文档`](https://html-eslint.org/docs/getting-started/)
219
251
  - 查看 [`@typescript-eslint/eslint-plugin 规则文档`](https://typescript-eslint.io/rules/)
220
252
 
@@ -233,6 +265,8 @@ module.exports = {
233
265
  - [`eslint`](https://www.npmjs.com/package/eslint)
234
266
  - [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
235
267
  - [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue)
268
+ - [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react)
269
+ - [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
236
270
  - [`eslint-plugin-html`](https://www.npmjs.com/package/eslint-plugin-html)
237
271
  - [`eslint-import-resolver-alias`](https://www.npmjs.com/package/eslint-import-resolver-alias)
238
272
  - [`eslint-import-resolver-node`](https://www.npmjs.com/package/eslint-import-resolver-node)
package/exports.js ADDED
@@ -0,0 +1,29 @@
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
+ import react from "./lib/react.js";
9
+
10
+ export default {
11
+ configs: {
12
+ ...es5.configs,
13
+ ...es6.configs,
14
+ ...typescript.configs,
15
+ ...html.configs,
16
+ ...vue2.configs,
17
+ ...vue3.configs,
18
+ ...react.configs,
19
+ },
20
+ supports: {
21
+ ...es5.supports,
22
+ ...es6.supports,
23
+ ...typescript.supports,
24
+ ...html.supports,
25
+ ...vue2.supports,
26
+ ...vue3.supports,
27
+ ...react.supports,
28
+ },
29
+ };
package/lib/html.js CHANGED
@@ -5,22 +5,97 @@
5
5
  // - @html-eslint/eslint-plugin 定制规则
6
6
  // ===============================================================================
7
7
 
8
- // 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
9
- require("@rushstack/eslint-patch/modern-module-resolution");
10
-
11
- const utils = require("@houheaven/eslint-config-helper-core");
12
-
13
- module.exports = {
14
- // 当 eslint-disable 注释配置未使用时,是否报错
15
- reportUnusedDisableDirectives: true,
16
- // 继承配置文件
17
- extends: [
18
- // html 支持
19
- "./support/html-support.js",
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
+ };
@@ -5,22 +5,54 @@
5
5
  // - Eslint ES5 定制规则
6
6
  // ==========================================================
7
7
 
8
- // 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
9
- require("@rushstack/eslint-patch/modern-module-resolution");
8
+ import utils from "@houheaven/eslint-config-helper-core";
9
+ import supportEs5 from "./supports/support-es5.js";
10
10
 
11
- const utils = require("@houheaven/eslint-config-helper-core");
12
-
13
- module.exports = {
14
- // 当 eslint-disable 注释配置未使用时,是否报错
15
- reportUnusedDisableDirectives: true,
16
- // 继承配置文件
17
- extends: [
18
- // Eslint ES5 支持
19
- "./support/es5-support.js",
11
+ // 基础配置
12
+ const jsCommonConfig = {
13
+ files: [
14
+ // js 文件
15
+ "**/*.js",
16
+ // Nodejs CommonJS 模块文件
17
+ "**/*.cjs",
18
+ // Nodejs ESM 模块文件
19
+ "**/*.mjs",
20
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
+ },
21
35
  // 规则
22
36
  rules: {
23
37
  // Eslint ES5 规则
24
38
  ...utils.rules.es5,
25
39
  },
26
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
+ };