-
Notifications
You must be signed in to change notification settings - Fork 0
/
eslint.config.js
411 lines (410 loc) · 14.2 KB
/
eslint.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// env
import globals from "globals";
// extends
import eslint from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
/** @type {import("eslint").Linter.FlatConfig[]} */
export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
...pluginVue.configs["flat/essential"],
stylistic.configs.customize({
indent: "tab",
quotes: "double",
semi: true,
}),
{
plugins: {
"typescript-eslint": tseslint.plugin,
},
languageOptions: {
parserOptions: {
parser: {
ts: tseslint.parser,
},
sourceType: "module",
ecmaVersion: "latest",
},
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.browser,
...globals.node,
},
},
files: ["**/*.{js,jsx,ts,tsx,vue}"],
rules: {
"@stylistic/indent": ["error", "tab", {
SwitchCase: 1,
flatTernaryExpressions: true,
ignoredNodes: [
"Program > .body",
"TSFunctionType *", // stylistic typescript indent bug
"TSMappedType *", // stylistic typescript indent bug
],
ignoreComments: true,
}],
"@stylistic/linebreak-style": ["error", "unix"],
"@stylistic/quotes": ["error", "double", { avoidEscape: true }],
"@stylistic/semi": ["error", "always"],
"@stylistic/array-bracket-spacing": ["error", "never"],
"@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
"@stylistic/comma-dangle": ["error", "always-multiline"],
"@stylistic/comma-spacing": ["error", { before: false, after: true }],
"@stylistic/comma-style": ["error", "last"],
"@stylistic/eol-last": "error",
"default-case": "error",
"no-duplicate-case": "error",
"no-eq-null": "off",
"@stylistic/no-floating-decimal": "error",
"@stylistic/no-mixed-spaces-and-tabs": ["error", false],
"no-var": "error",
"no-unused-vars": "off",
"@stylistic/no-tabs": "off",
"no-empty": ["error", { allowEmptyCatch: true }],
"no-constant-condition": ["error", { checkLoops: false }],
"eqeqeq": ["error", "always", { null: "ignore" }],
"prefer-const": ["error", { destructuring: "all" }],
"for-direction": "error",
"getter-return": "error",
"no-compare-neg-zero": "error",
"no-cond-assign": ["error", "except-parens"],
"@stylistic/no-extra-semi": "error",
"no-irregular-whitespace": "error",
"no-unreachable": "warn",
"use-isnan": "error",
"valid-typeof": "error",
"curly": ["error", "multi"],
"no-lonely-if": "off",
"dot-notation": ["error"],
"guard-for-in": "error",
"no-extra-label": "off",
"require-await": "error",
"yoda": "error",
"@stylistic/block-spacing": "error",
"@stylistic/func-call-spacing": ["error", "never"],
"@stylistic/computed-property-spacing": ["error", "never"],
"@stylistic/no-whitespace-before-property": "error",
"@stylistic/object-curly-spacing": ["error", "always"],
"@stylistic/padded-blocks": ["error", "never"],
"@stylistic/quote-props": ["error", "as-needed"],
"@stylistic/semi-spacing": "error",
"@stylistic/semi-style": ["error", "last"],
"@stylistic/space-before-function-paren": ["error", {
anonymous: "always",
named: "never",
asyncArrow: "always",
}],
"@stylistic/space-infix-ops": "error",
"@stylistic/space-in-parens": ["error", "never"],
"@stylistic/space-unary-ops": "error",
"unicode-bom": ["error", "never"],
"@stylistic/arrow-spacing": "error",
"require-yield": "error",
"@stylistic/yield-star-spacing": ["error", "after"],
"symbol-description": "error",
"@stylistic/template-tag-spacing": "error",
"@stylistic/switch-colon-spacing": "error",
"@stylistic/keyword-spacing": "error",
"@stylistic/key-spacing": "error",
"@stylistic/jsx-quotes": "error",
"@stylistic/no-multi-spaces": "error",
"@stylistic/dot-location": ["error", "property"],
"no-loss-of-precision": "error",
"no-useless-concat": "error",
"object-shorthand": "error",
"prefer-template": "off",
"@stylistic/template-curly-spacing": "error",
"no-undef": "off", // 这波 nuxt 的锅。
"@stylistic/multiline-ternary": "off",
"@stylistic/operator-linebreak": "off",
"@stylistic/no-trailing-spaces": ["error", { skipBlankLines: true }],
"one-var": "off",
"@stylistic/arrow-parens": ["error", "as-needed"],
"camelcase": "off",
"@stylistic/spaced-comment": ["error", "always", {
exceptions: ["+", "-", "*", "/"],
markers: ["/", "!", "@", "#", "#region", "#endregion"],
}],
"radix": "error", // parseInt 必须要指明是十进制。
"no-self-assign": "off",
"no-debugger": "warn",
"no-use-before-define": "off",
"accessor-pairs": "off",
"no-empty-function": "off",
"require-jsdoc": "off",
"valid-jsdoc": ["error", {
requireReturn: false,
requireParamType: false, // TypeScript 不需要 JSDoc 的 type。
requireReturnType: false,
}],
"no-inner-declarations": "warn",
"no-unmodified-loop-condition": "off",
"no-return-assign": "off",
"no-redeclare": "off",
"@stylistic/no-mixed-operators": "off",
"@stylistic/no-extra-parens": ["error", "all", { ignoreJSX: "multi-line" }],
"no-void": ["off", { allowAsStatement: true }], // 我就是要使用 void。
"no-labels": "off",
"default-case-last": "off",
"no-useless-constructor": "off", // private constructor() { } 你跟我说无用?
"@stylistic/no-multiple-empty-lines": ["error", { max: 1, maxEOF: 0, maxBOF: 0 }],
"no-unused-expressions": ["error", {
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
enforceForJSX: true,
}],
"@stylistic/max-statements-per-line": "off",
// "no-useless-assignment": "error", // TODO: ESLint 9.0 及其之后才开始支持
"import/order": "off", // 与 VSCode 内置导入排序特性打架。
"import/first": "off", // 与 Vue 特性冲突。
"import/named": "off", // 与 TypeScript 特性冲突。
"import/no-named-as-default": "off", // 似乎与文件命名方式有点出入。
"import/no-named-as-default-member": "off", // 某些库在导出成员时用 TS 命名空间欺诈。
"n/no-callback-literal": "off", // 这是啥?
"unicorn/escape-case": "off", // 暂时禁用,待修复。
"unicorn/number-literal-case": "off", // 同上,你真的觉得大写很好看吗?
"@typescript-eslint/no-unused-vars": ["warn", { // 非要使用未使用变量,前面加下划线。
argsIgnorePattern: "^_",
varsIgnorePattern: "^_|^props$|^emits$",
caughtErrorsIgnorePattern: "^_",
}],
"@typescript-eslint/no-inferrable-types": ["error", { ignoreParameters: true, ignoreProperties: true }],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as" }],
"@typescript-eslint/no-confusing-non-null-assertion": "error",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/no-empty-interface": "off",
"@stylistic/member-delimiter-style": ["error", {
multiline: {
delimiter: "semi",
requireLast: true,
},
singleline: {
delimiter: "semi",
requireLast: false,
},
}],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-use-before-define": ["warn", {
functions: false,
}],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-redeclare": "warn",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-this-alias": "off",
"@stylistic/indent-binary-ops": "error",
"@stylistic/type-generic-spacing": "error",
"@stylistic/type-named-tuple-spacing": "error",
// "@typescript-eslint/no-confusing-void-expression": "error",
// "@typescript-eslint/no-floating-promises": "error",
// 嗯对这几个不晓得怎么用不了。
"vue/html-indent": ["error", "tab"],
"vue/script-indent": ["error", "tab", {
baseIndent: 1,
switchCase: 1,
}],
"vue/html-self-closing": ["error", {
html: {
void: "always",
normal: "any",
component: "always",
},
svg: "always",
math: "always",
}],
"vue/no-export-in-script-setup": "error",
"vue/no-duplicate-attributes": "error",
"vue/no-reserved-component-names": "error",
"vue/no-use-v-if-with-v-for": "error",
"vue/no-v-text-v-html-on-component": "error",
"vue/html-quotes": ["error", "double", { avoidEscape: true }],
"vue/component-definition-name-casing": ["error", "PascalCase"],
"vue/no-multi-spaces": "error",
"vue/no-spaces-around-equal-signs-in-attribute": "error",
"vue/prop-name-casing": ["error", "camelCase"],
"vue/v-slot-style": "error",
"vue/html-closing-bracket-spacing": "error",
"vue/html-closing-bracket-newline": ["error", {
singleline: "never",
multiline: "always",
}],
"vue/no-v-html": "error",
"vue/this-in-template": ["error", "never"],
"vue/html-comment-content-spacing": ["error", "always"],
"vue/array-bracket-spacing": ["error", "never"],
"vue/arrow-spacing": "error",
"vue/block-spacing": "error",
"vue/brace-style": ["error", "1tbs", { allowSingleLine: true }],
"vue/comma-dangle": ["error", "always-multiline"],
"vue/comma-spacing": ["error", { before: false, after: true }],
"vue/comma-style": ["error", "last"],
"vue/dot-location": ["error", "property"],
"vue/dot-notation": ["error"],
"vue/func-call-spacing": ["error", "never"],
"vue/eqeqeq": ["error", "always", { null: "ignore" }],
"vue/no-irregular-whitespace": "error",
"vue/no-loss-of-precision": "error",
"vue/no-useless-concat": "error",
"vue/object-curly-spacing": ["error", "always"],
"vue/object-shorthand": "error",
"vue/prefer-template": "off",
"vue/quote-props": ["error", "as-needed"],
"vue/space-in-parens": ["error", "never"],
"vue/space-infix-ops": "error",
"vue/space-unary-ops": "error",
"vue/template-curly-spacing": "error",
"vue/key-spacing": "error",
"vue/keyword-spacing": "error",
"vue/multi-word-component-names": "off",
"vue/mustache-interpolation-spacing": "error",
"vue/attribute-hyphenation": ["error", "never"],
"vue/singleline-html-element-content-newline": "off",
"vue/no-unused-vars": "warn",
"vue/no-v-model-argument": "off",
"vue/require-typed-ref": "error",
"vue/block-lang": ["error", {
script: {
lang: ["ts", "tsx"],
},
i18n: {
lang: "json5",
},
}],
"vue/block-tag-newline": ["error", {
singleline: "always",
multiline: "always",
maxEmptyLines: 0,
}],
"vue/define-macros-order": ["off", { // 与 typescript 冲突了。
order: ["defineProps", "defineEmits"],
}],
"vue/component-options-name-casing": ["error", "PascalCase"],
"vue/next-tick-style": ["error", "promise"],
"vue/padding-line-between-blocks": ["error", "always"],
"vue/component-tags-order": ["error", {
order: ["docs", ["script:not([setup])", "script[setup]"], "template", "i18n", "style[scoped]", "style[module]", "style:not([scoped]):not([module])"],
}],
"vue/no-multiple-template-root": "off",
"vue/multiline-html-element-content-newline": "off",
"vue/no-template-shadow": "off",
"vue/no-mutating-props": ["off", { shallowOnly: false }],
"vue/no-deprecated-filter": "off", // 我要按位或,不是要什么过滤器。
"vue/no-dupe-keys": "off",
"vue/no-v-for-template-key": "off", // 官方说明:它会和 vue/no-v-for-template-key-on-child 规则打架。
"vue/v-on-event-hyphenation": ["error", "never", { autofix: true }],
"no-restricted-properties": ["error", {
object: "arguments",
property: "callee",
message: "arguments.callee is deprecated.",
}, {
object: "global",
property: "isFinite",
message: "Please use Number.isFinite instead.",
}, {
object: "self",
property: "isFinite",
message: "Please use Number.isFinite instead.",
}, {
object: "window",
property: "isFinite",
message: "Please use Number.isFinite instead.",
}, {
object: "globalThis",
property: "isFinite",
message: "Please use Number.isFinite instead.",
}, {
object: "global",
property: "isNaN",
message: "Please use Number.isNaN instead.",
}, {
object: "self",
property: "isNaN",
message: "Please use Number.isNaN instead.",
}, {
object: "window",
property: "isNaN",
message: "Please use Number.isNaN instead.",
}, {
object: "globalThis",
property: "isNaN",
message: "Please use Number.isNaN instead.",
}, {
property: "__defineGetter__",
message: "Please use Object.defineProperty instead.",
}, {
property: "__defineSetter__",
message: "Please use Object.defineProperty instead.",
}, {
object: "Math",
property: "pow",
message: "Use the exponentiation operator (**) instead.",
}],
"no-restricted-globals": ["error", {
name: "arguments",
message: "arguments is deprecated.",
}, {
name: "isFinite",
message: "Please use Number.isFinite instead.",
}, {
name: "isNaN",
message: "Please use Number.isNaN instead.",
}, {
name: "addEventListener",
message: "Please use window.addEventListener instead.",
}, {
name: "innerHeight",
message: "Please use window.innerHeight instead.",
}, {
name: "outerHeight",
message: "Please use window.outerHeight instead.",
}, {
name: "innerWidth",
message: "Please use window.innerWidth instead.",
}, {
name: "outerWidth",
message: "Please use window.outerWidth instead.",
}, /* {
name: "Number",
message: "Use + instead.",
}, {
name: "Boolean",
message: "Use !! instead.",
} */],
"no-restricted-syntax": ["error", {
selector: "VariableDeclaration[kind = 'let'] > VariableDeclarator[init = null]:not([id.typeAnnotation])",
message: "Type must be inferred at variable declaration",
}],
},
},
{
files: ["*.config.{js,ts}"],
rules: {
"@stylistic/quote-props": "off",
},
},
{
files: ["**/*.d.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
},
},
{
ignores: [
"**/dist/*",
".output/*",
"node_modules/*",
".nuxt/*",
"proto/*",
],
},
];