From b84e4ac6c5e1ce7f9ecffc4513a6c3772a5ba23c Mon Sep 17 00:00:00 2001 From: ray <1490493387@qq.com> Date: Sun, 3 Nov 2024 23:52:16 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20:hammer:=20=E7=B2=BE=E7=AE=80eslint?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eslint.config.mjs | 61 +++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index de06ab6..80ec7fc 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -15,7 +15,7 @@ import * as parserTypeScript from "@typescript-eslint/parser"; // 定义 ESLint 配置 export default [ - // 通用 JavaScript 配置 + // 通用 JavaScript/TypeScript 配置 { ...js.configs.recommended, ignores: [ @@ -39,18 +39,11 @@ export default [ rules: { ...configPrettier.rules, ...pluginPrettier.configs.recommended.rules, - "no-debug": "off", // 禁止 debugger - "no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_", - }, - ], // 允许未使用的变量,以 _ 开头的变量不检查 + "no-debug": "off", // 允许使用 debugger "prettier/prettier": [ "error", { - endOfLine: "auto", // 自动识别换行符 + endOfLine: "auto", // 解决换行符冲突 }, ], }, @@ -69,22 +62,14 @@ export default [ "@typescript-eslint": pluginTypeScript, }, rules: { - ...pluginTypeScript.configs.strict.rules, - "@typescript-eslint/ban-types": "off", // 禁止特定类型 - "@typescript-eslint/no-redeclare": "error", // 禁止重复声明 - "@typescript-eslint/ban-ts-comment": "off", // 禁止特定注释 - "@typescript-eslint/no-explicit-any": "off", // 禁止使用 any - "@typescript-eslint/prefer-as-const": "warn", // 使用 as const 替代 as 'const' - "@typescript-eslint/no-empty-function": "off", // 禁止空函数 - "@typescript-eslint/no-non-null-assertion": "off", // 禁止非空断言 - "@typescript-eslint/no-import-type-side-effects": "error", // 禁止导入类型产生副作用 - "@typescript-eslint/explicit-module-boundary-types": "off", // 显式函数返回类型 + ...pluginTypeScript.configs.recommended.rules, + "@typescript-eslint/no-explicit-any": "off", // 允许使用 any + "@typescript-eslint/no-empty-function": "off", // 允许空函数 + "@typescript-eslint/no-empty-object-type": "off", // 允许空对象类型 "@typescript-eslint/consistent-type-imports": [ "error", { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" }, - ], // 一致的类型导入 - "@typescript-eslint/prefer-literal-enum-member": ["error", { allowBitwiseExpressions: true }], // 使用字面量枚举成员 - "@typescript-eslint/no-empty-object-type": "off", // 禁止空对象类型 + ], // 统一类型导入风格 }, }, @@ -92,17 +77,16 @@ export default [ { files: ["**/*.d.ts"], rules: { - "eslint-comments/no-unlimited-disable": "off", - "unused-imports/no-unused-vars": "off", + "eslint-comments/no-unlimited-disable": "off", // 关闭 eslint 注释相关规则 + "unused-imports/no-unused-vars": "off", // 忽略未使用的导入 }, }, - // JavaScript 配置(包含 commonjs) + // JavaScript (commonjs) 配置 { files: ["**/*.?([cm])js"], rules: { - "@typescript-eslint/no-require-imports": "off", // 禁止 require - "@typescript-eslint/no-var-requires": "off", // 禁止 require + "@typescript-eslint/no-var-requires": "off", // 允许 require }, }, @@ -112,7 +96,6 @@ export default [ languageOptions: { parser: parserVue, parserOptions: { - extraFileExtensions: [".vue"], parser: "@typescript-eslint/parser", sourceType: "module", }, @@ -122,24 +105,14 @@ export default [ }, processor: pluginVue.processors[".vue"], rules: { - ...pluginVue.configs.base.rules, // Vue 基础配置 - ...pluginVue.configs["vue3-essential"].rules, // Vue3 基础配置 - ...pluginVue.configs["vue3-recommended"].rules, // Vue3 推荐配置 - "no-undef": "off", - "no-unused-vars": "off", - "vue/no-v-html": "off", - "vue/require-default-prop": "off", - "vue/require-explicit-emits": "off", - "vue/multi-word-component-names": "off", - "vue/no-setup-props-reactivity-loss": "off", + ...pluginVue.configs["vue3-recommended"].rules, + "vue/no-v-html": "off", // 允许 v-html + "vue/require-default-prop": "off", // 允许没有默认值的 prop + "vue/multi-word-component-names": "off", // 关闭组件名称多词要求 "vue/html-self-closing": [ "error", { - html: { - void: "always", - normal: "always", - component: "always", - }, + html: { void: "always", normal: "always", component: "always" }, svg: "always", math: "always", },