@houheaven/eslint-config-helper 2.0.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.
Files changed (75) hide show
  1. package/README.md +155 -149
  2. package/exports.js +26 -0
  3. package/lib/html.js +88 -10
  4. package/lib/javascript-es5.js +44 -9
  5. package/lib/javascript-es6.js +52 -9
  6. package/lib/supports/support-es5.js +25 -0
  7. package/lib/supports/support-es6.js +35 -0
  8. package/lib/supports/support-html.js +41 -0
  9. package/lib/{support/import-support.js → supports/support-import.js} +16 -11
  10. package/lib/supports/support-typescript.js +34 -0
  11. package/lib/supports/support-vue2.js +46 -0
  12. package/lib/supports/support-vue3-ts.js +65 -0
  13. package/lib/supports/support-vue3.js +46 -0
  14. package/lib/typescript.js +54 -21
  15. package/lib/vue2.js +52 -11
  16. package/lib/vue3.js +95 -11
  17. package/node_modules/@houheaven/eslint-config-helper-core/package.json +7 -0
  18. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/layout-formatting.js +0 -15
  19. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/stylistic.js +24 -0
  20. package/node_modules/@houheaven/eslint-config-helper-core/summary.js +57 -0
  21. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/utils/utils.js +1 -0
  22. package/package.json +29 -37
  23. package/lib/configs/format-prettier.js +0 -478
  24. package/lib/format-es5.js +0 -23
  25. package/lib/format-es6.js +0 -25
  26. package/lib/format-html.js +0 -23
  27. package/lib/format-import.js +0 -23
  28. package/lib/format-typescript.js +0 -28
  29. package/lib/format-vue2.js +0 -23
  30. package/lib/format-vue3.js +0 -23
  31. package/lib/import.js +0 -23
  32. package/lib/support/es5-support.js +0 -29
  33. package/lib/support/es6-support.js +0 -39
  34. package/lib/support/html-support.js +0 -38
  35. package/lib/support/import-bugfix.js +0 -65
  36. package/lib/support/typescript-support.js +0 -27
  37. package/lib/support/vue2-support.js +0 -43
  38. package/lib/support/vue3-support.js +0 -43
  39. package/lib/support/vue3-ts-support.js +0 -51
  40. package/lib/vue3-ts.js +0 -31
  41. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/_deprecated.js +0 -0
  42. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/_removed.js +0 -0
  43. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/es6.js +0 -0
  44. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/possible-errors.js +0 -0
  45. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/eslint/suggestions.js +0 -0
  46. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/html/accessibility.js +0 -0
  47. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/html/best-practice.js +0 -0
  48. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/html/seo.js +0 -0
  49. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/html/style.js +0 -0
  50. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/helpful-warnings.js +0 -0
  51. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/module-systems.js +0 -0
  52. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/static-analysis.js +0 -0
  53. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/style-guide.js +0 -0
  54. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/_deprecated.js +0 -0
  55. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/conflict.js +0 -0
  56. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/deprecated.js +0 -0
  57. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/extension.js +0 -0
  58. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/fixable.js +0 -0
  59. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/other.js +0 -0
  60. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/stylistic.js +0 -0
  61. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/suggestion.js +0 -0
  62. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/typescript/type-checked.js +0 -0
  63. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/_deprecated.js +0 -0
  64. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-base.js +0 -0
  65. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-essential.js +0 -0
  66. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-extension.js +0 -0
  67. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-recommended.js +0 -0
  68. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-strongly-recommended.js +0 -0
  69. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-uncategorized.js +0 -0
  70. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-essential.js +0 -0
  71. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-uncategorized.js +0 -0
  72. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-essential.js +0 -0
  73. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-strongly-recommended.js +0 -0
  74. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-uncategorized.js +0 -0
  75. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vuejs-accessibility/index.js +0 -0
