@houheaven/eslint-config-helper 3.0.0 → 3.2.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 +50 -0
- package/exports.js +3 -0
- package/lib/react.js +118 -0
- package/lib/supports/support-react-jsx.js +58 -0
- package/lib/supports/support-react-tsx.js +119 -0
- package/lib/supports/support-vue2-ts.js +65 -0
- package/lib/vue2.js +42 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/_deprecated.js +29 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/class-component.js +170 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/dom.js +140 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/fixable.js +239 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/jsx.js +147 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/prop-types.js +128 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react/suggestion.js +42 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/_deprecated.js +19 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/fixable.js +228 -0
- package/node_modules/@houheaven/eslint-config-helper-core/rules/react-hooks/other.js +19 -0
- package/node_modules/@houheaven/eslint-config-helper-core/summary.js +9 -1
- package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +28 -0
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
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
|
|
|
@@ -36,8 +38,11 @@ pnpm add -D @houheaven/eslint-config-helper@next
|
|
|
36
38
|
| configs.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
|
|
37
39
|
| configs.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
|
|
38
40
|
| configs.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
|
|
41
|
+
| configs.vue2Ts | 校验 Vue2 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
39
42
|
| configs.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
|
|
40
43
|
| configs.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
44
|
+
| configs.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
|
|
45
|
+
| configs.reactTsx | 校验 React + TS + JS(Es6+)+ import 代码 | `.tsx` |
|
|
41
46
|
| configs.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
|
|
42
47
|
| configs.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
|
|
43
48
|
|
|
@@ -48,8 +53,11 @@ pnpm add -D @houheaven/eslint-config-helper@next
|
|
|
48
53
|
| supports.es6 | 校验 JS(Es6+)+ import 代码 | `.js` `.mjs` `.cjs` |
|
|
49
54
|
| supports.typescript | 校验 TS + JS(Es6+)+ import 代码 | `.ts` |
|
|
50
55
|
| supports.vue2 | 校验 Vue2 + JS(Es6+)+ import 代码 | `.vue` |
|
|
56
|
+
| supports.vue2Ts | 校验 Vue2 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
51
57
|
| supports.vue3 | 校验 Vue3 + JS(Es6+)+ import 代码 | `.vue` |
|
|
52
58
|
| supports.vue3Ts | 校验 Vue3 + TS + JS(Es6+)+ import 代码 | `.vue` |
|
|
59
|
+
| supports.reactJsx | 校验 React + JS(Es6+)+ import 代码 | `.jsx` |
|
|
60
|
+
| supports.reactTsx | 校验 React + TS + JS(Es6+)+ import 代码 | `.tsx` |
|
|
53
61
|
| supports.htmlEs5 | 校验 html 和 <script> 中的 JS(Es5) 代码 | `.html` `.htm` `.php` |
|
|
54
62
|
| supports.htmlEs6 | 校验 html 和 <script> 中的 JS(Es6+) 代码 | `.html` `.htm` `.php` |
|
|
55
63
|
|
|
@@ -114,6 +122,20 @@ export default [
|
|
|
114
122
|
];
|
|
115
123
|
```
|
|
116
124
|
|
|
125
|
+
### Vue2 + TypeScript
|
|
126
|
+
|
|
127
|
+
校验文件范围:`.vue` `.ts` `.js`
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
131
|
+
|
|
132
|
+
export default [
|
|
133
|
+
...hhEslintConfigHelper.configs.es6,
|
|
134
|
+
...hhEslintConfigHelper.configs.typescript,
|
|
135
|
+
...hhEslintConfigHelper.configs.vue2Ts,
|
|
136
|
+
];
|
|
137
|
+
```
|
|
138
|
+
|
|
117
139
|
### Vue3
|
|
118
140
|
|
|
119
141
|
校验文件范围:`.vue` `.js`
|
|
@@ -141,6 +163,30 @@ export default [
|
|
|
141
163
|
];
|
|
142
164
|
```
|
|
143
165
|
|
|
166
|
+
### React(JSX)
|
|
167
|
+
|
|
168
|
+
校验文件范围:`.jsx`
|
|
169
|
+
|
|
170
|
+
```js
|
|
171
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
172
|
+
|
|
173
|
+
export default [
|
|
174
|
+
...hhEslintConfigHelper.configs.reactJsx,
|
|
175
|
+
];
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### React + TypeScript(TSX,推荐)
|
|
179
|
+
|
|
180
|
+
校验文件范围:`.tsx`
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import hhEslintConfigHelper from "@houheaven/eslint-config-helper";
|
|
184
|
+
|
|
185
|
+
export default [
|
|
186
|
+
...hhEslintConfigHelper.configs.reactTsx,
|
|
187
|
+
];
|
|
188
|
+
```
|
|
189
|
+
|
|
144
190
|
### html + ES5
|
|
145
191
|
|
|
146
192
|
校验文件范围:`.html` `.js`
|
|
@@ -215,6 +261,8 @@ export default [
|
|
|
215
261
|
- 查看 [`Eslint 规则文档`](https://www.npmjs.com/package/eslint)
|
|
216
262
|
- 查看 [`eslint-plugin-import 规则文档`](https://www.npmjs.com/package/eslint-plugin-import)
|
|
217
263
|
- 查看 [`eslint-plugin-vue 规则文档`](https://eslint.vuejs.org/rules/)
|
|
264
|
+
- 查看 [`eslint-plugin-react 规则文档`](https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules)
|
|
265
|
+
- 查看 [`eslint-plugin-react-hooks 规则文档`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
|
|
218
266
|
- 查看 [`@html-eslint 规则文档`](https://html-eslint.org/docs/getting-started/)
|
|
219
267
|
- 查看 [`@typescript-eslint/eslint-plugin 规则文档`](https://typescript-eslint.io/rules/)
|
|
220
268
|
|
|
@@ -233,6 +281,8 @@ export default [
|
|
|
233
281
|
- [`eslint`](https://www.npmjs.com/package/eslint)
|
|
234
282
|
- [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
|
|
235
283
|
- [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue)
|
|
284
|
+
- [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react)
|
|
285
|
+
- [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
|
|
236
286
|
- [`eslint-plugin-html`](https://www.npmjs.com/package/eslint-plugin-html)
|
|
237
287
|
- [`eslint-import-resolver-alias`](https://www.npmjs.com/package/eslint-import-resolver-alias)
|
|
238
288
|
- [`eslint-import-resolver-node`](https://www.npmjs.com/package/eslint-import-resolver-node)
|
package/exports.js
CHANGED
|
@@ -5,6 +5,7 @@ import typescript from "./lib/typescript.js";
|
|
|
5
5
|
import html from "./lib/html.js";
|
|
6
6
|
import vue2 from "./lib/vue2.js";
|
|
7
7
|
import vue3 from "./lib/vue3.js";
|
|
8
|
+
import react from "./lib/react.js";
|
|
8
9
|
|
|
9
10
|
export default {
|
|
10
11
|
configs: {
|
|
@@ -14,6 +15,7 @@ export default {
|
|
|
14
15
|
...html.configs,
|
|
15
16
|
...vue2.configs,
|
|
16
17
|
...vue3.configs,
|
|
18
|
+
...react.configs,
|
|
17
19
|
},
|
|
18
20
|
supports: {
|
|
19
21
|
...es5.supports,
|
|
@@ -22,5 +24,6 @@ export default {
|
|
|
22
24
|
...html.supports,
|
|
23
25
|
...vue2.supports,
|
|
24
26
|
...vue3.supports,
|
|
27
|
+
...react.supports,
|
|
25
28
|
},
|
|
26
29
|
};
|
package/lib/react.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/react
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - eslint-plugin-react 定制规则
|
|
6
|
+
// - eslint-plugin-react-hooks 定制规则
|
|
7
|
+
// ==========================================================
|
|
8
|
+
|
|
9
|
+
import utils from "@houheaven/eslint-config-helper-core";
|
|
10
|
+
import supportEs6 from "./supports/support-es6.js";
|
|
11
|
+
import supportImport from "./supports/support-import.js";
|
|
12
|
+
import supportReactJsx from "./supports/support-react-jsx.js";
|
|
13
|
+
import supportReactTsx from "./supports/support-react-tsx.js";
|
|
14
|
+
|
|
15
|
+
// 基础配置(JSX)
|
|
16
|
+
const reactJsxCommonConfig = {
|
|
17
|
+
files: ["**/*.jsx"],
|
|
18
|
+
linterOptions: {
|
|
19
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
20
|
+
reportUnusedDisableDirectives: "warn",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// 基础配置(TSX)
|
|
25
|
+
const reactTsxCommonConfig = {
|
|
26
|
+
files: ["**/*.tsx"],
|
|
27
|
+
linterOptions: {
|
|
28
|
+
// 当 eslint-disable 注释配置未使用时,是否报错
|
|
29
|
+
reportUnusedDisableDirectives: "warn",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 基础支持:校验 ES5、ES6、import、react 规则
|
|
34
|
+
const supportReactJsxConfig = {
|
|
35
|
+
plugins: {
|
|
36
|
+
...supportEs6.plugins,
|
|
37
|
+
...supportImport.plugins,
|
|
38
|
+
...supportReactJsx.plugins,
|
|
39
|
+
},
|
|
40
|
+
languageOptions: {
|
|
41
|
+
...supportEs6.languageOptions,
|
|
42
|
+
...supportReactJsx.languageOptions,
|
|
43
|
+
},
|
|
44
|
+
settings: {
|
|
45
|
+
...supportImport.settings,
|
|
46
|
+
...supportReactJsx.settings,
|
|
47
|
+
},
|
|
48
|
+
rules: {
|
|
49
|
+
// Eslint 基础规则
|
|
50
|
+
...utils.rules.es5,
|
|
51
|
+
...utils.rules.es6,
|
|
52
|
+
// eslint-plugin-import 规则
|
|
53
|
+
...utils.rules.import,
|
|
54
|
+
// React 规则
|
|
55
|
+
...supportReactJsx.rules,
|
|
56
|
+
...utils.rules.react,
|
|
57
|
+
...utils.rules.reactHooks,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 基础支持:校验 ES5、ES6、TypeScript、import、react 规则
|
|
62
|
+
const supportReactTsxConfig = {
|
|
63
|
+
plugins: {
|
|
64
|
+
...supportEs6.plugins,
|
|
65
|
+
...supportImport.plugins,
|
|
66
|
+
...supportReactTsx.plugins,
|
|
67
|
+
},
|
|
68
|
+
languageOptions: {
|
|
69
|
+
...supportReactTsx.languageOptions,
|
|
70
|
+
...supportEs6.languageOptions,
|
|
71
|
+
},
|
|
72
|
+
settings: {
|
|
73
|
+
...supportImport.settings,
|
|
74
|
+
...supportReactTsx.settings,
|
|
75
|
+
},
|
|
76
|
+
rules: {
|
|
77
|
+
// Eslint 基础规则
|
|
78
|
+
...utils.rules.es5,
|
|
79
|
+
...utils.rules.es6,
|
|
80
|
+
// eslint-plugin-import 规则
|
|
81
|
+
...utils.rules.import,
|
|
82
|
+
// React 规则
|
|
83
|
+
...supportReactTsx.rules,
|
|
84
|
+
...utils.rules.react,
|
|
85
|
+
...utils.rules.reactHooks,
|
|
86
|
+
// @typescript-eslint/eslint-plugin 规则
|
|
87
|
+
...utils.rules.typescript,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// 预设配置:校验 JSX 文件的 ES5、ES6、import、react 规则
|
|
92
|
+
const reactJsxConfig = {
|
|
93
|
+
name: "@houheaven/eslint-config-helper/react",
|
|
94
|
+
...reactJsxCommonConfig,
|
|
95
|
+
...supportReactJsxConfig,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// 预设配置:校验 TSX 文件的 ES5、ES6、TypeScript、import、react 规则
|
|
99
|
+
const reactTsxConfig = {
|
|
100
|
+
name: "@houheaven/eslint-config-helper/react-tsx",
|
|
101
|
+
...reactTsxCommonConfig,
|
|
102
|
+
...supportReactTsxConfig,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default {
|
|
106
|
+
supports: {
|
|
107
|
+
reactJsx: supportReactJsxConfig,
|
|
108
|
+
reactTsx: supportReactTsxConfig,
|
|
109
|
+
},
|
|
110
|
+
configs: {
|
|
111
|
+
reactJsx: [
|
|
112
|
+
reactJsxConfig,
|
|
113
|
+
],
|
|
114
|
+
reactTsx: [
|
|
115
|
+
reactTsxConfig,
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/support-react-jsx
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - 解析 JSX 文件(React 语法)
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
import globals from "globals";
|
|
9
|
+
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
10
|
+
import pluginReact from "eslint-plugin-react";
|
|
11
|
+
import pluginReactHooks from "eslint-plugin-react-hooks";
|
|
12
|
+
|
|
13
|
+
const supportReactJsx = {
|
|
14
|
+
plugins: {
|
|
15
|
+
"react": pluginReact,
|
|
16
|
+
"react-hooks": pluginReactHooks,
|
|
17
|
+
"@stylistic": pluginStylistic,
|
|
18
|
+
},
|
|
19
|
+
languageOptions: {
|
|
20
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
21
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
22
|
+
parserOptions: {
|
|
23
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
24
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
25
|
+
ecmaFeatures: {
|
|
26
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
globals: {
|
|
30
|
+
...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
31
|
+
...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
32
|
+
...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
33
|
+
...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
settings: {
|
|
37
|
+
// ---------------- eslint-plugin-react 的语义字典 ----------------
|
|
38
|
+
// 这里只是"告诉规则怎么理解你的代码",不产生任何报错。
|
|
39
|
+
"react": {
|
|
40
|
+
// JSX 编译目标:<div/> => React.createElement(...);用 h/preact 等自定义 pragma 时再改
|
|
41
|
+
pragma: "React",
|
|
42
|
+
// Fragment 名称:<>...</> => React.Fragment;改自定义 pragma 时同步改
|
|
43
|
+
fragment: "Fragment",
|
|
44
|
+
// React 版本:默认从 node_modules/react 自动探测,兼容 no-unsupported-features 等版本相关规则
|
|
45
|
+
version: "detect",
|
|
46
|
+
},
|
|
47
|
+
// 供 react/prefer-exact-props 识别的 exact wrapper 函数
|
|
48
|
+
// 注意:只有对象形式并显式声明 `exact: true` 的条目,才会被 prefer-exact-props 视为 "exact wrapper"(源码依据:propWrapper.getExactPropWrapperFunctions 中的 `func.exact === true` 过滤)。
|
|
49
|
+
// 单纯字符串或不带 exact 的对象只会参与 `forbid-foreign-prop-types` 等宽松匹配。
|
|
50
|
+
"propWrapperFunctions": [
|
|
51
|
+
{ property: "exact", exact: true },
|
|
52
|
+
{ property: "forbidExtraProps", exact: true },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
rules: {},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default supportReactJsx;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/support-react-tsx
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - 解析 TSX 文件(React 语法)
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
import globals from "globals";
|
|
9
|
+
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
10
|
+
import pluginTs from "@typescript-eslint/eslint-plugin";
|
|
11
|
+
import pluginReact from "eslint-plugin-react";
|
|
12
|
+
import pluginReactHooks from "eslint-plugin-react-hooks";
|
|
13
|
+
import parserTs from "@typescript-eslint/parser";
|
|
14
|
+
|
|
15
|
+
const supportReactTsx = {
|
|
16
|
+
plugins: {
|
|
17
|
+
"react": pluginReact,
|
|
18
|
+
"react-hooks": pluginReactHooks,
|
|
19
|
+
"@typescript-eslint": pluginTs,
|
|
20
|
+
"@stylistic": pluginStylistic,
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
parser: parserTs,
|
|
24
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
25
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
26
|
+
parserOptions: {
|
|
27
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
28
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
29
|
+
ecmaFeatures: {
|
|
30
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
31
|
+
},
|
|
32
|
+
// React 添加对 TypeScript 的支持
|
|
33
|
+
extraFileExtensions: [".jsx", ".tsx"],
|
|
34
|
+
project: [
|
|
35
|
+
"**/tsconfig.json",
|
|
36
|
+
"**/tsconfig.**.json",
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
globals: {
|
|
40
|
+
...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
41
|
+
...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
42
|
+
...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
43
|
+
...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
settings: {
|
|
47
|
+
// ---------------- eslint-plugin-react 的语义字典 ----------------
|
|
48
|
+
// 这里只是"告诉规则怎么理解你的代码",不产生任何报错。
|
|
49
|
+
"react": {
|
|
50
|
+
// JSX 编译目标:<div/> => React.createElement(...);用 h/preact 等自定义 pragma 时再改
|
|
51
|
+
pragma: "React",
|
|
52
|
+
// Fragment 名称:<>...</> => React.Fragment;改自定义 pragma 时同步改
|
|
53
|
+
fragment: "Fragment",
|
|
54
|
+
// React 版本:默认从 node_modules/react 自动探测,兼容 no-unsupported-features 等版本相关规则
|
|
55
|
+
version: "detect",
|
|
56
|
+
},
|
|
57
|
+
// 供 react/prefer-exact-props 识别的 exact wrapper 函数
|
|
58
|
+
// 注意:只有对象形式并显式声明 `exact: true` 的条目,才会被 prefer-exact-props 视为 "exact wrapper"(源码依据:propWrapper.getExactPropWrapperFunctions 中的 `func.exact === true` 过滤)。
|
|
59
|
+
// 单纯字符串或不带 exact 的对象只会参与 `forbid-foreign-prop-types` 等宽松匹配。
|
|
60
|
+
"propWrapperFunctions": [
|
|
61
|
+
{ property: "exact", exact: true },
|
|
62
|
+
{ property: "forbidExtraProps", exact: true },
|
|
63
|
+
],
|
|
64
|
+
|
|
65
|
+
// 如果组件被 observer / styled / memo 之类高阶函数包一层,就在这里登记
|
|
66
|
+
// 否则 react/display-name、react/prop-types 等规则可能"看不见"里面的组件
|
|
67
|
+
// componentWrapperFunctions: [],
|
|
68
|
+
|
|
69
|
+
// 自定义"表单"组件:影响 react/form-has-action 等规则如何识别提交入口
|
|
70
|
+
// formComponents: [],
|
|
71
|
+
|
|
72
|
+
// 自定义"链接"组件:影响 jsx-no-target-blank、jsx-a11y/anchor-is-valid 等识别
|
|
73
|
+
// 例如:{ name: "Link", linkAttribute: ["to", "href"] }
|
|
74
|
+
// linkComponents: [],
|
|
75
|
+
|
|
76
|
+
// "react": {
|
|
77
|
+
// "createClass": "createReactClass", // 告诉插件"创建组件的工厂函数叫什么"。老代码里 React.createClass 被拆到独立包 create-react-class,插件需要知道这个函数名,才能把 createReactClass({...}) 识别成一个组件。
|
|
78
|
+
// "pragma": "React", // JSX 编译时对应的全局对象名。<div/> 会被编译成 React.createElement("div"),
|
|
79
|
+
// // 改为 "h" 或 "Preact" 等自定义 pragma 时要在这里改,否则 no-unused-vars 之类的规则会误判 React / 自定义 pragma 变量是"没用到的 import"。
|
|
80
|
+
// "fragment": "Fragment", // Fragment 的对应名。<>...</> 会被识别为 React.Fragment;如果你有自定义 pragma(比如 h + Fragment),也在这里改。
|
|
81
|
+
// "version": "detect", // React 版本。"detect" 让插件从 node_modules/react/package.json 自动读版本号。有些规则(如 react/no-unsupported-features、hooks 相关行为)要按版本区分。也可以硬编码成 "18.2"。
|
|
82
|
+
// "defaultVersion": "", // 当 detect 探测不到(比如项目里根本没装 react)时的兜底版本。空字符串意味着不设兜底,插件会用它自带的默认(一般是最新版)。
|
|
83
|
+
// "flowVersion": "0.53", // Flow 类型系统的版本(仅在你用 Flow 而不是 TS 时才有用),影响某些 propTypes / Flow 类型的解析行为。
|
|
84
|
+
// },
|
|
85
|
+
// // propTypes 的包装函数白名单
|
|
86
|
+
// "propWrapperFunctions": [
|
|
87
|
+
// "forbidExtraProps",
|
|
88
|
+
// { "property": "freeze", "object": "Object" },
|
|
89
|
+
// { "property": "myFavoriteWrapper" },
|
|
90
|
+
// { "property": "forbidExtraProps", "exact": true }, // exact 表示这个包装器语义是"禁止未声明的 prop"
|
|
91
|
+
// ],
|
|
92
|
+
// // 组件包装函数,告诉插件"哪些函数返回的还是一个 React 组件"
|
|
93
|
+
// "componentWrapperFunctions": [
|
|
94
|
+
// "observer", // `property`
|
|
95
|
+
// { "property": "styled" }, // `object` is optional
|
|
96
|
+
// { "property": "observer", "object": "Mobx" },
|
|
97
|
+
// { "property": "observer", "object": "<pragma>" }, // sets `object` to whatever value `settings.react.pragma` is set to
|
|
98
|
+
// ],
|
|
99
|
+
// // 自定义"表单"组件
|
|
100
|
+
// // 有些项目不用原生 <form action="...">,而用自定义组件 <CustomForm endpoint="..."/>。像 react/form-has-action、以及安全类规则会关心"这个组件是否指定了提交地址"。formAttribute 就告诉插件"这个组件的『action』等价属性叫什么",可以是字符串,也可以是数组(允许多个字段任选其一)。
|
|
101
|
+
// "formComponents": [
|
|
102
|
+
// // Components used as alternatives to <form> for forms, eg. <Form endpoint={ url } />
|
|
103
|
+
// "CustomForm",
|
|
104
|
+
// { "name": "SimpleForm", "formAttribute": "endpoint" },
|
|
105
|
+
// { "name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"] }, // allows specifying multiple properties if necessary
|
|
106
|
+
// ],
|
|
107
|
+
// // 自定义"链接"组件
|
|
108
|
+
// // 很多项目不用 <a>,而是 <Link to="...">(React Router)或自研 <Hyperlink>。react/jsx-no-target-blank、jsx-a11y/anchor-is-valid 等规则要靠这个白名单才能识别"哪些组件本质上是链接",linkAttribute 指明它的 href 对应属性叫什么。
|
|
109
|
+
// "linkComponents": [
|
|
110
|
+
// // Components used as alternatives to <a> for linking, eg. <Link to={ url } />
|
|
111
|
+
// "Hyperlink",
|
|
112
|
+
// { "name": "MyLink", "linkAttribute": "to" },
|
|
113
|
+
// { "name": "Link", "linkAttribute": ["to", "href"] }, // allows specifying multiple properties if necessary
|
|
114
|
+
// ],
|
|
115
|
+
},
|
|
116
|
+
rules: {},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default supportReactTsx;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// @houheaven/eslint-config-helper/support-vue2-ts
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// - 解析 Vue 文件(Vue2 + TypeScript 语法)
|
|
6
|
+
// ==========================================================
|
|
7
|
+
|
|
8
|
+
import globals from "globals";
|
|
9
|
+
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
10
|
+
import pluginTs from "@typescript-eslint/eslint-plugin";
|
|
11
|
+
import pluginVue from "eslint-plugin-vue";
|
|
12
|
+
import parserVue from "vue-eslint-parser";
|
|
13
|
+
import parserTs from "@typescript-eslint/parser";
|
|
14
|
+
|
|
15
|
+
const supportVue2Ts = {
|
|
16
|
+
plugins: {
|
|
17
|
+
"vue": pluginVue,
|
|
18
|
+
"@typescript-eslint": pluginTs,
|
|
19
|
+
"@stylistic": pluginStylistic,
|
|
20
|
+
},
|
|
21
|
+
languageOptions: {
|
|
22
|
+
parser: parserVue,
|
|
23
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
24
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
25
|
+
parserOptions: {
|
|
26
|
+
sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
|
|
27
|
+
ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
|
|
28
|
+
ecmaFeatures: {
|
|
29
|
+
jsx: true, // 启用 JSX 全局变量和作用域规则
|
|
30
|
+
},
|
|
31
|
+
// Vue 添加对 TypeScript 的支持
|
|
32
|
+
parser: parserTs,
|
|
33
|
+
extraFileExtensions: [".vue"],
|
|
34
|
+
project: [
|
|
35
|
+
"**/tsconfig.json",
|
|
36
|
+
"**/tsconfig.**.json",
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
globals: {
|
|
40
|
+
...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
|
|
41
|
+
...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
|
|
42
|
+
...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
|
|
43
|
+
...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
processor: "vue/vue",
|
|
47
|
+
rules: {
|
|
48
|
+
"indent": "off",
|
|
49
|
+
"max-len": "off",
|
|
50
|
+
"no-irregular-whitespace": "off",
|
|
51
|
+
// 禁止在 Vue 指定的版本上使用不支持的语法
|
|
52
|
+
// https://eslint.vuejs.org/rules/no-unsupported-features.html
|
|
53
|
+
"vue/no-unsupported-features": ["error", {
|
|
54
|
+
"version": "^2.6.0",
|
|
55
|
+
"ignores": [],
|
|
56
|
+
}],
|
|
57
|
+
// 禁止在 props 中使用保留关键字
|
|
58
|
+
// https://eslint.vuejs.org/rules/no-reserved-props.html
|
|
59
|
+
"vue/no-reserved-props": ["error", {
|
|
60
|
+
"vueVersion": 2,
|
|
61
|
+
}],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default supportVue2Ts;
|
package/lib/vue2.js
CHANGED
|
@@ -8,6 +8,7 @@ import utils from "@houheaven/eslint-config-helper-core";
|
|
|
8
8
|
import supportEs6 from "./supports/support-es6.js";
|
|
9
9
|
import supportImport from "./supports/support-import.js";
|
|
10
10
|
import supportVue2 from "./supports/support-vue2.js";
|
|
11
|
+
import supportVue2Ts from "./supports/support-vue2-ts.js";
|
|
11
12
|
|
|
12
13
|
// 基础配置
|
|
13
14
|
const vueCommonConfig = {
|
|
@@ -46,6 +47,36 @@ const supportVue2Config = {
|
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
|
|
50
|
+
// 基础支持:校验 ES5、ES6、import、vue2-ts 规则
|
|
51
|
+
const supportVue2TsConfig = {
|
|
52
|
+
plugins: {
|
|
53
|
+
...supportEs6.plugins,
|
|
54
|
+
...supportImport.plugins,
|
|
55
|
+
...supportVue2Ts.plugins,
|
|
56
|
+
},
|
|
57
|
+
languageOptions: {
|
|
58
|
+
...supportEs6.languageOptions,
|
|
59
|
+
...supportVue2Ts.languageOptions,
|
|
60
|
+
},
|
|
61
|
+
settings: {
|
|
62
|
+
...supportImport.settings,
|
|
63
|
+
},
|
|
64
|
+
processor: supportVue2Ts.processor,
|
|
65
|
+
rules: {
|
|
66
|
+
// Eslint 基础规则
|
|
67
|
+
...utils.rules.es5,
|
|
68
|
+
...utils.rules.es6,
|
|
69
|
+
// eslint-plugin-import 规则
|
|
70
|
+
...utils.rules.import,
|
|
71
|
+
// Vue2 规则
|
|
72
|
+
...supportVue2Ts.rules,
|
|
73
|
+
...utils.rules.vue,
|
|
74
|
+
...utils.rules.vue2,
|
|
75
|
+
// @typescript-eslint/eslint-plugin 规则
|
|
76
|
+
...utils.rules.typescript,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
49
80
|
// 预设配置:校验 vue2 文件的 ES5、ES6、import、vue2 规则
|
|
50
81
|
const vue2Config = {
|
|
51
82
|
name: "@houheaven/eslint-config-helper/vue2",
|
|
@@ -53,13 +84,24 @@ const vue2Config = {
|
|
|
53
84
|
...supportVue2Config,
|
|
54
85
|
};
|
|
55
86
|
|
|
87
|
+
// 预设配置:校验 Vue2 + TypeScript 文件的 ES5、ES6、import、vue2-ts 规则
|
|
88
|
+
const vue2TsConfig = {
|
|
89
|
+
name: "@houheaven/eslint-config-helper/vue2-ts",
|
|
90
|
+
...vueCommonConfig,
|
|
91
|
+
...supportVue2TsConfig,
|
|
92
|
+
};
|
|
93
|
+
|
|
56
94
|
export default {
|
|
57
95
|
supports: {
|
|
58
96
|
vue2: supportVue2Config,
|
|
97
|
+
vue2Ts: supportVue2TsConfig,
|
|
59
98
|
},
|
|
60
99
|
configs: {
|
|
61
100
|
vue2: [
|
|
62
101
|
vue2Config,
|
|
63
102
|
],
|
|
103
|
+
vue2Ts: [
|
|
104
|
+
vue2TsConfig,
|
|
105
|
+
],
|
|
64
106
|
},
|
|
65
107
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// eslint-plugin-react - deprecated
|
|
4
|
+
// ----------------------------------------------------------
|
|
5
|
+
// 已弃用规则,会用 replacedBy 迁移到新规则;配置一律保持 "off",
|
|
6
|
+
// 演示时在示例文件里通过 /* eslint react/xxx: "error" */ 临时启用。
|
|
7
|
+
// ==========================================================
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
rules: {
|
|
11
|
+
// 排序 defaultProps
|
|
12
|
+
// ----------------------------------------------------------
|
|
13
|
+
// 已废弃(v7.33.0),替换为 react/sort-default-props
|
|
14
|
+
// 官方推荐:无(deprecated 规则一律不进入 recommended)
|
|
15
|
+
// 社区最佳:保持 "off",改用 react/sort-default-props 或
|
|
16
|
+
// typescript-eslint 的 sort-type-constituents
|
|
17
|
+
// - 官方文档:https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-default-props.md
|
|
18
|
+
"react/jsx-sort-default-props": "off",
|
|
19
|
+
|
|
20
|
+
// JSX 闭合前空格
|
|
21
|
+
// ----------------------------------------------------------
|
|
22
|
+
// 已废弃(v7.4.0),替换为 react/jsx-tag-spacing
|
|
23
|
+
// 官方推荐:无(deprecated 规则一律不进入 recommended)
|
|
24
|
+
// 社区最佳:保持 "off",改用 react/jsx-tag-spacing(更完整地覆盖
|
|
25
|
+
// before/after 空格控制)
|
|
26
|
+
// - 官方文档:https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
|
|
27
|
+
"react/jsx-space-before-closing": "off",
|
|
28
|
+
},
|
|
29
|
+
};
|