2026-02-03 19:25:24 +08:00
|
|
|
|
import js from "@eslint/js";
|
|
|
|
|
|
import globals from "globals";
|
|
|
|
|
|
import tseslint from "typescript-eslint";
|
|
|
|
|
|
import pluginVue from "eslint-plugin-vue";
|
|
|
|
|
|
import { defineConfig } from "eslint/config";
|
|
|
|
|
|
import stylistic from "@stylistic/eslint-plugin";
|
|
|
|
|
|
|
|
|
|
|
|
export default defineConfig([
|
2026-02-04 19:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
name: "通用设置",
|
2026-02-04 12:01:41 +08:00
|
|
|
|
files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}",],
|
2026-02-04 11:45:47 +08:00
|
|
|
|
plugins: { js, },
|
2026-02-03 19:25:24 +08:00
|
|
|
|
extends: ["js/recommended",],
|
2026-02-04 19:53:50 +08:00
|
|
|
|
languageOptions: {
|
2026-02-03 19:25:24 +08:00
|
|
|
|
globals: {
|
|
|
|
|
|
...globals.browser,
|
2026-02-04 19:53:50 +08:00
|
|
|
|
...globals.node,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rules:{
|
|
|
|
|
|
// indent: ["warn", 4,],
|
|
|
|
|
|
// 圆括号中的空格,为空不加空格,紧跟花括号、方括号、圆括号时也不加入空格
|
|
|
|
|
|
"space-in-parens": ["error", "always", { exceptions: ["{}", "[]", "()", "empty",], },],
|
|
|
|
|
|
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
|
|
|
|
|
|
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
|
|
|
|
|
|
"no-unused-vars": "warn",
|
|
|
|
|
|
semi: ["error", "always",], // 控制行尾部分号
|
|
|
|
|
|
quotes: ["error", "double",],
|
|
|
|
|
|
"comma-dangle": ["error", {
|
|
|
|
|
|
arrays: "always",
|
|
|
|
|
|
objects: "always",
|
|
|
|
|
|
imports: "never",
|
|
|
|
|
|
exports: "never",
|
|
|
|
|
|
functions: "never",
|
|
|
|
|
|
},], // 数组和对象键值对最后一个逗号
|
|
|
|
|
|
"comma-style": ["error", "last",], // 逗号在行尾
|
|
|
|
|
|
"no-undef-init": "error",
|
|
|
|
|
|
"no-invalid-this": "error",
|
|
|
|
|
|
"no-use-before-define": "error",
|
|
|
|
|
|
"no-shadow-restricted-names": "error", // 禁止对一些关键字或者保留字进行赋值操作,比如NaN、Infinity、undefined、eval、arguments等
|
|
|
|
|
|
"comma-spacing": ["error", { before: false,
|
|
|
|
|
|
after: true, },],
|
|
|
|
|
|
"array-bracket-spacing": ["error", "never", {
|
|
|
|
|
|
singleValue: false,
|
|
|
|
|
|
objectsInArrays: false,
|
|
|
|
|
|
arraysInArrays: false,
|
|
|
|
|
|
},],
|
|
|
|
|
|
"brace-style": ["error", "allman", { allowSingleLine: true, },],
|
|
|
|
|
|
"prefer-const": "warn",
|
|
|
|
|
|
"space-before-function-paren": ["error", {
|
|
|
|
|
|
anonymous: "always",
|
|
|
|
|
|
named: "never",
|
|
|
|
|
|
asyncArrow: "always",
|
|
|
|
|
|
},],
|
|
|
|
|
|
"@stylistic/no-trailing-spaces": [ // 不允许末尾的空格
|
|
|
|
|
|
"error",
|
|
|
|
|
|
{
|
|
|
|
|
|
"skipBlankLines": false,
|
|
|
|
|
|
"ignoreComments": false,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
2026-02-03 19:25:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
tseslint.configs.recommended,
|
|
|
|
|
|
{
|
|
|
|
|
|
files: ["src/**/*.ts", "eslint.config.ts",],
|
|
|
|
|
|
plugins: {
|
|
|
|
|
|
"@stylistic": stylistic,
|
|
|
|
|
|
},
|
2026-02-04 12:17:13 +08:00
|
|
|
|
languageOptions: {
|
2026-02-04 19:53:50 +08:00
|
|
|
|
parserOptions: { parser: tseslint.parser, },
|
2026-02-04 12:17:13 +08:00
|
|
|
|
},
|
2026-02-03 19:25:24 +08:00
|
|
|
|
rules: {
|
|
|
|
|
|
"spaced-comment": "error",
|
|
|
|
|
|
"space-before-function-paren": "off",
|
2026-02-04 19:53:50 +08:00
|
|
|
|
"semi-spacing": ["error", { before: false,
|
|
|
|
|
|
after: true, },],
|
2026-02-03 19:25:24 +08:00
|
|
|
|
"@typescript-eslint/no-unused-vars": "warn",
|
|
|
|
|
|
"@stylistic/indent": ["error", 4, { SwitchCase: 1, },],
|
|
|
|
|
|
"@typescript-eslint/no-explicit-any": "off",
|
|
|
|
|
|
"@typescript-eslint/no-extra-semi": "off",
|
|
|
|
|
|
"@typescript-eslint/no-inferrable-types": "off",
|
|
|
|
|
|
"@typescript-eslint/ban-ts-comment": "warn",
|
|
|
|
|
|
"@typescript-eslint/member-delimiter-style": "off",
|
|
|
|
|
|
"@stylistic/semi": ["error", "always",], // 控制行尾部分号
|
|
|
|
|
|
"@stylistic/brace-style": ["error", "allman", { allowSingleLine: true, },],
|
|
|
|
|
|
"@stylistic/comma-dangle": [
|
|
|
|
|
|
"error",
|
|
|
|
|
|
{
|
|
|
|
|
|
arrays: "always",
|
|
|
|
|
|
objects: "always",
|
|
|
|
|
|
imports: "never",
|
|
|
|
|
|
exports: "never",
|
|
|
|
|
|
functions: "never",
|
|
|
|
|
|
},
|
|
|
|
|
|
], // 数组和对象键值对最后一个逗号
|
|
|
|
|
|
"@stylistic/quotes": ["error", "double",],
|
|
|
|
|
|
"@typescript-eslint/space-before-function-paren": "off",
|
2026-02-04 19:53:50 +08:00
|
|
|
|
"@typescript-eslint/comma-spacing": [
|
|
|
|
|
|
"off",
|
|
|
|
|
|
{ before: false,
|
|
|
|
|
|
after: true, },
|
|
|
|
|
|
], // 使用eslint的,不用ts的
|
2026-02-03 19:25:24 +08:00
|
|
|
|
// "@typescript-eslint/strict-boolean-expressions": ["error", {
|
|
|
|
|
|
// allowString: false,
|
|
|
|
|
|
// },],
|
|
|
|
|
|
"@stylistic/object-property-newline": "warn",
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-02-04 11:45:47 +08:00
|
|
|
|
pluginVue.configs["flat/essential"],
|
2026-02-04 12:17:13 +08:00
|
|
|
|
pluginVue.configs["flat/strongly-recommended"],
|
2026-02-04 19:53:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
files: ["**/*.vue", "**/.ts", "eslint.config.ts",],
|
2026-02-04 12:01:41 +08:00
|
|
|
|
plugins: {
|
|
|
|
|
|
"@stylistic": stylistic,
|
|
|
|
|
|
},
|
2026-02-04 12:17:13 +08:00
|
|
|
|
languageOptions: {
|
2026-02-04 19:53:50 +08:00
|
|
|
|
parserOptions: { parser: tseslint.parser, },
|
2026-02-04 12:17:13 +08:00
|
|
|
|
ecmaVersion: "latest",
|
|
|
|
|
|
sourceType: "module",
|
|
|
|
|
|
globals: globals.browser,
|
2026-02-04 12:01:41 +08:00
|
|
|
|
},
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
"vue/html-indent": ["error", 4,],
|
2026-02-04 12:17:13 +08:00
|
|
|
|
// "vue/max-attributes-per-line": ["error", {
|
|
|
|
|
|
// "singleline": {
|
|
|
|
|
|
// "max": 1,
|
|
|
|
|
|
// },
|
|
|
|
|
|
// "multiline": {
|
|
|
|
|
|
// "max": 1,
|
|
|
|
|
|
// },
|
|
|
|
|
|
// },],
|
2026-02-04 12:01:41 +08:00
|
|
|
|
"spaced-comment": "error",
|
|
|
|
|
|
"space-before-function-paren": "off",
|
2026-02-04 19:53:50 +08:00
|
|
|
|
"semi-spacing": ["error", { before: false,
|
|
|
|
|
|
after: true, },],
|
2026-02-04 12:01:41 +08:00
|
|
|
|
"@typescript-eslint/no-unused-vars": "warn",
|
|
|
|
|
|
"@stylistic/indent": ["error", 4, { SwitchCase: 1, },],
|
|
|
|
|
|
"@typescript-eslint/no-explicit-any": "off",
|
|
|
|
|
|
"@typescript-eslint/no-extra-semi": "off",
|
|
|
|
|
|
"@typescript-eslint/no-inferrable-types": "off",
|
|
|
|
|
|
"@typescript-eslint/ban-ts-comment": "warn",
|
|
|
|
|
|
"@typescript-eslint/member-delimiter-style": "off",
|
|
|
|
|
|
"@stylistic/semi": ["error", "always",], // 控制行尾部分号
|
|
|
|
|
|
"@stylistic/brace-style": ["error", "allman", { allowSingleLine: true, },],
|
|
|
|
|
|
"@stylistic/comma-dangle": [
|
|
|
|
|
|
"error",
|
|
|
|
|
|
{
|
|
|
|
|
|
arrays: "always",
|
|
|
|
|
|
objects: "always",
|
|
|
|
|
|
imports: "never",
|
|
|
|
|
|
exports: "never",
|
|
|
|
|
|
functions: "never",
|
|
|
|
|
|
},
|
|
|
|
|
|
], // 数组和对象键值对最后一个逗号
|
|
|
|
|
|
"@stylistic/quotes": ["error", "double",],
|
|
|
|
|
|
"@typescript-eslint/space-before-function-paren": "off",
|
2026-02-04 19:53:50 +08:00
|
|
|
|
"@typescript-eslint/comma-spacing": [
|
|
|
|
|
|
"off",
|
|
|
|
|
|
{ before: false,
|
|
|
|
|
|
after: true, },
|
|
|
|
|
|
], // 使用eslint的,不用ts的
|
2026-02-04 12:01:41 +08:00
|
|
|
|
// "@typescript-eslint/strict-boolean-expressions": ["error", {
|
|
|
|
|
|
// allowString: false,
|
|
|
|
|
|
// },],
|
|
|
|
|
|
"@stylistic/object-property-newline": "warn",
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-02-03 19:25:24 +08:00
|
|
|
|
]);
|