@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
@@ -4,25 +4,65 @@
4
4
  // ----------------------------------------------------------
5
5
  // - Eslint ES5 定制规则
6
6
  // - Eslint ES6+ 定制规则
7
+ // - eslint-plugin-import 定制规则
7
8
  // ==========================================================
8
9
 
9
- // 这个插件为当前类库提供”开箱即用“的能力,使用者无需手动安装当前库的依赖项
10
- require("@rushstack/eslint-patch/modern-module-resolution");
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
- const utils = require("@houheaven/eslint-config-helper-core");
13
-
14
- module.exports = {
15
- // 当 eslint-disable 注释配置未使用时,是否报错
16
- reportUnusedDisableDirectives: true,
17
- // 继承配置文件
18
- extends: [
19
- // Eslint ES6 支持
20
- "./support/es6-support.js",
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
  };
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,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;
@@ -0,0 +1,35 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-es6
4
+ // ----------------------------------------------------------
5
+ // - 解析 ES6+ 语法
6
+ // ==========================================================
7
+
8
+ import globals from "globals";
9
+ import pluginStylistic from "@stylistic/eslint-plugin";
10
+
11
+ const supportEs6 = {
12
+ plugins: {
13
+ "@stylistic": pluginStylistic,
14
+ },
15
+ languageOptions: {
16
+ sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
17
+ ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
18
+ // ecmaFeatures: {
19
+ // generators: false,
20
+ // objectLiteralDuplicateProperties: false,
21
+ // jsx: true,
22
+ // },
23
+ globals: {
24
+ ...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
25
+ ...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
26
+ ...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
27
+ ...globals.amd, // AMD 环境,启用 AMD 环境的全局变量和作用域规则(define()、require() 等)
28
+ ...globals.mocha, // Mocha 环境,启用 Mocha 环境的全局变量和作用域规则(describe()、it()、before()、after() 等)
29
+ ...globals.jasmine, // Jasmine 环境,启用 Jasmine 环境的全局变量和作用域规则(describe()、it()、beforeEach()、afterEach() 等)
30
+ ...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
31
+ },
32
+ },
33
+ };
34
+
35
+ export default supportEs6;
@@ -0,0 +1,41 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-html
4
+ // ----------------------------------------------------------
5
+ // - 解析 HTML 语法
6
+ // ==========================================================
7
+
8
+ import pluginHtmlScripts from "eslint-plugin-html";
9
+ import pluginHtml from "@html-eslint/eslint-plugin";
10
+ import parserHtml from "@html-eslint/parser";
11
+
12
+ const supportHtml = {
13
+ plugins: {
14
+ // 检查和修复 html 文件中的 html 代码
15
+ "@html-eslint": pluginHtml,
16
+ // 检查和修复 html 文件中的 JS 代码,即 <script> 中的代码
17
+ // 仅仅提供技术支持,不包含任何规则,具体规则由 eslint.js 提供
18
+ "html": pluginHtmlScripts,
19
+ },
20
+ languageOptions: {
21
+ parser: parserHtml,
22
+ },
23
+ // eslint-plugin-html 配置
24
+ settings: {
25
+ "html/html-extensions": [".html", ".htm", ".php"],
26
+ "html/javascript-tag-names": ["script"],
27
+ // "html/javascript-mime-types": "/^(application|text)\\/(x-)?(javascript|babel|ecmascript-6|html)$/",
28
+ "html/javascript-mime-types": ["text/javascript", "module"],
29
+ "html/ignore-tags-without-type": false,
30
+ "html/report-bad-indent": "warn",
31
+ "html/indent": "+2",
32
+ },
33
+ rules: {
34
+ // 此处不可删除,解决 html 中 <script> 换行问题
35
+ "eol-last": "off",
36
+ // 解决 HTML 注释(<!-- -->)引起 eslint 报错的问题
37
+ "spaced-comment": "off",
38
+ },
39
+ };
40
+
41
+ export default supportHtml;
@@ -1,25 +1,30 @@
1
1
 
2
2
  // ==========================================================
3
- // import 支持
3
+ // @houheaven/eslint-config-helper/support-import
4
+ // ----------------------------------------------------------
5
+ // - 解析 import 规则
4
6
  // ==========================================================
5
7
 
6
- const importResolver = require("./import-bugfix.js");
8
+ import pluginImport from "eslint-plugin-import";
7
9
 
8
- module.exports = {
9
- plugins: ["eslint-plugin-import"],
10
- parserOptions: {
11
- sourceType: "module",
12
- ecmaVersion: "latest",
10
+ const supportImport = {
11
+ plugins: {
12
+ "import": pluginImport,
13
13
  },
14
14
  settings: {
15
- "import/resolver": {
16
- ...importResolver,
17
- },
18
- "import/extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
19
15
  "import/parsers": {
20
16
  "@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
21
17
  },
18
+ "import/resolver": {
19
+ "node": {
20
+ "extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
21
+ },
22
+ },
23
+ "import/extensions": [".js", ".jsx", ".ts", ".tsx", ".d.ts"],
24
+ "import/external-module-folders": ["node_modules", "node_modules/@types"],
22
25
  "import/ignore": ["node_modules", "\\.(coffee|scss|css|less|hbs|svg|json)$"],
23
26
  "import/docstyle": ["jsdoc", "tomdoc"],
24
27
  },
25
28
  };
29
+
30
+ export default supportImport;
@@ -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,34 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-typescript
4
+ // ----------------------------------------------------------
5
+ // - 解析 Typescript 文件
6
+ // ==========================================================
7
+
8
+ import pluginStylistic from "@stylistic/eslint-plugin";
9
+ import pluginTypescript from "@typescript-eslint/eslint-plugin";
10
+ import parserTypescript from "@typescript-eslint/parser";
11
+
12
+ const supportTypescript = {
13
+ plugins: {
14
+ "@typescript-eslint": pluginTypescript,
15
+ "@stylistic": pluginStylistic,
16
+ },
17
+ languageOptions: {
18
+ // Typescript 规则很多是类型感知规则,需要访问 TypeScript 类型系统(即需要配置 parserOptions)
19
+ parser: parserTypescript,
20
+ parserOptions: {
21
+ ecmaVersion: "latest",
22
+ sourceType: "module",
23
+ // 零配置方案
24
+ // - 自动适配项目中的 tsconfig.json 配置文件
25
+ // - 不需要指定具体路径,让 ESLint 自动查找
26
+ // 方案一:优先使用用户项目的 tsconfig.json
27
+ // project: true,
28
+ // 方案二:projectService 作为降级方案
29
+ projectService: true,
30
+ },
31
+ },
32
+ };
33
+
34
+ export default supportTypescript;
@@ -0,0 +1,46 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-vue2
4
+ // ----------------------------------------------------------
5
+ // - 解析 Vue 文件(Vue2 语法)
6
+ // ==========================================================
7
+
8
+ import globals from "globals";
9
+ import pluginVue from "eslint-plugin-vue";
10
+ import parserVue from "vue-eslint-parser";
11
+
12
+ const supportVue2 = {
13
+ plugins: {
14
+ "vue": pluginVue,
15
+ },
16
+ languageOptions: {
17
+ parser: parserVue,
18
+ sourceType: "module", // 指定代码的来源类型,"module" 表示 ESLint 会在 ECMAScript 模块的上下文中解析代码(即支持 import 和 export 语法)
19
+ ecmaVersion: "latest", // 指定 ECMAScript 版本,"latest" 表示使用最新的 ECMAScript 版本
20
+ globals: {
21
+ ...globals.browser, // 浏览器环境,启用浏览器环境的全局变量(window、document、navigator、alert 等)
22
+ ...globals.node, // Node.js 环境,启用 Node.js 环境的全局变量和作用域规则(__dirname、__filename、process、global 等)
23
+ ...globals.commonjs, // Node.js 环境,启用 CommonJS 的全局变量和作用域规则(require()、module、exports 等)
24
+ ...globals.es6, // 启用 ECMAScript 6 全局变量和作用域规则(let、const、class、import、export 等)
25
+ },
26
+ },
27
+ processor: "vue/vue",
28
+ rules: {
29
+ "indent": "off",
30
+ "max-len": "off",
31
+ "no-irregular-whitespace": "off",
32
+ // 禁止在 Vue 指定的版本上使用不支持的语法
33
+ // https://eslint.vuejs.org/rules/no-unsupported-features.html
34
+ "vue/no-unsupported-features": ["error", {
35
+ "version": "^2.6.0",
36
+ "ignores": [],
37
+ }],
38
+ // 禁止在 props 中使用保留关键字
39
+ // https://eslint.vuejs.org/rules/no-reserved-props.html
40
+ "vue/no-reserved-props": ["error", {
41
+ "vueVersion": 2,
42
+ }],
43
+ },
44
+ };
45
+
46
+ export default supportVue2;