@houheaven/eslint-config-helper 1.0.0 → 1.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.
Files changed (52) hide show
  1. package/README.md +112 -53
  2. package/format.js +40 -0
  3. package/html.js +32 -0
  4. package/index.js +18 -0
  5. package/lib/configs/eslint-es5.js +24 -0
  6. package/lib/configs/eslint.js +23 -0
  7. package/lib/configs/format-html.js +22 -0
  8. package/lib/configs/format-js.js +134 -0
  9. package/{eslint/prettier.js → lib/configs/format-prettier.js} +109 -45
  10. package/lib/configs/format-vue.js +278 -0
  11. package/lib/configs/html.js +20 -0
  12. package/lib/configs/import-bugfix.js +36 -0
  13. package/lib/configs/import.js +44 -0
  14. package/lib/configs/vue2.js +28 -0
  15. package/lib/configs/vue3.js +28 -0
  16. package/{eslint/rules → lib/rules/eslint}/best-practices.js +19 -19
  17. package/{eslint/rules → lib/rules/eslint}/es6.js +8 -9
  18. package/{eslint/rules → lib/rules/eslint}/node.js +0 -0
  19. package/{eslint/rules → lib/rules/eslint}/possible-errors.js +16 -11
  20. package/{eslint/rules → lib/rules/eslint}/strict-mode.js +0 -0
  21. package/{eslint/rules → lib/rules/eslint}/stylistic-issues.js +60 -59
  22. package/{eslint/rules → lib/rules/eslint}/variables.js +13 -11
  23. package/lib/rules/html/accessibility.js +44 -0
  24. package/lib/rules/html/best-practice.js +64 -0
  25. package/lib/rules/html/seo.js +24 -0
  26. package/lib/rules/html/style.js +32 -0
  27. package/lib/rules/import/helpful-warnings.js +68 -0
  28. package/lib/rules/import/module-systems.js +34 -0
  29. package/lib/rules/import/static-analysis.js +69 -0
  30. package/lib/rules/import/style-guide.js +97 -0
  31. package/lib/rules/vue/common-base.js +29 -0
  32. package/lib/rules/vue/common-eslint.js +220 -0
  33. package/lib/rules/vue/common-essential.js +267 -0
  34. package/lib/rules/vue/common-extra.js +282 -0
  35. package/lib/rules/vue/common-recommended.js +96 -0
  36. package/lib/rules/vue/common-strongly-recommended.js +138 -0
  37. package/lib/rules/vue/vue2-essential.js +41 -0
  38. package/lib/rules/vue/vue2-recommended.js +17 -0
  39. package/lib/rules/vue/vue2-strongly-recommended.js +16 -0
  40. package/lib/rules/vue/vue3-essential.js +129 -0
  41. package/lib/rules/vue/vue3-recommended.js +17 -0
  42. package/lib/rules/vue/vue3-strongly-recommended.js +24 -0
  43. package/lib/rules/vuejs-accessibility/index.js +92 -0
  44. package/package.json +37 -28
  45. package/vue2.js +30 -0
  46. package/vue3.js +28 -0
  47. package/eslint/eslint-fix.js +0 -29
  48. package/eslint/file-bof-eof.js +0 -22
  49. package/eslint/index.js +0 -18
  50. package/eslint/legacy.js +0 -34
  51. package/eslint/rules/imports.js +0 -279
  52. package/eslint/rules/vue.js +0 -23
