@houheaven/eslint-config-helper 1.4.0 → 2.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.
- package/LICENSE +21 -21
- package/README.md +149 -28
- package/lib/format-es5.js +23 -0
- package/lib/format-es6.js +25 -0
- package/lib/format-html.js +23 -0
- package/lib/format-import.js +23 -0
- package/lib/format-typescript.js +28 -0
- package/lib/format-vue2.js +23 -0
- package/lib/format-vue3.js +23 -0
- package/lib/html.js +13 -22
- package/lib/import.js +23 -0
- package/lib/javascript-es5.js +23 -0
- package/lib/javascript-es6.js +25 -0
- package/lib/rules/eslint/_deprecated.js +132 -0
- package/lib/rules/eslint/_removed.js +25 -0
- package/lib/rules/eslint/es6.js +279 -110
- package/lib/rules/eslint/layout-formatting.js +441 -0
- package/lib/rules/eslint/possible-errors.js +140 -131
- package/lib/rules/eslint/suggestions.js +666 -0
- package/lib/rules/html/accessibility.js +47 -23
- package/lib/rules/html/best-practice.js +122 -36
- package/lib/rules/html/seo.js +16 -11
- package/lib/rules/html/style.js +53 -15
- package/lib/rules/import/helpful-warnings.js +23 -18
- package/lib/rules/import/module-systems.js +16 -17
- package/lib/rules/import/static-analysis.js +54 -38
- package/lib/rules/import/style-guide.js +89 -61
- package/lib/rules/typescript/_deprecated.js +57 -0
- package/lib/rules/typescript/conflict.js +16 -0
- package/lib/rules/typescript/deprecated.js +41 -0
- package/lib/rules/typescript/extension.js +207 -0
- package/lib/rules/typescript/fixable.js +215 -0
- package/lib/rules/typescript/other.js +125 -0
- package/lib/rules/typescript/stylistic.js +34 -0
- package/lib/rules/typescript/suggestion.js +53 -0
- package/lib/rules/typescript/type-checked.js +263 -0
- package/lib/rules/vue/_deprecated.js +37 -0
- package/lib/rules/vue/common-base.js +1 -11
- package/lib/rules/vue/common-essential.js +25 -38
- package/lib/rules/vue/common-extension.js +321 -0
- package/lib/rules/vue/common-recommended.js +64 -31
- package/lib/rules/vue/common-strongly-recommended.js +37 -20
- package/lib/rules/vue/{common-extra.js → common-uncategorized.js} +141 -52
- package/lib/rules/vue/vue2-essential.js +16 -14
- package/lib/rules/vue/vue2-uncategorized.js +15 -0
- package/lib/rules/vue/vue3-essential.js +54 -24
- package/lib/rules/vue/vue3-strongly-recommended.js +8 -10
- package/lib/rules/vue/vue3-uncategorized.js +115 -0
- package/lib/support/es5-support.js +29 -0
- package/lib/support/es6-support.js +39 -0
- package/lib/support/html-support.js +38 -0
- package/lib/support/import-bugfix.js +65 -0
- package/lib/support/import-support.js +25 -0
- package/lib/support/typescript-support.js +27 -0
- package/lib/support/vue2-support.js +43 -0
- package/lib/support/vue3-support.js +43 -0
- package/lib/support/vue3-ts-support.js +51 -0
- package/lib/typescript.js +24 -32
- package/lib/utils/utils.js +160 -0
- package/lib/vue2.js +16 -22
- package/lib/vue3-ts.js +31 -0
- package/lib/vue3.js +13 -17
- package/package.json +38 -22
- package/lib/configs/eslint-es5.js +0 -24
- package/lib/configs/eslint.js +0 -23
- package/lib/configs/format-html.js +0 -22
- package/lib/configs/format-js.js +0 -134
- package/lib/configs/format-vue.js +0 -278
- package/lib/configs/html.js +0 -20
- package/lib/configs/import-bugfix.js +0 -36
- package/lib/configs/import.js +0 -44
- package/lib/configs/typescript.js +0 -10
- package/lib/configs/vue2.js +0 -28
- package/lib/configs/vue3.js +0 -28
- package/lib/eslint.js +0 -18
- package/lib/format.js +0 -40
- package/lib/rules/eslint/best-practices.js +0 -422
- package/lib/rules/eslint/node.js +0 -48
- package/lib/rules/eslint/strict-mode.js +0 -12
- package/lib/rules/eslint/stylistic-issues.js +0 -578
- package/lib/rules/eslint/variables.js +0 -73
- package/lib/rules/typescript/all.js +0 -193
- package/lib/rules/typescript/base.js +0 -10
- package/lib/rules/typescript/eslint-recommended.js +0 -36
- package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
- package/lib/rules/typescript/recommended.js +0 -36
- package/lib/rules/typescript/strict.js +0 -47
- package/lib/rules/vue/common-eslint.js +0 -220
- package/lib/rules/vue/vue2-recommended.js +0 -17
- package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
- package/lib/rules/vue/vue3-recommended.js +0 -17
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
|
|
2
|
+
// ==========================================================
|
|
3
|
+
// 拓展规则(Extension Rules)
|
|
4
|
+
// 基于 eslint 部分基础规则,用于 <template> 内容规则校验、格式化
|
|
5
|
+
// ==========================================================
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
rules: {
|
|
9
|
+
// 在数组开括号后和闭括号前强制换行
|
|
10
|
+
// https://eslint.vuejs.org/rules/array-bracket-newline.html
|
|
11
|
+
"vue/array-bracket-newline": ["warn", "consistent"],
|
|
12
|
+
|
|
13
|
+
// 强制数组方括号中使用一致的空格
|
|
14
|
+
// https://eslint.vuejs.org/rules/array-bracket-spacing.html
|
|
15
|
+
"vue/array-bracket-spacing": ["warn", "never", {
|
|
16
|
+
singleValue: false,
|
|
17
|
+
objectsInArrays: false,
|
|
18
|
+
arraysInArrays: false,
|
|
19
|
+
}],
|
|
20
|
+
|
|
21
|
+
// 强制数组元素间出现换行
|
|
22
|
+
// https://eslint.vuejs.org/rules/array-element-newline.html
|
|
23
|
+
"vue/array-element-newline": ["warn", "consistent"],
|
|
24
|
+
|
|
25
|
+
// 要求箭头函数的箭头之前或之后有空格
|
|
26
|
+
// https://eslint.vuejs.org/rules/arrow-spacing.html
|
|
27
|
+
"vue/arrow-spacing": ["warn", {
|
|
28
|
+
before: true,
|
|
29
|
+
after: true,
|
|
30
|
+
}],
|
|
31
|
+
|
|
32
|
+
// 禁止或强制在代码块中开括号前和闭括号后有空格
|
|
33
|
+
// https://eslint.vuejs.org/rules/block-spacing.html
|
|
34
|
+
"vue/block-spacing": ["warn", "always"],
|
|
35
|
+
|
|
36
|
+
// 强制在代码块中使用一致的大括号风格
|
|
37
|
+
// https://eslint.vuejs.org/rules/brace-style.html
|
|
38
|
+
"vue/brace-style": ["warn", "stroustrup", {
|
|
39
|
+
allowSingleLine: true,
|
|
40
|
+
}],
|
|
41
|
+
|
|
42
|
+
// 要求使用骆驼拼写法
|
|
43
|
+
// https://eslint.vuejs.org/rules/camelcase.html
|
|
44
|
+
"vue/camelcase": ["error", {
|
|
45
|
+
properties: "always",
|
|
46
|
+
ignoreDestructuring: false,
|
|
47
|
+
}],
|
|
48
|
+
|
|
49
|
+
// 要求或禁止使用拖尾逗号(对象、数组、导入、导出、函数参数的最后一项后面是否允许有逗号)
|
|
50
|
+
// https://eslint.vuejs.org/rules/comma-dangle.html
|
|
51
|
+
"vue/comma-dangle": ["warn", {
|
|
52
|
+
arrays: "always-multiline",
|
|
53
|
+
objects: "always-multiline",
|
|
54
|
+
imports: "always-multiline",
|
|
55
|
+
exports: "always-multiline",
|
|
56
|
+
functions: "never",
|
|
57
|
+
}],
|
|
58
|
+
|
|
59
|
+
// 强制在逗号前后使用一致的空格
|
|
60
|
+
// https://eslint.vuejs.org/rules/comma-spacing.html
|
|
61
|
+
"vue/comma-spacing": ["warn", {
|
|
62
|
+
before: false,
|
|
63
|
+
after: true,
|
|
64
|
+
}],
|
|
65
|
+
|
|
66
|
+
// 强制使用一致的逗号风格
|
|
67
|
+
// https://eslint.vuejs.org/rules/comma-style.html
|
|
68
|
+
"vue/comma-style": ["warn", "last", {
|
|
69
|
+
exceptions: {
|
|
70
|
+
ArrayExpression: false,
|
|
71
|
+
ArrayPattern: false,
|
|
72
|
+
ArrowFunctionExpression: false,
|
|
73
|
+
CallExpression: false,
|
|
74
|
+
FunctionDeclaration: false,
|
|
75
|
+
FunctionExpression: false,
|
|
76
|
+
ImportDeclaration: false,
|
|
77
|
+
ObjectExpression: false,
|
|
78
|
+
ObjectPattern: false,
|
|
79
|
+
VariableDeclaration: false,
|
|
80
|
+
NewExpression: false,
|
|
81
|
+
},
|
|
82
|
+
}],
|
|
83
|
+
|
|
84
|
+
// 强制在点号之前和之后一致的换行
|
|
85
|
+
// https://eslint.vuejs.org/rules/dot-location.html
|
|
86
|
+
"vue/dot-location": ["warn", "property"],
|
|
87
|
+
|
|
88
|
+
// 尽可能的使用点符号
|
|
89
|
+
// https://eslint.vuejs.org/rules/dot-notation.html
|
|
90
|
+
"vue/dot-notation": ["warn", {
|
|
91
|
+
allowKeywords: true,
|
|
92
|
+
allowPattern: "",
|
|
93
|
+
}],
|
|
94
|
+
|
|
95
|
+
// 要求使用 === 和 !==
|
|
96
|
+
// https://eslint.vuejs.org/rules/eqeqeq.html
|
|
97
|
+
"vue/eqeqeq": ["warn", "always", { null: "ignore" }],
|
|
98
|
+
|
|
99
|
+
// 要求或禁止在函数标识符和其调用之间有空格
|
|
100
|
+
// https://eslint.vuejs.org/rules/func-call-spacing.html
|
|
101
|
+
"vue/func-call-spacing": ["warn", "never"],
|
|
102
|
+
|
|
103
|
+
// 强制在对象字面量的键和值之间使用一致的空格
|
|
104
|
+
// https://eslint.vuejs.org/rules/key-spacing.html
|
|
105
|
+
"vue/key-spacing": ["warn", {
|
|
106
|
+
beforeColon: false,
|
|
107
|
+
afterColon: true,
|
|
108
|
+
}],
|
|
109
|
+
|
|
110
|
+
// 强制关键字周围空格的一致性
|
|
111
|
+
// https://eslint.vuejs.org/rules/keyword-spacing.html
|
|
112
|
+
"vue/keyword-spacing": ["warn", {
|
|
113
|
+
before: true,
|
|
114
|
+
after: true,
|
|
115
|
+
overrides: {
|
|
116
|
+
if: { after: true },
|
|
117
|
+
for: { after: false },
|
|
118
|
+
while: { after: false },
|
|
119
|
+
switch: { after: false },
|
|
120
|
+
case: { after: true },
|
|
121
|
+
catch: { after: false },
|
|
122
|
+
return: { after: true },
|
|
123
|
+
throw: { after: true },
|
|
124
|
+
},
|
|
125
|
+
}],
|
|
126
|
+
|
|
127
|
+
// 强制一行的最大长度
|
|
128
|
+
// https://eslint.vuejs.org/rules/max-len.html
|
|
129
|
+
"vue/max-len": ["error", {
|
|
130
|
+
code: 200,
|
|
131
|
+
tabWidth: 2,
|
|
132
|
+
comments: 200,
|
|
133
|
+
template: 200,
|
|
134
|
+
ignorePattern: "",
|
|
135
|
+
ignoreComments: false,
|
|
136
|
+
ignoreTrailingComments: false,
|
|
137
|
+
ignoreUrls: true,
|
|
138
|
+
ignoreStrings: true,
|
|
139
|
+
ignoreTemplateLiterals: true,
|
|
140
|
+
ignoreRegExpLiterals: true,
|
|
141
|
+
ignoreHTMLAttributeValues: true,
|
|
142
|
+
ignoreHTMLTextContents: true,
|
|
143
|
+
}],
|
|
144
|
+
|
|
145
|
+
// 要求或禁止在三元操作数中间换行
|
|
146
|
+
// https://eslint.vuejs.org/rules/multiline-ternary.html
|
|
147
|
+
"vue/multiline-ternary": ["off", "never"],
|
|
148
|
+
|
|
149
|
+
// 禁止在 Vue 组件中使用 console
|
|
150
|
+
// https://eslint.vuejs.org/rules/no-console.html
|
|
151
|
+
"vue/no-console": "off",
|
|
152
|
+
|
|
153
|
+
// 禁止条件中的常量表达式
|
|
154
|
+
// https://eslint.vuejs.org/rules/no-constant-condition.html
|
|
155
|
+
"vue/no-constant-condition": "error",
|
|
156
|
+
|
|
157
|
+
// 禁止空的解构模式
|
|
158
|
+
// https://eslint.vuejs.org/rules/no-empty-pattern.html
|
|
159
|
+
"vue/no-empty-pattern": "error",
|
|
160
|
+
|
|
161
|
+
// 禁止冗余的括号
|
|
162
|
+
// https://eslint.vuejs.org/rules/no-extra-parens.html
|
|
163
|
+
"vue/no-extra-parens": ["warn", "all", {
|
|
164
|
+
conditionalAssign: false, // 允许在条件测试表达式中的赋值周围加上括号
|
|
165
|
+
returnAssign: false, // 允许在 return 语句中使用额外的小括号
|
|
166
|
+
nestedBinaryExpressions: false, // 允许在嵌套二进制表达式中使用额外的小括号
|
|
167
|
+
ternaryOperandBinaryExpressions: false, // 允许在三元运算符 ?: 的操作数周围添加额外的括号
|
|
168
|
+
ignoreJSX: "all", // 允许在没有/所有/多行/单行 JSX 组件周围使用额外的小括号,delegate to eslint-plugin-react
|
|
169
|
+
enforceForArrowConditionals: false, // 允许在作为箭头函数主体的三元表达式周围添加小括号
|
|
170
|
+
enforceForSequenceExpressions: false, // 允许在序列表达式周围加上小括号
|
|
171
|
+
enforceForNewInMemberExpressions: false, // 允许在成员表达式中的 new 表达式周围使用额外的小括号
|
|
172
|
+
enforceForFunctionPrototypeMethods: false, // 允许在函数表达式的即时 .call 和 .apply 方法调用周围以及同一上下文中的函数表达式周围添加括号
|
|
173
|
+
allowParensAfterCommentPattern: "", // 允许在匹配正则表达式的注释前面加上额外的括号
|
|
174
|
+
}],
|
|
175
|
+
|
|
176
|
+
// 禁止隐式类型转换
|
|
177
|
+
// https://eslint.vuejs.org/rules/no-implicit-coercion.html
|
|
178
|
+
"vue/no-implicit-coercion": ["off", {
|
|
179
|
+
boolean: false,
|
|
180
|
+
number: true,
|
|
181
|
+
string: true,
|
|
182
|
+
allow: [],
|
|
183
|
+
}],
|
|
184
|
+
|
|
185
|
+
// 禁止不规则的空格
|
|
186
|
+
// https://eslint.vuejs.org/rules/no-irregular-whitespace.html
|
|
187
|
+
"vue/no-irregular-whitespace": ["error", {
|
|
188
|
+
skipStrings: true,
|
|
189
|
+
skipComments: false,
|
|
190
|
+
skipRegExps: false,
|
|
191
|
+
skipTemplates: false,
|
|
192
|
+
skipHTMLAttributeValues: false,
|
|
193
|
+
skipHTMLTextContents: false,
|
|
194
|
+
}],
|
|
195
|
+
|
|
196
|
+
// 禁止失去精度的文字数字
|
|
197
|
+
// https://eslint.vuejs.org/rules/no-loss-of-precision.html
|
|
198
|
+
"vue/no-loss-of-precision": "error",
|
|
199
|
+
|
|
200
|
+
// if 语句和三元表达式中不允许使用否定条件
|
|
201
|
+
// https://eslint.vuejs.org/rules/no-negated-condition.html
|
|
202
|
+
"vue/no-negated-condition": "off",
|
|
203
|
+
|
|
204
|
+
// 禁用特定的语法
|
|
205
|
+
// https://eslint.vuejs.org/rules/no-restricted-syntax.html
|
|
206
|
+
"vue/no-restricted-syntax": [
|
|
207
|
+
"off",
|
|
208
|
+
{
|
|
209
|
+
selector: "ForInStatement",
|
|
210
|
+
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.",
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
selector: "ForOfStatement",
|
|
214
|
+
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.",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
selector: "LabeledStatement",
|
|
218
|
+
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
selector: "WithStatement",
|
|
222
|
+
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
|
|
226
|
+
// 禁止使用稀疏数组
|
|
227
|
+
// 稀疏数组包含空槽,最常见的原因是在数组字面中使用了多个逗号(比如:[,,])
|
|
228
|
+
// https://eslint.vuejs.org/rules/no-sparse-arrays.html
|
|
229
|
+
"vue/no-sparse-arrays": "error",
|
|
230
|
+
|
|
231
|
+
// 禁止不必要的文字或模板文字串联
|
|
232
|
+
// https://eslint.vuejs.org/rules/no-useless-concat.html
|
|
233
|
+
"vue/no-useless-concat": "error",
|
|
234
|
+
|
|
235
|
+
// 强制大括号内换行符的一致性
|
|
236
|
+
// https://eslint.vuejs.org/rules/object-curly-newline.html
|
|
237
|
+
"vue/object-curly-newline": ["warn", {
|
|
238
|
+
// 对象字面量
|
|
239
|
+
ObjectExpression: {
|
|
240
|
+
multiline: true,
|
|
241
|
+
consistent: true,
|
|
242
|
+
},
|
|
243
|
+
// 解构赋值
|
|
244
|
+
ObjectPattern: {
|
|
245
|
+
multiline: true,
|
|
246
|
+
consistent: true,
|
|
247
|
+
},
|
|
248
|
+
// 导入模块
|
|
249
|
+
ImportDeclaration: {
|
|
250
|
+
multiline: true,
|
|
251
|
+
consistent: true,
|
|
252
|
+
},
|
|
253
|
+
// 导出模块
|
|
254
|
+
ExportDeclaration: {
|
|
255
|
+
multiline: true,
|
|
256
|
+
minProperties: 1,
|
|
257
|
+
},
|
|
258
|
+
}],
|
|
259
|
+
|
|
260
|
+
// 强制在花括号中使用一致的空格
|
|
261
|
+
// https://eslint.vuejs.org/rules/object-curly-spacing.html
|
|
262
|
+
"vue/object-curly-spacing": ["warn", "always", {
|
|
263
|
+
arraysInObjects: true,
|
|
264
|
+
objectsInObjects: true,
|
|
265
|
+
}],
|
|
266
|
+
|
|
267
|
+
// 强制将对象的属性放在不同的行上
|
|
268
|
+
// https://eslint.vuejs.org/rules/object-property-newline.html
|
|
269
|
+
"vue/object-property-newline": ["warn", {
|
|
270
|
+
allowAllPropertiesOnSameLine: true,
|
|
271
|
+
}],
|
|
272
|
+
|
|
273
|
+
// 要求或禁止对象字面量的方法和属性简写语法
|
|
274
|
+
// https://eslint.vuejs.org/rules/object-shorthand.html
|
|
275
|
+
"vue/object-shorthand": ["warn", "properties", {
|
|
276
|
+
avoidQuotes: true,
|
|
277
|
+
// ignoreConstructors: false,
|
|
278
|
+
// methodsIgnorePattern: "",
|
|
279
|
+
// avoidExplicitReturnArrows: false,
|
|
280
|
+
}],
|
|
281
|
+
|
|
282
|
+
// 强制操作符使用一致的换行符
|
|
283
|
+
// https://eslint.vuejs.org/rules/operator-linebreak.html
|
|
284
|
+
"vue/operator-linebreak": ["warn", "none", {
|
|
285
|
+
overrides: { "=": "none" },
|
|
286
|
+
}],
|
|
287
|
+
|
|
288
|
+
// 要求使用模板文字进行字符串连接
|
|
289
|
+
// https://eslint.vuejs.org/rules/prefer-template.html
|
|
290
|
+
"vue/prefer-template": "warn",
|
|
291
|
+
|
|
292
|
+
// 要求对象字面量属性名称用引号括起来
|
|
293
|
+
// https://eslint.vuejs.org/rules/quote-props.html
|
|
294
|
+
"vue/quote-props": ["warn", "consistent"],
|
|
295
|
+
|
|
296
|
+
// 强制在圆括号内使用一致的空格
|
|
297
|
+
// https://eslint.vuejs.org/rules/space-in-parens.html
|
|
298
|
+
"vue/space-in-parens": ["warn", "never", {
|
|
299
|
+
exceptions: [],
|
|
300
|
+
}],
|
|
301
|
+
|
|
302
|
+
// 要求中缀操作符周围有空格(+-*/?| etc.)
|
|
303
|
+
// https://eslint.vuejs.org/rules/space-infix-ops.html
|
|
304
|
+
"vue/space-infix-ops": ["warn", {
|
|
305
|
+
// 设置 int32Hint 选项为 true(默认为是 false),以允许写 a|0 时不留空格
|
|
306
|
+
int32Hint: false,
|
|
307
|
+
}],
|
|
308
|
+
|
|
309
|
+
// 强制在一元操作符前后使用一致的空格
|
|
310
|
+
// https://eslint.vuejs.org/rules/space-unary-ops.html
|
|
311
|
+
"vue/space-unary-ops": ["warn", {
|
|
312
|
+
words: true, // 适用于单数词运算符,如 new, delete, typeof, void, yield
|
|
313
|
+
nonwords: false, // 适用于单数运算符,如 -, +, --, ++, !, !!
|
|
314
|
+
overrides: {},
|
|
315
|
+
}],
|
|
316
|
+
|
|
317
|
+
// 要求或禁止模板字符串中的嵌入表达式周围空格的使用
|
|
318
|
+
// https://eslint.vuejs.org/rules/template-curly-spacing.html
|
|
319
|
+
"vue/template-curly-spacing": ["warn", "never"],
|
|
320
|
+
},
|
|
321
|
+
};
|
|
@@ -6,38 +6,80 @@
|
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
rules: {
|
|
9
|
-
// 强制组件顶级元素的顺序
|
|
10
|
-
// https://eslint.vuejs.org/rules/component-tags-order.html
|
|
11
|
-
"vue/component-tags-order": ["warn", {
|
|
12
|
-
"order": [
|
|
13
|
-
"docs",
|
|
14
|
-
"template",
|
|
15
|
-
"script:not([setup])",
|
|
16
|
-
"script[setup]",
|
|
17
|
-
"style:not([scoped])",
|
|
18
|
-
"style[scoped]",
|
|
19
|
-
"i18n",
|
|
20
|
-
],
|
|
21
|
-
}],
|
|
22
|
-
|
|
23
9
|
// 属性排序
|
|
10
|
+
// ==========================================================
|
|
11
|
+
// - DEFINITION e.g. 'is', 'v-is'
|
|
12
|
+
// - GLOBAL e.g. 'id'
|
|
13
|
+
// - OTHER_ATTR alias for [ATTR_DYNAMIC, ATTR_STATIC, ATTR_SHORTHAND_BOOL]:
|
|
14
|
+
// - ATTR_STATIC e.g. 'prop="foo"', 'custom-prop="foo"'
|
|
15
|
+
// - ATTR_DYNAMIC e.g. 'v-bind:prop="foo"', ':prop="foo"'
|
|
16
|
+
// - ATTR_SHORTHAND_BOOL e.g. 'boolean-prop'
|
|
17
|
+
// - TWO_WAY_BINDING e.g. 'v-model'
|
|
18
|
+
// - CONTENT e.g. 'v-text', 'v-html'
|
|
19
|
+
// - SLOT e.g. 'v-slot', 'slot'.
|
|
20
|
+
// - OTHER_DIRECTIVES e.g. 'v-custom-directive'
|
|
21
|
+
// - RENDER_MODIFIERS e.g. 'v-once', 'v-pre'
|
|
22
|
+
// - LIST_RENDERING e.g. 'v-for item in items'
|
|
23
|
+
// - UNIQUE e.g. 'ref', 'key'
|
|
24
|
+
// - CONDITIONALS e.g. 'v-if', 'v-else-if', 'v-else', 'v-show', 'v-cloak'
|
|
25
|
+
// - EVENTS e.g. '@click="functionCall"', 'v-on="event"'
|
|
26
|
+
// ==========================================================
|
|
24
27
|
// https://eslint.vuejs.org/rules/attributes-order.html
|
|
25
28
|
"vue/attributes-order": ["off", {
|
|
26
29
|
"order": [
|
|
27
30
|
"DEFINITION",
|
|
28
31
|
"GLOBAL",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
32
|
+
"ATTR_STATIC",
|
|
33
|
+
"ATTR_DYNAMIC",
|
|
34
|
+
"ATTR_SHORTHAND_BOOL",
|
|
31
35
|
"TWO_WAY_BINDING",
|
|
32
36
|
"CONTENT",
|
|
37
|
+
"SLOT",
|
|
38
|
+
"OTHER_DIRECTIVES",
|
|
33
39
|
"RENDER_MODIFIERS",
|
|
34
|
-
|
|
35
|
-
"
|
|
40
|
+
"LIST_RENDERING",
|
|
41
|
+
"UNIQUE",
|
|
36
42
|
"CONDITIONALS",
|
|
43
|
+
"EVENTS",
|
|
37
44
|
],
|
|
38
45
|
"alphabetical": false,
|
|
46
|
+
// "sortLineLength": false,
|
|
47
|
+
}],
|
|
48
|
+
|
|
49
|
+
// 强制组件顶级元素的顺序
|
|
50
|
+
// https://eslint.vuejs.org/rules/block-order.html
|
|
51
|
+
"vue/block-order": ["warn", {
|
|
52
|
+
"order": [
|
|
53
|
+
"docs",
|
|
54
|
+
"i18n",
|
|
55
|
+
"template",
|
|
56
|
+
"script:not([setup])",
|
|
57
|
+
"script[setup]",
|
|
58
|
+
"style[scoped]",
|
|
59
|
+
"style:not([scoped])",
|
|
60
|
+
],
|
|
39
61
|
}],
|
|
40
|
-
|
|
62
|
+
|
|
63
|
+
// 禁用不必要的 <template> 标签
|
|
64
|
+
// https://eslint.vuejs.org/rules/no-lone-template.html
|
|
65
|
+
"vue/no-lone-template": ["error", {
|
|
66
|
+
"ignoreAccessible": false,
|
|
67
|
+
}],
|
|
68
|
+
|
|
69
|
+
// 不允许将多个参数传递给作用域插槽
|
|
70
|
+
// https://eslint.vuejs.org/rules/no-multiple-slot-args.html
|
|
71
|
+
"vue/no-multiple-slot-args": "error",
|
|
72
|
+
|
|
73
|
+
// 禁止在 props 中使用 required 选项和默认值
|
|
74
|
+
// https://eslint.vuejs.org/rules/no-required-prop-with-default.html
|
|
75
|
+
"vue/no-required-prop-with-default": ["warn", {
|
|
76
|
+
"autofix": true,
|
|
77
|
+
}],
|
|
78
|
+
|
|
79
|
+
// 禁止使用 v-html 来预防 XSS 攻击
|
|
80
|
+
// https://eslint.vuejs.org/rules/no-v-html.html
|
|
81
|
+
"vue/no-v-html": "off",
|
|
82
|
+
|
|
41
83
|
// 强制组件中属性的排序
|
|
42
84
|
// https://eslint.vuejs.org/rules/order-in-components.html
|
|
43
85
|
"vue/order-in-components": ["warn", {
|
|
@@ -63,6 +105,8 @@ module.exports = {
|
|
|
63
105
|
"model",
|
|
64
106
|
["props", "propsData"],
|
|
65
107
|
"emits",
|
|
108
|
+
"slots",
|
|
109
|
+
"expose",
|
|
66
110
|
"setup",
|
|
67
111
|
"asyncData",
|
|
68
112
|
"data",
|
|
@@ -78,19 +122,8 @@ module.exports = {
|
|
|
78
122
|
],
|
|
79
123
|
}],
|
|
80
124
|
|
|
81
|
-
// https://eslint.vuejs.org/rules/no-lone-template.html
|
|
82
|
-
"vue/no-lone-template": "warn",
|
|
83
|
-
|
|
84
|
-
// 不允许将多个参数传递给作用域插槽
|
|
85
|
-
// https://eslint.vuejs.org/rules/no-multiple-slot-args.html
|
|
86
|
-
"vue/no-multiple-slot-args": "warn",
|
|
87
|
-
|
|
88
|
-
// 禁止使用 v-html 来预防 XSS 攻击
|
|
89
|
-
// https://eslint.vuejs.org/rules/no-v-html.html
|
|
90
|
-
"vue/no-v-html": "off",
|
|
91
|
-
|
|
92
125
|
// 禁止在 <template> 中使用 this
|
|
93
126
|
// https://eslint.vuejs.org/rules/this-in-template.html
|
|
94
|
-
"vue/this-in-template": "warn",
|
|
127
|
+
"vue/this-in-template": ["warn", "never"],
|
|
95
128
|
},
|
|
96
129
|
};
|
|
@@ -8,7 +8,10 @@ module.exports = {
|
|
|
8
8
|
rules: {
|
|
9
9
|
// 属性名称使用连字符("-")进行连接
|
|
10
10
|
// https://eslint.vuejs.org/rules/attribute-hyphenation.html
|
|
11
|
-
"vue/attribute-hyphenation": "warn",
|
|
11
|
+
"vue/attribute-hyphenation": ["warn", "always", {
|
|
12
|
+
"ignore": ["custom-prop"],
|
|
13
|
+
"ignoreTags": ["/^custom-/"],
|
|
14
|
+
}],
|
|
12
15
|
|
|
13
16
|
// 强制组件命名的格式
|
|
14
17
|
// https://eslint.vuejs.org/rules/component-definition-name-casing.html
|
|
@@ -52,14 +55,19 @@ module.exports = {
|
|
|
52
55
|
|
|
53
56
|
// 在 html 属性中,强制统一引号
|
|
54
57
|
// https://eslint.vuejs.org/rules/html-quotes.html
|
|
55
|
-
"vue/html-quotes": ["warn", "double", {
|
|
58
|
+
"vue/html-quotes": ["warn", "double", {
|
|
59
|
+
"avoidEscape": true,
|
|
60
|
+
}],
|
|
56
61
|
|
|
57
62
|
// 强制标签自闭合
|
|
63
|
+
// void 元素(如 <img> , <br> , <input> 等)
|
|
64
|
+
// normal 元素(如 <div> , <span> , <p> 等)
|
|
65
|
+
// component 元素表示 Vue 组件
|
|
58
66
|
// https://eslint.vuejs.org/rules/html-self-closing.html
|
|
59
67
|
"vue/html-self-closing": ["warn", {
|
|
60
68
|
"html": {
|
|
61
|
-
"normal": "never",
|
|
62
69
|
"void": "always",
|
|
70
|
+
"normal": "never",
|
|
63
71
|
"component": "always",
|
|
64
72
|
},
|
|
65
73
|
"svg": "always",
|
|
@@ -69,24 +77,16 @@ module.exports = {
|
|
|
69
77
|
// 强制每行属性的数量
|
|
70
78
|
// https://eslint.vuejs.org/rules/max-attributes-per-line.html
|
|
71
79
|
"vue/max-attributes-per-line": ["warn", {
|
|
72
|
-
"singleline": { "max":
|
|
80
|
+
"singleline": { "max": 6 },
|
|
73
81
|
"multiline": { "max": 1 },
|
|
74
82
|
}],
|
|
75
83
|
|
|
76
|
-
// 在单行元素的内容之前和之后需要换行符
|
|
77
|
-
// https://eslint.vuejs.org/rules/singleline-html-element-content-newline.html
|
|
78
|
-
"vue/singleline-html-element-content-newline": ["off", {
|
|
79
|
-
"ignoreWhenEmpty": true,
|
|
80
|
-
"ignoreWhenNoAttributes": true,
|
|
81
|
-
// "ignores": ["pre", "textarea", ...INLINE_ELEMENTS]
|
|
82
|
-
}],
|
|
83
|
-
|
|
84
84
|
// 在多行元素的内容之前和之后需要换行符
|
|
85
85
|
// https://eslint.vuejs.org/rules/multiline-html-element-content-newline.html
|
|
86
86
|
"vue/multiline-html-element-content-newline": ["warn", {
|
|
87
|
+
"allowEmptyLines": true,
|
|
87
88
|
"ignoreWhenEmpty": true,
|
|
88
|
-
"
|
|
89
|
-
// "ignores": ["pre", "textarea", ...INLINE_ELEMENTS],
|
|
89
|
+
"ignores": ["pre", "table", "tr", "ul", "ol", "textarea", "code"],
|
|
90
90
|
}],
|
|
91
91
|
|
|
92
92
|
// 在 mustache 胡须插值中强制统一间距
|
|
@@ -105,7 +105,9 @@ module.exports = {
|
|
|
105
105
|
|
|
106
106
|
// 作用域内外声明的变量不能冲突
|
|
107
107
|
// https://eslint.vuejs.org/rules/no-template-shadow.html
|
|
108
|
-
"vue/no-template-shadow": "error",
|
|
108
|
+
"vue/no-template-shadow": ["error", {
|
|
109
|
+
"allow": [],
|
|
110
|
+
}],
|
|
109
111
|
|
|
110
112
|
// 强制一个文件只能有一个组件
|
|
111
113
|
// https://eslint.vuejs.org/rules/one-component-per-file.html
|
|
@@ -113,19 +115,30 @@ module.exports = {
|
|
|
113
115
|
|
|
114
116
|
// 强制组件 prop 命名的格式
|
|
115
117
|
// https://eslint.vuejs.org/rules/prop-name-casing.html
|
|
116
|
-
"vue/prop-name-casing": ["
|
|
118
|
+
"vue/prop-name-casing": ["error", "camelCase"],
|
|
117
119
|
|
|
118
120
|
// 强制组件 prop 必须配置默认值(default)
|
|
119
121
|
// https://eslint.vuejs.org/rules/require-default-prop.html
|
|
120
|
-
"vue/require-default-prop": "
|
|
122
|
+
"vue/require-default-prop": "error",
|
|
121
123
|
|
|
122
124
|
// 强制组件 prop 必须配置类型值(type)
|
|
123
125
|
// https://eslint.vuejs.org/rules/require-prop-types.html
|
|
124
|
-
"vue/require-prop-types": "
|
|
126
|
+
"vue/require-prop-types": "error",
|
|
127
|
+
|
|
128
|
+
// 在单行元素的内容之前和之后需要换行符
|
|
129
|
+
// https://eslint.vuejs.org/rules/singleline-html-element-content-newline.html
|
|
130
|
+
"vue/singleline-html-element-content-newline": ["off", {
|
|
131
|
+
"ignoreWhenNoAttributes": true,
|
|
132
|
+
"ignoreWhenEmpty": true,
|
|
133
|
+
"ignores": ["pre", "table", "tr", "ul", "ol", "textarea", "code"],
|
|
134
|
+
"externalIgnores": [],
|
|
135
|
+
}],
|
|
125
136
|
|
|
126
137
|
// 强制 v-bind 指令的风格
|
|
127
138
|
// https://eslint.vuejs.org/rules/v-bind-style.html
|
|
128
|
-
"vue/v-bind-style": ["warn", "shorthand"
|
|
139
|
+
"vue/v-bind-style": ["warn", "shorthand", {
|
|
140
|
+
"sameNameShorthand": "never",
|
|
141
|
+
}],
|
|
129
142
|
|
|
130
143
|
// 强制 v-on 指令的风格
|
|
131
144
|
// https://eslint.vuejs.org/rules/v-on-style.html
|
|
@@ -133,6 +146,10 @@ module.exports = {
|
|
|
133
146
|
|
|
134
147
|
// 强制 v-slot 指令的风格
|
|
135
148
|
// https://eslint.vuejs.org/rules/v-slot-style.html
|
|
136
|
-
"vue/v-slot-style": "warn",
|
|
149
|
+
"vue/v-slot-style": ["warn", {
|
|
150
|
+
"atComponent": "v-slot",
|
|
151
|
+
"default": "v-slot",
|
|
152
|
+
"named": "longform",
|
|
153
|
+
}],
|
|
137
154
|
},
|
|
138
155
|
};
|