@@ -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,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;
@@ -0,0 +1,65 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-vue3-ts
4
+ // ----------------------------------------------------------
5
+ // - 解析 Vue 文件(Vue3 + 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 supportVue3Ts = {
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": "^3.4.0",
55
+ "ignores": [],
56
+ }],
57
+ // 禁止在 props 中使用保留关键字
58
+ // https://eslint.vuejs.org/rules/no-reserved-props.html
59
+ "vue/no-reserved-props": ["error", {
60
+ "vueVersion": 3,
61
+ }],
62
+ },
63
+ };
64
+
65
+ export default supportVue3Ts;
@@ -0,0 +1,46 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/support-vue3
4
+ // ----------------------------------------------------------
5
+ // - 解析 Vue 文件(Vue3 语法)
6
+ // ==========================================================
7
+
8
+ import globals from "globals";
9
+ import pluginVue from "eslint-plugin-vue";
10
+ import parserVue from "vue-eslint-parser";
11
+
12
+ const supportVue3 = {
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": "^3.4.0",
36
+ "ignores": [],
37
+ }],
38
+ // 禁止在 props 中使用保留关键字
39
+ // https://eslint.vuejs.org/rules/no-reserved-props.html
40
+ "vue/no-reserved-props": ["error", {
41
+ "vueVersion": 3,
42
+ }],
43
+ },
44
+ };
45
+
46
+ export default supportVue3;
package/lib/typescript.js CHANGED
@@ -12,26 +12,59 @@
12
12
  // 两类分组不能覆盖全部规则,部分规则还存在交叉,所以当前规则分类优先级如下:
13
13
  // extension > fixable > type-checked > has-suggestions > other
14
14
 
15
- const utils = require("./utils/utils.js");
15
+ import utils from "@houheaven/eslint-config-helper-core";
16
+ import supportEs6 from "./supports/support-es6.js";
17
+ import supportImport from "./supports/support-import.js";
18
+ import supportTypescript from "./supports/support-typescript.js";
16
19
 