package/README.md CHANGED
@@ -1,53 +1,112 @@
1
- # @houheaven/eslint-config-helper
2
-
3
- > Eslint 规则助手
4
-
5
-
6
- ## 安装
7
-
8
- ```sh
9
- npm install --dev @houheaven/eslint-config-helper
10
- ```
11
-
12
- 请确保你已经安装了 `eslint`
13
-
14
- ## 用法
15
-
16
- 在 Eslint 配置文件中的 `"extends"` 数组里添加 `"@houheaven/eslint-config-helper"`
17
-
18
- ```js
19
- // .eslintrc.js
20
-
21
- module.exports = {
22
- extends: [
23
- // ... 其他配置
24
- "@houheaven/eslint-config-helper"
25
- ]
26
- }
27
- ```
28
-
29
- ## 修改 Eslint 规则
30
-
31
- Eslint 官网:http://eslint.org/
32
-
33
- 在 Eslint 配置文件中的 `"rules"` 里添加规则配置。
34
-
35
- ```js
36
- // .eslintrc.js
37
-
38
- module.exports = {
39
- rules: {
40
- "quotes": ["warn", "double"],
41
- "no-multiple-empty-lines": ["warn", {
42
- "max": 2,
43
- "maxBOF": 1,
44
- "maxEOF": 1
45
- }]
46
- }
47
- };
48
- ```
49
-
50
- ## 更多
51
-
52
- 功能依赖:
53
- - [`eslint`](https://www.npmjs.com/package/eslint)
1
+
2
+ # @houheaven/eslint-config-helper
3
+
4
+ > Eslint 规则助手
5
+ > 主要功能是处理 html、JavaScript、Vue 中的语法校验、代码格式化
6
+
7
+
8
+ ## 特点
9
+ - 内置了 `Eslint`,并对其规则进行了优化
10
+ - 内置了 `eslint-plugin-import`,并对其规则进行了优化
11
+ - 内置了 `eslint-plugin-vue`,并对其规则进行了优化
12
+ - 内置了 `eslint-plugin-vuejs-accessibility`,并对其规则进行了优化
13
+ - 内置了 `@html-eslint/eslint-plugin`,并对其规则进行了优化
14
+ - 支持 html、JavaScript、Vue2、Vue3
15
+
16
+
17
+ ## 安装
18
+
19
+ ```sh
20
+ npm install --dev @houheaven/eslint-config-helper
21
+ ```
22
+
23
+ ## 用法
24
+
25
+ 在 Eslint 配置文件中的 `"extends"` 数组里添加 `"@houheaven/eslint-config-helper"`
26
+
27
+ ```js
28
+ // .eslintrc.js
29
+
30
+ module.exports = {
31
+ extends: [
32
+ // ... 其他配置
33
+ "@houheaven/eslint-config-helper"
34
+ ]
35
+ };
36
+ ```
37
+
38
+ 我们提供了多种模式,分别用来处理不同的场景
39
+ | 模式名称 | 功能说明 | 适用场景 |
40
+ | ------ | ------ | ------ |
41
+ | @houheaven/eslint-config-helper | `语法校验` `代码格式化` | `js` |
42
+ | @houheaven/eslint-config-helper/vue2 | `语法校验` `代码格式化` | `js` `vue2` |
43
+ | @houheaven/eslint-config-helper/vue3 | `语法校验` `代码格式化` | `js` `vue3` |
44
+ | @houheaven/eslint-config-helper/html | `语法校验` `代码格式化` | `js` `html` |
45
+ | @houheaven/eslint-config-helper/format | `代码格式化` | `js` `vue2` `vue3` |
46
+
47
+
48
+ ## 修改 Eslint 规则
49
+
50
+ 在 Eslint 配置文件中的 `"rules"` 里添加规则。
51
+
52
+ ```js
53
+ // .eslintrc.js
54
+
55
+ module.exports = {
56
+ // eslint 其他配置
57
+ // ……
58
+ rules: {
59
+ // js 规则
60
+ "quotes": ["warn", "double"],
61
+ "no-multiple-empty-lines": ["warn", {
62
+ max: 2,
63
+ maxBOF: 1,
64
+ maxEOF: 1
65
+ }],
66
+ // import 规则
67
+ "import/first": "error",
68
+ "import/no-unresolved": ["error", {
69
+ commonjs: true,
70
+ caseSensitive: true,
71
+ }],
72
+ // vue 规则
73
+ "vue/eqeqeq": ["error", "always", { null: "ignore" }],
74
+ "vue/custom-event-name-casing": ["warn", "kebab-case"],
75
+ // vuejs-accessibility 规则
76
+ "vuejs-accessibility/alt-text": "off",
77
+ "vuejs-accessibility/no-onchange": "off",
78
+ // html 规则
79
+ "@html-eslint/require-title": "error",
80
+ "@html-eslint/no-duplicate-id": "error",
81
+ }
82
+ };
83
+ ```
84
+
85
+ - 查看 [`Eslint 规则文档`](https://www.npmjs.com/package/eslint)
86
+ - 查看 [`eslint-plugin-import 规则文档`](https://www.npmjs.com/package/eslint-plugin-import)
87
+ - 查看 [`eslint-plugin-vue 规则文档`](https://eslint.vuejs.org/rules/)
88
+ - 查看 [`eslint-plugin-vuejs-accessibility 规则文档`](https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility/tree/main/docs)
89
+ - 查看 [`@html-eslint 规则文档`](https://yeonjuan.github.io/html-eslint/docs/getting-started.html)
90
+
91
+ <!--
92
+ ## 常见问题
93
+
94
+ ### Vue3 中会产生 import/no-unresolved 错误
95
+
96
+ 解决方案:https://stackoverflow.com/questions/67835072/vue-3-on-vite-js-with-eslint-unable-to-resolve-path-to-module-eslintimport-no
97
+ 依赖包:[`eslint-import-resolver-alias`](https://www.npmjs.com/package/eslint-import-resolver-alias)
98
+ -->
99
+
100
+ ## 更多
101
+
102
+ 功能依赖:
103
+ - [`eslint`](https://www.npmjs.com/package/eslint)
104
+ - [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import)
105
+ - [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue)
106
+ - [`eslint-plugin-vuejs-accessibility`](https://www.npmjs.com/package/eslint-plugin-vuejs-accessibility)
107
+ - [`eslint-plugin-html`](https://www.npmjs.com/package/eslint-plugin-html)
108
+ - [`eslint-import-resolver-alias`](https://www.npmjs.com/package/eslint-import-resolver-alias)
109
+ - [`eslint-import-resolver-node`](https://www.npmjs.com/package/eslint-import-resolver-node)
110
+ - [`eslint-import-resolver-webpack`](https://www.npmjs.com/package/eslint-import-resolver-webpack)
111
+ - [`@html-eslint/eslint-plugin`](https://www.npmjs.com/package/@html-eslint/eslint-plugin)
112
+ - [`@html-eslint/parser`](https://www.npmjs.com/package/@html-eslint/parser)
package/format.js ADDED
@@ -0,0 +1,40 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper/format
4
+ // ----------------------------------------------------------
5
+ // 说明:代码格式化,功能非常的基础、安全
6
+ // - ./lib/configs/format-js.js : js 定制规则
7
+ // - ./lib/configs/format-vue.js : vue 定制规则
8
+ // - ./lib/configs/format-html.js : html 定制规则
9
+ // ==========================================================
10
+
11
+ module.exports = {
12
+ extends: [
13
+ "./lib/configs/format-js.js",
14
+ ],
15
+ parserOptions: {
16
+ ecmaVersion: "latest",
17
+ sourceType: "module",
18
+ },
19
+ overrides: [
20
+ {
21
+ files: ["*.vue", "**/*.vue"],
22
+ extends: [
23
+ "./lib/rules/vue/common-base.js",
24
+ "./lib/configs/format-vue.js",
25
+ ],
26
+ rules: {
27
+ "indent": "off",
28
+ },
29
+ },
30
+ {
31
+ files: ["*.html", "**/*.html", "*.htm", "**/*.htm"],
32
+ extends: [
33
+ "./lib/configs/format-html.js",
34
+ ],
35
+ rules: {
36
+ "eol-last": ["warn", "never"],
37
+ },
38
+ },
39
+ ],
40
+ };
package/html.js ADDED
@@ -0,0 +1,32 @@
1
+
2
+ // ===============================================================================
3
+ // @houheaven/eslint-config-helper/html
4
+ // -------------------------------------------------------------------------------
5
+ // - ./lib/configs/eslint-es5.j : Eslint ES5 定制规则
6
+ // - ./lib/configs/html.js : @html-eslint/eslint-plugin 定制规则
7
+ // ===============================================================================
8
+
9
+ module.exports = {
10
+ extends: [
11
+ "./lib/configs/eslint-es5.js",
12
+ ],
13
+ overrides: [
14
+ {
15
+ files: ["*.html", "**/*.html", "*.htm", "**/*.htm"],
16
+ extends: ["./lib/configs/html.js"],
17
+ rules: {
18
+ // 此处不可删除,解决 html 中 <script> 换行问题
19
+ "eol-last": ["warn", "never"],
20
+ },
21
+ },
22
+ {
23
+ files: ["*.html", "**/*.html", "*.htm", "**/*.htm"],
24
+ plugins: ["eslint-plugin-html"],
25
+ rules: {
26
+ // 此处不可删除,解决 html 中 <script> 换行问题
27
+ "eol-last": "off",
28
+ "space-before-function-paren": "off",
29
+ },
30
+ },
31
+ ],
32
+ };
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+
2
+ // ==========================================================
3
+ // @houheaven/eslint-config-helper
4
+ // ----------------------------------------------------------
5
+ // - ./lib/configs/eslint.js : eslint 定制规则
6
+ // - ./lib/configs/import.js : eslint-plugin-import 定制规则
7
+ // ==========================================================
8
+
9
+ module.exports = {
10
+ extends: [
11
+ "./lib/configs/eslint.js",
12
+ "./lib/configs/import.js",
13
+ ],
14
+ parserOptions: {
15
+ ecmaVersion: "latest",
16
+ sourceType: "module",
17
+ },
18
+ };
@@ -0,0 +1,24 @@
1
+
2
+ // ==========================================================
3
+ // Eslint ES5 规则
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ env: {
8
+ browser: true,
9
+ jquery: true,
10
+ },
11
+ parserOptions: {
12
+ ecmaVersion: 5,
13
+ sourceType: "script",
14
+ },
15
+ extends: [
16
+ "../rules/eslint/best-practices.js",
17
+ "../rules/eslint/possible-errors.js",
18
+ "../rules/eslint/stylistic-issues.js",
19
+ "../rules/eslint/strict-mode.js",
20
+ "../rules/eslint/variables.js",
21
+ // "../rules/eslint/node.js",
22
+ // "../rules/eslint/es6.js",
23
+ ].map(require.resolve),
24
+ };
@@ -0,0 +1,23 @@
1
+
2
+ // ==========================================================
3
+ // Eslint 规则
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ env: {
8
+ browser: true,
9
+ node: true,
10
+ amd: false,
11
+ mocha: false,
12
+ jasmine: false,
13
+ },
14
+ extends: [
15
+ "../rules/eslint/best-practices.js",
16
+ "../rules/eslint/possible-errors.js",
17
+ "../rules/eslint/stylistic-issues.js",
18
+ "../rules/eslint/strict-mode.js",
19
+ "../rules/eslint/variables.js",
20
+ "../rules/eslint/node.js",
21
+ "../rules/eslint/es6.js",
22
+ ].map(require.resolve),
23
+ };
@@ -0,0 +1,22 @@
1
+
2
+ // ==========================================================
3
+ // html 文件代码格式化
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ parser: "@html-eslint/parser",
8
+ plugins: ["@html-eslint"],
9
+ rules: {
10
+ // 要求设置 <!DOCTYPE html> 文档申明
11
+ "@html-eslint/require-doctype": "warn",
12
+
13
+ // 要求标签闭合
14
+ "@html-eslint/require-closing-tags": ["warn", { selfClosing: "always" }],
15
+
16
+ // 强制使用一致的引号
17
+ "@html-eslint/quotes": ["warn", "double"],
18
+
19
+ // 禁止出现多个空行
20
+ "@html-eslint/no-multiple-empty-lines": ["warn", { max: 2 }],
21
+ },
22
+ };
@@ -0,0 +1,134 @@
1
+
2
+ // ==========================================================
3
+ // JS 文件代码格式化
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // Best Practices - 最佳实践
9
+ // "eqeqeq": ["error", "always", { null: "ignore" }],
10
+
11
+ // ES6
12
+ "arrow-parens": ["warn", "as-needed"],
13
+ "arrow-spacing": ["warn", {
14
+ before: true,
15
+ after: true,
16
+ }],
17
+ "arrow-body-style": ["error", "as-needed", {
18
+ requireReturnForObjectLiteral: false,
19
+ }],
20
+ "prefer-template": "warn",
21
+ "template-curly-spacing": "warn",
22
+
23
+ // Stylistic Issues
24
+ "quotes": ["warn", "double", { "avoidEscape": true }],
25
+ "linebreak-style": ["warn", "unix"],
26
+ "comma-spacing": ["warn", {
27
+ before: false,
28
+ after: true,
29
+ }],
30
+ "comma-dangle": ["warn", {
31
+ arrays: "always-multiline",
32
+ objects: "always-multiline",
33
+ imports: "always-multiline",
34
+ exports: "always-multiline",
35
+ functions: "never",
36
+ }],
37
+ "keyword-spacing": ["warn", {
38
+ "before": true,
39
+ "after": true,
40
+ "overrides": {
41
+ "if": { "after": true },
42
+ "for": { "after": false },
43
+ "while": { "after": false },
44
+ "switch": { "after": false },
45
+ "case": { "after": true },
46
+ "catch": { "after": false },
47
+ "return": { "after": true },
48
+ "throw": { "after": true },
49
+ },
50
+ }],
51
+ "object-curly-spacing": ["warn", "always", {
52
+ arraysInObjects: true,
53
+ objectsInObjects: true,
54
+ }],
55
+ "object-curly-newline": ["warn", {
56
+ ObjectExpression: { minProperties: 40, multiline: true, consistent: true },
57
+ ObjectPattern: "never",
58
+ ImportDeclaration: "never",
59
+ ExportDeclaration: "always",
60
+ }],
61
+ "array-bracket-spacing": ["warn", "never"],
62
+ "space-in-parens": ["warn", "never"],
63
+ "space-infix-ops": "warn",
64
+ "semi-spacing": ["error", { before: false, after: true }],
65
+ "space-before-blocks": ["warn", {
66
+ "functions": "always",
67
+ "keywords": "always",
68
+ "classes": "always",
69
+ }],
70
+ "brace-style": ["warn", "stroustrup", { "allowSingleLine": true }],
71
+
72
+
73
+ // 文件首尾空行
74
+
75
+ // 要求或禁止文件末尾存在空行
76
+ "eol-last": ["warn", "always"],
77
+
78
+ // 禁止出现多行空行
79
+ "no-multiple-empty-lines": ["warn", {
80
+ "max": 2,
81
+ "maxBOF": 1,
82
+ "maxEOF": 1,
83
+ }],
84
+
85
+ // 禁用行尾空白
86
+ "no-trailing-spaces": ["warn", {
87
+ "skipBlankLines": true,
88
+ "ignoreComments": false,
89
+ }],
90
+
91
+ // 强制使用一致的缩进
92
+ "indent": ["error", 2, {
93
+ SwitchCase: 1,
94
+ VariableDeclarator: 1,
95
+ outerIIFEBody: 1,
96
+ // MemberExpression: null,
97
+ FunctionDeclaration: {
98
+ parameters: 1,
99
+ body: 1,
100
+ },
101
+ FunctionExpression: {
102
+ parameters: 1,
103
+ body: 1,
104
+ },
105
+ CallExpression: {
106
+ arguments: 1,
107
+ },
108
+ ArrayExpression: 1,
109
+ ObjectExpression: 1,
110
+ ImportDeclaration: 1,
111
+ flatTernaryExpressions: false,
112
+ // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
113
+ ignoredNodes: [
114
+ "JSXElement",
115
+ "JSXElement > *",
116
+ "JSXAttribute",
117
+ "JSXIdentifier",
118
+ "JSXNamespacedName",
119
+ "JSXMemberExpression",
120
+ "JSXSpreadAttribute",
121
+ "JSXExpressionContainer",
122
+ "JSXOpeningElement",
123
+ "JSXClosingElement",
124
+ "JSXFragment",
125
+ "JSXOpeningFragment",
126
+ "JSXClosingFragment",
127
+ "JSXText",
128
+ "JSXEmptyExpression",
129
+ "JSXSpreadChild",
130
+ ],
131
+ ignoreComments: false,
132
+ }],
133
+ },
134
+ };