@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
@@ -0,0 +1,220 @@
1
+
2
+ // ==========================================================
3
+ // 拓展规则(Extension Rules)
4
+ // 基于 eslint 部分基础规则,用于 <template> 内容规则校验、格式化
5
+ // ==========================================================
6
+
7
+ module.exports = {
8
+ rules: {
9
+ // 在数组开括号后和闭括号前强制换行
10
+ "vue/array-bracket-newline": ["warn", "consistent"],
11
+
12
+ // 强制数组方括号中使用一致的空格
13
+ "vue/array-bracket-spacing": ["warn", "never"],
14
+
15
+ // 禁止稀疏数组
16
+ "vue/no-sparse-arrays": "error",
17
+
18
+ // 要求箭头函数的箭头之前或之后有空格
19
+ "vue/arrow-spacing": ["warn", {
20
+ before: true,
21
+ after: true,
22
+ }],
23
+
24
+ // 强制大括号内换行符的一致性
25
+ "vue/object-curly-newline": ["warn", {
26
+ ObjectExpression: "never",
27
+ ObjectPattern: "never",
28
+ ImportDeclaration: "never",
29
+ ExportDeclaration: "never",
30
+ }],
31
+
32
+ // 强制在花括号中使用一致的空格
33
+ "vue/object-curly-spacing": ["warn", "always", {
34
+ arraysInObjects: true,
35
+ objectsInObjects: true,
36
+ }],
37
+
38
+ // 强制将对象的属性放在不同的行上
39
+ "vue/object-property-newline": ["off", {
40
+ allowAllPropertiesOnSameLine: true,
41
+ }],
42
+
43
+ // 要求或禁止对象字面量的方法和属性简写语法
44
+ "vue/object-shorthand": ["warn", "always", {
45
+ ignoreConstructors: false,
46
+ avoidQuotes: true,
47
+ }],
48
+
49
+ // 要求对象字面量属性名称用引号括起来
50
+ "vue/quote-props": ["warn", "consistent"],
51
+
52
+ // 强制在对象字面量的键和值之间使用一致的空格
53
+ "vue/key-spacing": ["warn", {
54
+ beforeColon: false,
55
+ afterColon: true,
56
+ }],
57
+
58
+ // 禁止或强制在代码块中开括号前和闭括号后有空格
59
+ "vue/block-spacing": ["warn", "always"],
60
+
61
+ // 强制在代码块中使用一致的大括号风格
62
+ "vue/brace-style": ["warn", "stroustrup", { "allowSingleLine": true }],
63
+
64
+ // 要求使用骆驼拼写法
65
+ "vue/camelcase": ["off", {
66
+ properties: "never",
67
+ ignoreDestructuring: false,
68
+ }],
69
+
70
+ // 要求或禁止使用拖尾逗号(对象、数组、导入、导出、函数参数的最后一项后面是否允许有逗号)
71
+ "vue/comma-dangle": ["warn", {
72
+ arrays: "always-multiline",
73
+ objects: "always-multiline",
74
+ imports: "always-multiline",
75
+ exports: "always-multiline",
76
+ functions: "never",
77
+ }],
78
+
79
+ // 强制在逗号前后使用一致的空格
80
+ "vue/comma-spacing": ["warn", {
81
+ before: false,
82
+ after: true,
83
+ }],
84
+
85
+ // 强制使用一致的逗号风格
86
+ "vue/comma-style": ["warn", "last", {
87
+ exceptions: {
88
+ ArrayExpression: false,
89
+ ArrayPattern: false,
90
+ ArrowFunctionExpression: false,
91
+ CallExpression: false,
92
+ FunctionDeclaration: false,
93
+ FunctionExpression: false,
94
+ ImportDeclaration: false,
95
+ ObjectExpression: false,
96
+ ObjectPattern: false,
97
+ VariableDeclaration: false,
98
+ NewExpression: false,
99
+ },
100
+ }],
101
+
102
+ // 强制在点号之前和之后一致的换行
103
+ "vue/dot-location": ["warn", "property"],
104
+
105
+ // 尽可能的使用点符号
106
+ "vue/dot-notation": ["warn", { allowKeywords: true }],
107
+
108
+ // 要求使用 === 和 !==
109
+ "vue/eqeqeq": ["error", "always", { null: "ignore" }],
110
+
111
+ // 要求或禁止在函数标识符和其调用之间有空格
112
+ "vue/func-call-spacing": ["warn", "never"],
113
+
114
+ // 强制关键字周围空格的一致性
115
+ "vue/keyword-spacing": ["warn", {
116
+ "before": true,
117
+ "after": true,
118
+ "overrides": {
119
+ "if": { "after": true },
120
+ "for": { "after": false },
121
+ "while": { "after": false },
122
+ "switch": { "after": false },
123
+ "case": { "after": true },
124
+ "catch": { "after": false },
125
+ "return": { "after": true },
126
+ "throw": { "after": true },
127
+ },
128
+ }],
129
+
130
+ // 强制一行的最大长度
131
+ "vue/max-len": ["warn", {
132
+ "code": 200,
133
+ "comments": 200,
134
+ "template": 200,
135
+ "tabWidth": 2,
136
+ "ignorePattern": "",
137
+ "ignoreComments": false,
138
+ "ignoreTrailingComments": false,
139
+ "ignoreUrls": true,
140
+ "ignoreStrings": true,
141
+ "ignoreTemplateLiterals": true,
142
+ "ignoreRegExpLiterals": true,
143
+ "ignoreHTMLAttributeValues": true,
144
+ "ignoreHTMLTextContents": true,
145
+ }],
146
+
147
+ // 禁止条件中的常量表达式
148
+ "vue/no-constant-condition": "warn",
149
+
150
+ // 禁止空的解构模式
151
+ "vue/no-empty-pattern": "error",
152
+
153
+ // 禁止冗余的括号
154
+ "vue/no-extra-parens": ["off", "all", {
155
+ conditionalAssign: true,
156
+ nestedBinaryExpressions: false,
157
+ returnAssign: false,
158
+ ignoreJSX: "all", // delegate to eslint-plugin-react
159
+ enforceForArrowConditionals: false,
160
+ }],
161
+
162
+ // 禁止不规则的空格
163
+ "vue/no-irregular-whitespace": ["error", {
164
+ "skipStrings": true,
165
+ "skipComments": false,
166
+ "skipRegExps": false,
167
+ "skipTemplates": false,
168
+ "skipHTMLAttributeValues": false,
169
+ "skipHTMLTextContents": false,
170
+ }],
171
+
172
+ // 禁止失去精度的文字数字
173
+ "vue/no-loss-of-precision": "error",
174
+
175
+ // 禁用特定的语法
176
+ "vue/no-restricted-syntax": [
177
+ "off",
178
+ {
179
+ selector: "ForInStatement",
180
+ message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
181
+ },
182
+ {
183
+ selector: "ForOfStatement",
184
+ message: "iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.",
185
+ },
186
+ {
187
+ selector: "LabeledStatement",
188
+ message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
189
+ },
190
+ {
191
+ selector: "WithStatement",
192
+ message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
193
+ },
194
+ ],
195
+
196
+ // 禁止不必要的文字或模板文字串联
197
+ "vue/no-useless-concat": "warn",
198
+
199
+ // 强制操作符使用一致的换行符
200
+ "vue/operator-linebreak": ["off", "before", { overrides: { "=": "none" } }],
201
+
202
+ // 要求使用模板文字进行字符串连接
203
+ "vue/prefer-template": "warn",
204
+
205
+ // 强制在圆括号内使用一致的空格
206
+ "vue/space-in-parens": ["warn", "never"],
207
+
208
+ // 要求中缀操作符周围有空格(+-*/?| etc.)
209
+ "vue/space-infix-ops": "warn",
210
+
211
+ // 强制在一元操作符前后使用一致的空格
212
+ "vue/space-unary-ops": ["warn", {
213
+ words: true,
214
+ nonwords: false,
215
+ }],
216
+
217
+ // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
218
+ "vue/template-curly-spacing": "warn",
219
+ },
220
+ };
@@ -0,0 +1,267 @@
1
+
2
+ // ==========================================================
3
+ // 极其重要的规则(通用)
4
+ // plugin:vue/essential、plugin:vue/vue3-essential 通用部分
5
+ // ==========================================================
6
+
7
+ module.exports = {
8
+ rules: {
9
+ // 组件名称必须是多词组合
10
+ // https://eslint.vuejs.org/rules/multi-word-component-names.html
11
+ "vue/multi-word-component-names": "off",
12
+
13
+ // watch 中禁止使用箭头函数
14
+ // https://eslint.vuejs.org/rules/no-arrow-functions-in-watch.html
15
+ "vue/no-arrow-functions-in-watch": "error",
16
+
17
+ // computed 中禁用异步操作
18
+ // https://eslint.vuejs.org/rules/no-async-in-computed-properties.html
19
+ "vue/no-async-in-computed-properties": "error",
20
+
21
+ // 使用了 v-html、v-text 的元素不能含有子内容(会被覆盖)
22
+ // https://eslint.vuejs.org/rules/no-child-content.html
23
+ "vue/no-child-content": "error",
24
+
25
+ // 禁止在 data 中使用 computed 属性
26
+ // https://eslint.vuejs.org/rules/no-computed-properties-in-data.html
27
+ "vue/no-computed-properties-in-data": "error",
28
+
29
+ // 字段名称不能重复
30
+ // https://eslint.vuejs.org/rules/no-dupe-keys.html
31
+ "vue/no-dupe-keys": "error",
32
+
33
+ // 在 v-if / v-else-if 链条中,不能出现重复的条件
34
+ // https://eslint.vuejs.org/rules/no-dupe-v-else-if.html
35
+ "vue/no-dupe-v-else-if": "error",
36
+
37
+ // 在元素标签中,禁止出现重复的属性
38
+ // https://eslint.vuejs.org/rules/no-duplicate-attributes.html
39
+ "vue/no-duplicate-attributes": "error",
40
+
41
+ // 在 <script setup> 中,禁止出现 export 导出关键字
42
+ // https://eslint.vuejs.org/rules/no-export-in-script-setup.html
43
+ "vue/no-export-in-script-setup": "error",
44
+
45
+ // 禁止组件 props 值的突变(必须使用 emit 修改 props 值)
46
+ // https://eslint.vuejs.org/rules/no-mutating-props.html
47
+ "vue/no-mutating-props": "error",
48
+
49
+ // 在 <template> 中,不允许出现语法错误的代码
50
+ // https://eslint.vuejs.org/rules/no-parsing-error.html
51
+ "vue/no-parsing-error": ["error", {
52
+ "abrupt-closing-of-empty-comment": true,
53
+ "absence-of-digits-in-numeric-character-reference": true,
54
+ "cdata-in-html-content": true,
55
+ "character-reference-outside-unicode-range": true,
56
+ "control-character-in-input-stream": true,
57
+ "control-character-reference": true,
58
+ "eof-before-tag-name": true,
59
+ "eof-in-cdata": true,
60
+ "eof-in-comment": true,
61
+ "eof-in-tag": true,
62
+ "incorrectly-closed-comment": true,
63
+ "incorrectly-opened-comment": true,
64
+ "invalid-first-character-of-tag-name": true,
65
+ "missing-attribute-value": true,
66
+ "missing-end-tag-name": true,
67
+ "missing-semicolon-after-character-reference": true,
68
+ "missing-whitespace-between-attributes": true,
69
+ "nested-comment": true,
70
+ "noncharacter-character-reference": true,
71
+ "noncharacter-in-input-stream": true,
72
+ "null-character-reference": true,
73
+ "surrogate-character-reference": true,
74
+ "surrogate-in-input-stream": true,
75
+ "unexpected-character-in-attribute-name": true,
76
+ "unexpected-character-in-unquoted-attribute-value": true,
77
+ "unexpected-equals-sign-before-attribute-name": true,
78
+ "unexpected-null-character": true,
79
+ "unexpected-question-mark-instead-of-tag-name": true,
80
+ "unexpected-solidus-in-tag": true,
81
+ "unknown-named-character-reference": true,
82
+ "end-tag-with-attributes": true,
83
+ "duplicate-attribute": true,
84
+ "end-tag-with-trailing-solidus": true,
85
+ "non-void-html-element-start-tag-with-trailing-solidus": false,
86
+ "x-invalid-end-tag": true,
87
+ "x-invalid-namespace": true,
88
+ }],
89
+
90
+ // 组合 API(Composition API)中,ref() 值 value 的用法
91
+ // https://eslint.vuejs.org/rules/no-ref-as-operand.html
92
+ "vue/no-ref-as-operand": "error",
93
+
94
+ // 组件名称不能为保留的元素标签名
95
+ // 比如:html/div、vue2/transition、vue3/teleport 等
96
+ // https://eslint.vuejs.org/rules/no-reserved-component-names.html
97
+ "vue/no-reserved-component-names": ["error", {
98
+ "disallowVueBuiltInComponents": true,
99
+ "disallowVue3BuiltInComponents": true,
100
+ }],
101
+
102
+ // 禁止重写保留关键字
103
+ // https://eslint.vuejs.org/rules/no-reserved-keys.html
104
+ "vue/no-reserved-keys": "error",
105
+
106
+ // 禁止在 props 中使用保留关键字
107
+ // https://eslint.vuejs.org/rules/no-reserved-props.html
108
+ "vue/no-reserved-props": ["error", {
109
+ "vueVersion": 3,
110
+ }],
111
+
112
+ // https://eslint.vuejs.org/rules/no-setup-props-destructure.html
113
+ "vue/no-setup-props-destructure": "error",
114
+
115
+ // 强制组件的 data 必须为函数
116
+ // https://eslint.vuejs.org/rules/no-shared-component-data.html
117
+ "vue/no-shared-component-data": "error",
118
+
119
+ // 不允许计算属性中的副作用
120
+ // https://eslint.vuejs.org/rules/no-side-effects-in-computed-properties.html
121
+ "vue/no-side-effects-in-computed-properties": "error",
122
+
123
+ // 在 <template v-for> 上不允许使用 key
124
+ // https://eslint.vuejs.org/rules/no-template-key.html
125
+ "vue/no-template-key": "error",
126
+
127
+ // 禁止在 textarea 标签中使用 mustache 语法
128
+ // https://eslint.vuejs.org/rules/no-textarea-mustache.html
129
+ // mustache 语法介绍:https://zhuanlan.zhihu.com/p/36572041
130
+ "vue/no-textarea-mustache": "error",
131
+
132
+ // 禁止组件定义后不使用
133
+ // https://eslint.vuejs.org/rules/no-unused-components.html
134
+ "vue/no-unused-components": ["error", {
135
+ "ignoreWhenBindingPresent": true,
136
+ }],
137
+
138
+ // 禁止 v-for 指令 或 scope 属性中出现未使用的变量定义
139
+ // https://eslint.vuejs.org/rules/no-unused-vars.html
140
+ "vue/no-unused-vars": "error",
141
+
142
+ // https://eslint.vuejs.org/rules/no-use-computed-property-like-method.html
143
+ "vue/no-use-computed-property-like-method": "error",
144
+
145
+ // 禁止在同一个元素标签上使用 v-for、v-if
146
+ // https://eslint.vuejs.org/rules/no-use-v-if-with-v-for.html
147
+ "vue/no-use-v-if-with-v-for": "error",
148
+
149
+ // 禁止在 <template> 上使用无效的属性
150
+ // https://eslint.vuejs.org/rules/no-useless-template-attributes.html
151
+ "vue/no-useless-template-attributes": "error",
152
+
153
+ // 禁止在组件上使用 v-text / v-html
154
+ // https://eslint.vuejs.org/rules/no-v-text-v-html-on-component.html
155
+ "vue/no-v-text-v-html-on-component": "error",
156
+
157
+ // 使用 <component> 元素时,必须使用 v-bind:is
158
+ // https://eslint.vuejs.org/rules/require-component-is.html
159
+ "vue/require-component-is": "error",
160
+
161
+ // 要求 prop 中的 type 必须是构造函数
162
+ // https://eslint.vuejs.org/rules/require-prop-type-constructor.html
163
+ "vue/require-prop-type-constructor": "error",
164
+
165
+ // 要求 render 函数必须有一个返回值
166
+ // https://eslint.vuejs.org/rules/require-render-return.html
167
+ "vue/require-render-return": "error",
168
+
169
+ // 要求 v-for 指令必须含有 v-bind:key
170
+ // https://eslint.vuejs.org/rules/require-v-for-key.html
171
+ "vue/require-v-for-key": "error",
172
+
173
+ // 强制 props 中的 default 值必须有效(数组、对象必须是函数类型)
174
+ // https://eslint.vuejs.org/rules/require-valid-default-prop.html
175
+ "vue/require-valid-default-prop": "error",
176
+
177
+ // 在计算属性中必须存在返回语句
178
+ // https://eslint.vuejs.org/rules/return-in-computed-property.html
179
+ "vue/return-in-computed-property": ["error", {
180
+ "treatUndefinedAsUnspecified": true,
181
+ }],
182
+
183
+ // 强制在emits验证器中存在返回语句
184
+ // https://eslint.vuejs.org/rules/return-in-emits-validator.html
185
+ "vue/return-in-emits-validator": "error",
186
+
187
+ // 在 v-on 上强制 exact 修饰符的用法
188
+ // https://eslint.vuejs.org/rules/use-v-on-exact.html
189
+ "vue/use-v-on-exact": "error",
190
+
191
+ // 强制使用有效的属性名
192
+ // https://eslint.vuejs.org/rules/valid-attribute-name.html
193
+ "vue/valid-attribute-name": "error",
194
+
195
+ // 强制使用有效的 defineEmits 编译器宏
196
+ // https://eslint.vuejs.org/rules/valid-define-emits.html
197
+ "vue/valid-define-emits": "error",
198
+
199
+ // 强制使用有效的 defineProps 编译器宏
200
+ // https://eslint.vuejs.org/rules/valid-define-props.html
201
+ "vue/valid-define-props": "error",
202
+
203
+ // 强制使用有效的 nextTick 函数回调
204
+ // https://eslint.vuejs.org/rules/valid-next-tick.html
205
+ "vue/valid-next-tick": "error",
206
+
207
+ // 强制使用有效的 template 根节点
208
+ // https://eslint.vuejs.org/rules/valid-template-root.html
209
+ "vue/valid-template-root": "error",
210
+
211
+ // 强制使用有效的 v-bind 指令
212
+ // https://eslint.vuejs.org/rules/valid-v-bind.html
213
+ "vue/valid-v-bind": "error",
214
+
215
+ // 强制使用有效的 v-cloak 指令
216
+ // https://eslint.vuejs.org/rules/valid-v-cloak.html
217
+ "vue/valid-v-cloak": "error",
218
+
219
+ // 强制使用有效的 v-else-if 指令
220
+ // https://eslint.vuejs.org/rules/valid-v-else-if.html
221
+ "vue/valid-v-else-if": "error",
222
+
223
+ // 强制使用有效的 v-else 指令
224
+ // https://eslint.vuejs.org/rules/valid-v-else.html
225
+ "vue/valid-v-else": "error",
226
+
227
+ // 强制使用有效的 v-for 指令
228
+ // https://eslint.vuejs.org/rules/valid-v-for.html
229
+ "vue/valid-v-for": "error",
230
+
231
+ // 强制使用有效的 v-html 指令
232
+ // https://eslint.vuejs.org/rules/valid-v-html.html
233
+ "vue/valid-v-html": "error",
234
+
235
+ // 强制使用有效的 v-if 指令
236
+ // https://eslint.vuejs.org/rules/valid-v-if.html
237
+ "vue/valid-v-if": "error",
238
+
239
+ // 强制使用有效的 v-model 指令
240
+ // https://eslint.vuejs.org/rules/valid-v-model.html
241
+ "vue/valid-v-model": "error",
242
+
243
+ // 强制使用有效的 v-on 指令
244
+ // https://eslint.vuejs.org/rules/valid-v-on.html
245
+ "vue/valid-v-on": "error",
246
+
247
+ // 强制使用有效的 v-once 指令
248
+ // https://eslint.vuejs.org/rules/valid-v-once.html
249
+ "vue/valid-v-once": "error",
250
+
251
+ // 强制使用有效的 v-pre 指令
252
+ // https://eslint.vuejs.org/rules/valid-v-pre.html
253
+ "vue/valid-v-pre": "error",
254
+
255
+ // 强制使用有效的 v-show 指令
256
+ // https://eslint.vuejs.org/rules/valid-v-show.html
257
+ "vue/valid-v-show": "error",
258
+
259
+ // 强制使用有效的 v-slot 指令
260
+ // https://eslint.vuejs.org/rules/valid-v-slot.html
261
+ "vue/valid-v-slot": "error",
262
+
263
+ // 强制使用有效的 v-text 指令
264
+ // https://eslint.vuejs.org/rules/valid-v-text.html
265
+ "vue/valid-v-text": "error",
266
+ },
267
+ };