17
- module.exports = {
18
- // Typescript 规则很多是类型感知规则,需要访问 TypeScript 类型系统(即需要配置 parserOptions)
19
- // typescript-support.js 作用域是 TS 文件,如果没有 overrides 限制,utils.rules.typescript 规则会应用到所有文件
20
- // 其他类型的文件没有经过 parserOptions 处理,就会导致报错,因此此处必须使用 overrides 嵌套
21
- overrides: [
22
- {
23
- files: ["**/*.ts"],
24
- // 当 eslint-disable 注释配置未使用时,是否报错
25
- reportUnusedDisableDirectives: true,
26
- // 继承配置文件
27
- extends: [
28
- // Typescript 支持
29
- "./support/typescript-support.js",
30
- ],
31
- rules: {
32
- // @typescript-eslint/eslint-plugin 规则
33
- ...utils.rules.typescript,
34
- },
35
- },
36
- ],
20
+ // 基础配置
21
+ const tsCommonConfig = {
22
+ files: ["**/*.ts"],
23
+ linterOptions: {
24
+ // 当 eslint-disable 注释配置未使用时,是否报错
25
+ reportUnusedDisableDirectives: "warn",
26
+ },
27
+ };
28
+
29
+ // 基础支持:校验 ES5、ES6、import、ts 规则
30
+ const supportTs = {
31
+ plugins: {
32
+ ...supportImport.plugins,
33
+ ...supportTypescript.plugins,
34
+ },
35
+ languageOptions: {
36
+ ...supportTypescript.languageOptions,
37
+ ...supportEs6.languageOptions,
38
+ },
39
+ settings: {
40
+ ...supportImport.settings,
41
+ },
42
+ // 规则
43
+ rules: {
44
+ // Eslint 基础规则
45
+ ...utils.rules.es5,
46
+ ...utils.rules.es6,
47
+ // eslint-plugin-import 规则
48
+ ...utils.rules.import,
49
+ // @typescript-eslint/eslint-plugin 规则
50
+ ...utils.rules.typescript,
51
+ },
52
+ };
53
+
54
+ // 预设配置:校验 ts 文件的 ES5、ES6、import、ts 规则
55
+ const tsConfig = {
56
+ name: "@houheaven/eslint-config-helper/typescript",
57
+ ...tsCommonConfig,
58
+ ...supportTs,
59
+ };
60
+
61
+ export default {
62
+ supports: {
63
+ typescript: supportTs,
64
+ },
65
+ configs: {
66
+ typescript: [
67
+ tsConfig,
68
+ ],
69
+ },
37
70
  };
package/lib/vue2.js CHANGED
@@ -1,24 +1,65 @@
1
-
2
1
  // ==========================================================
3
2
  // @houheaven/eslint-config-helper/vue2
4
3
  // ----------------------------------------------------------
5
4
  // - eslint-plugin-vue 定制规则
6
5
  // ==========================================================
7
6
 
8
- const utils = require("./utils/utils.js");
7
+ import utils from "@houheaven/eslint-config-helper-core";
8
+ import supportEs6 from "./supports/support-es6.js";
9
+ import supportImport from "./supports/support-import.js";
10
+ import supportVue2 from "./supports/support-vue2.js";
11
+
12
+ // 基础配置
13
+ const vueCommonConfig = {
14
+ files: ["**/*.vue"],
15
+ linterOptions: {
16
+ // 当 eslint-disable 注释配置未使用时,是否报错
17
+ reportUnusedDisableDirectives: "warn",
18
+ },
19
+ };
9
20
 
10
- module.exports = {
11
- // 当 eslint-disable 注释配置未使用时,是否报错
12
- reportUnusedDisableDirectives: true,
13
- // 继承配置文件
14
- extends: [
15
- // Vue2 支持
16
- "./support/vue2-support.js",
17
- ],
18
- // 规则
21
+ // 基础支持:校验 ES5、ES6、import、vue2 规则
22
+ const supportVue2Config = {
23
+ plugins: {
24
+ ...supportEs6.plugins,
25
+ ...supportImport.plugins,
26
+ ...supportVue2.plugins,
27
+ },
28
+ languageOptions: {
29
+ ...supportVue2.languageOptions,
30
+ ...supportEs6.languageOptions,
31
+ },
32
+ settings: {
33
+ ...supportImport.settings,
34
+ },
35
+ processor: supportVue2.processor,
19
36
  rules: {
37
+ // Eslint 基础规则
38
+ ...utils.rules.es5,
39
+ ...utils.rules.es6,
40
+ // eslint-plugin-import 规则
41
+ ...utils.rules.import,
20
42
  // Vue2 规则
43
+ ...supportVue2.rules,
21
44
  ...utils.rules.vue,
22
45
  ...utils.rules.vue2,
23
46
  },
24
47
  };
48
+
49
+ // 预设配置:校验 vue2 文件的 ES5、ES6、import、vue2 规则
50
+ const vue2Config = {
51
+ name: "@houheaven/eslint-config-helper/vue2",
52
+ ...vueCommonConfig,
53
+ ...supportVue2Config,
54
+ };
55
+
56
+ export default {
57
+ supports: {
58
+ vue2: supportVue2Config,
59
+ },
60
+ configs: {
61
+ vue2: [
62
+ vue2Config,
63
+ ],
64
+ },
65
+ };
package/lib/vue3.js CHANGED
@@ -5,20 +5,104 @@
5
5
  // - eslint-plugin-vue 定制规则
6
6
  // ==========================================================
7
7
 
8
- const utils = require("./utils/utils.js");
9
-
10
- module.exports = {
11
- // 当 eslint-disable 注释配置未使用时,是否报错
12
- reportUnusedDisableDirectives: true,
13
- // 继承配置文件
14
- extends: [
15
- // Vue3 支持
16
- "./support/vue3-support.js",
17
- ],
18
- // 规则
8
+ import utils from "@houheaven/eslint-config-helper-core";
9
+ import supportEs6 from "./supports/support-es6.js";
10
+ import supportImport from "./supports/support-import.js";
11
+ import supportVue3 from "./supports/support-vue3.js";
12
+ import supportVue3Ts from "./supports/support-vue3-ts.js";
13
+
14
+ // 基础配置
15
+ const vueCommonConfig = {
16
+ files: ["**/*.vue"],
17
+ linterOptions: {
18
+ // 当 eslint-disable 注释配置未使用时,是否报错
19
+ reportUnusedDisableDirectives: "warn",
20
+ },
21
+ };
22
+
23
+ // 基础支持:校验 ES5、ES6、import、vue3 规则
24
+ const supportVue3Config = {
25
+ plugins: {
26
+ ...supportEs6.plugins,
27
+ ...supportImport.plugins,
28
+ ...supportVue3.plugins,
29
+ },
30
+ languageOptions: {
31
+ ...supportVue3.languageOptions,
32
+ ...supportEs6.languageOptions,
33
+ },
34
+ settings: {
35
+ ...supportImport.settings,
36
+ },
37
+ processor: supportVue3.processor,
19
38
  rules: {
39
+ // Eslint 基础规则
40
+ ...utils.rules.es5,
41
+ ...utils.rules.es6,
42
+ // eslint-plugin-import 规则
43
+ ...utils.rules.import,
20
44
  // Vue3 规则
45
+ ...supportVue3.rules,
21
46
  ...utils.rules.vue,
22
47
  ...utils.rules.vue3,
23
48
  },
24
49
  };
50
+
51
+ // 基础支持:校验 ES5、ES6、import、vue3-ts 规则
52
+ const supportVue3TsConfig = {
53
+ plugins: {
54
+ ...supportEs6.plugins,
55
+ ...supportImport.plugins,
56
+ ...supportVue3Ts.plugins,
57
+ },
58
+ languageOptions: {
59
+ ...supportEs6.languageOptions,
60
+ ...supportVue3Ts.languageOptions,
61
+ },
62
+ settings: {
63
+ ...supportImport.settings,
64
+ },
65
+ processor: supportVue3Ts.processor,
66
+ rules: {
67
+ // Eslint 基础规则
68
+ ...utils.rules.es5,
69
+ ...utils.rules.es6,
70
+ // eslint-plugin-import 规则
71
+ ...utils.rules.import,
72
+ // Vue3 规则
73
+ ...supportVue3Ts.rules,
74
+ ...utils.rules.vue,
75
+ ...utils.rules.vue3,
76
+ // @typescript-eslint/eslint-plugin 规则
77
+ ...utils.rules.typescript,
78
+ },
79
+ };
80
+
81
+ // 预设配置:校验 Vue3 文件的 ES5、ES6、import、vue3 规则
82
+ const vue3Config = {
83
+ name: "@houheaven/eslint-config-helper/vue3",
84
+ ...vueCommonConfig,
85
+ ...supportVue3Config,
86
+ };
87
+
88
+ // 预设配置:校验 Vue3 + TypeScript 文件的 ES5、ES6、import、vue3-ts 规则
89
+ const vue3TsConfig = {
90
+ name: "@houheaven/eslint-config-helper/vue3-ts",
91
+ ...vueCommonConfig,
92
+ ...supportVue3TsConfig,
93
+ };
94
+
95
+ export default {
96
+ supports: {
97
+ vue3: supportVue3Config,
98
+ vue3Ts: supportVue3TsConfig,
99
+ },
100
+ configs: {
101
+ vue3: [
102
+ vue3Config,
103
+ ],
104
+ vue3Ts: [
105
+ vue3TsConfig,
106
+ ],
107
+ },
108
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@houheaven/eslint-config-helper-core",
3
+ "version": "1.0.0",
4
+ "description": "Core rules for eslint-config-helper",
5
+ "private": true,
6
+ "main": "utils/utils.js"
7
+ }
@@ -264,26 +264,11 @@ module.exports = {
264
264
  exceptions: {},
265
265
  }],
266
266
 
267
- // 禁止出现多行空行
268
- // https://zh-hans.eslint.org/docs/latest/rules/no-multiple-empty-lines
269
- "no-multiple-empty-lines": ["warn", {
270
- max: 2,
271
- maxBOF: 1,
272
- maxEOF: 1,
273
- }],
274
-
275
267
  // 禁用 tab
276
268
  "no-tabs": ["error", {
277
269
  allowIndentationTabs: false, // 允许缩进使用 tab
278
270
  }],
279
271
 
280
- // 禁用行尾空白
281
- // 这条规则不允许在行末有尾随空格(空格、制表符和其他 Unicode 空白字符)
282
- "no-trailing-spaces": ["warn", {
283
- skipBlankLines: true,
284
- ignoreComments: false,
285
- }],
286
-
287
272
  // 禁止属性前有空白
288
273
  // https://zh-hans.eslint.org/docs/latest/rules/no-whitespace-before-property
289
274
  "no-whitespace-before-property": "warn",
@@ -0,0 +1,24 @@
1
+
2
+ // ==========================================================
3
+ // - @stylistic/eslint-plugin 定制规则
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 禁用行尾空白
9
+ // 这条规则不允许在行末有尾随空格(空格、制表符和其他 Unicode 空白字符)
10
+ // https://eslint.style/rules/no-trailing-spaces
11
+ "@stylistic/no-trailing-spaces": ["warn", {
12
+ skipBlankLines: true,
13
+ ignoreComments: false,
14
+ }],
15
+
16
+ // 禁止出现多行空行
17
+ // https://eslint.style/rules/no-multiple-empty-lines
18
+ "@stylistic/no-multiple-empty-lines": ["warn", {
19
+ max: 2,
20
+ maxBOF: 1,
21
+ maxEOF: 1,
22
+ }],
23
+ },
24
+ };