chore: 🔨 eslint 配置适配版本v9
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
node: true,
|
||||
},
|
||||
parser: "vue-eslint-parser",
|
||||
extends: [
|
||||
// https://eslint.vuejs.org/user-guide/#usage
|
||||
"plugin:vue/vue3-recommended",
|
||||
"./.eslintrc-auto-import.json",
|
||||
"prettier",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:prettier/recommended",
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
parser: "@typescript-eslint/parser",
|
||||
project: "./tsconfig.*?.json",
|
||||
createDefaultProgram: false,
|
||||
extraFileExtensions: [".vue"],
|
||||
},
|
||||
plugins: ["vue", "@typescript-eslint"],
|
||||
// 添加忽略的文件或目录
|
||||
ignores: [
|
||||
"dist",
|
||||
"node_modules",
|
||||
"public",
|
||||
".husky",
|
||||
".vscode",
|
||||
".idea",
|
||||
"*.sh",
|
||||
"*.md",
|
||||
"src/assets",
|
||||
".eslintrc.cjs",
|
||||
".prettierrc.cjs",
|
||||
".stylelintrc.cjs",
|
||||
],
|
||||
|
||||
rules: {
|
||||
// https://eslint.vuejs.org/rules/#priority-a-essential-error-prevention
|
||||
"vue/multi-word-component-names": "off",
|
||||
"vue/no-v-model-argument": "off",
|
||||
"vue/script-setup-uses-vars": "error",
|
||||
"vue/no-reserved-component-names": "off",
|
||||
"vue/custom-event-name-casing": "off",
|
||||
"vue/attributes-order": "off",
|
||||
"vue/one-component-per-file": "off",
|
||||
"vue/html-closing-bracket-newline": "off",
|
||||
"vue/max-attributes-per-line": "off",
|
||||
"vue/multiline-html-element-content-newline": "off",
|
||||
"vue/singleline-html-element-content-newline": "off",
|
||||
"vue/attribute-hyphenation": "off",
|
||||
"vue/require-default-prop": "off",
|
||||
"vue/require-explicit-emits": "off",
|
||||
"vue/html-self-closing": [
|
||||
"error",
|
||||
{
|
||||
html: {
|
||||
void: "always",
|
||||
normal: "never",
|
||||
component: "always",
|
||||
},
|
||||
svg: "always",
|
||||
math: "always",
|
||||
},
|
||||
],
|
||||
|
||||
"@typescript-eslint/no-empty-function": "off", // 关闭空方法检查
|
||||
"@typescript-eslint/no-explicit-any": "off", // 关闭any类型的警告
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@typescript-eslint/ban-types": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-var-requires": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
|
||||
"prettier/prettier": [
|
||||
"error",
|
||||
{
|
||||
useTabs: false, // 不使用制表符
|
||||
},
|
||||
],
|
||||
|
||||
"vue/no-v-html": "off", // 关闭v-html检查
|
||||
},
|
||||
// eslint不能对html文件生效
|
||||
overrides: [
|
||||
{
|
||||
files: ["*.html"],
|
||||
processor: "vue/.vue",
|
||||
},
|
||||
],
|
||||
// https://eslint.org/docs/latest/use/configure/language-options#specifying-globals
|
||||
globals: {
|
||||
OptionType: "readonly",
|
||||
},
|
||||
};
|
||||
143
eslint.config.js
Normal file
143
eslint.config.js
Normal file
@@ -0,0 +1,143 @@
|
||||
import globals from "globals";
|
||||
import js from "@eslint/js";
|
||||
|
||||
// ESLint 核心插件
|
||||
import pluginVue from "eslint-plugin-vue";
|
||||
import pluginTypeScript from "@typescript-eslint/eslint-plugin";
|
||||
|
||||
// Prettier 插件及配置
|
||||
import configPrettier from "eslint-config-prettier";
|
||||
import pluginPrettier from "eslint-plugin-prettier";
|
||||
|
||||
// 解析器
|
||||
import * as parserVue from "vue-eslint-parser";
|
||||
import * as parserTypeScript from "@typescript-eslint/parser";
|
||||
|
||||
// 定义 ESLint 配置
|
||||
export default [
|
||||
// 通用 JavaScript 配置
|
||||
{
|
||||
...js.configs.recommended,
|
||||
ignores: ["**/.*", "dist/*", "*.d.ts", "public/*", "src/assets/**"],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser, // 浏览器变量 (window, document 等)
|
||||
...globals.node, // Node.js 变量 (process, require 等)
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
prettier: pluginPrettier,
|
||||
},
|
||||
rules: {
|
||||
...configPrettier.rules,
|
||||
...pluginPrettier.configs.recommended.rules,
|
||||
"no-debug": "off", // 禁止 debugger
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
argsIgnorePattern: "^_",
|
||||
varsIgnorePattern: "^_",
|
||||
},
|
||||
], // 允许未使用的变量,以 _ 开头的变量不检查
|
||||
"prettier/prettier": [
|
||||
"error",
|
||||
{
|
||||
endOfLine: "auto", // 自动识别换行符
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// TypeScript 配置
|
||||
{
|
||||
files: ["**/*.?([cm])ts"],
|
||||
languageOptions: {
|
||||
parser: parserTypeScript,
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
"@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", // 显式函数返回类型
|
||||
"@typescript-eslint/consistent-type-imports": [
|
||||
"error",
|
||||
{ disallowTypeAnnotations: false, fixStyle: "inline-type-imports" },
|
||||
], // 一致的类型导入
|
||||
"@typescript-eslint/prefer-literal-enum-member": [
|
||||
"error",
|
||||
{ allowBitwiseExpressions: true },
|
||||
], // 使用字面量枚举成员
|
||||
},
|
||||
},
|
||||
|
||||
// TypeScript 声明文件的特殊配置
|
||||
{
|
||||
files: ["**/*.d.ts"],
|
||||
rules: {
|
||||
"eslint-comments/no-unlimited-disable": "off",
|
||||
"unused-imports/no-unused-vars": "off",
|
||||
},
|
||||
},
|
||||
|
||||
// JavaScript 配置(包含 commonjs)
|
||||
{
|
||||
files: ["**/*.?([cm])js"],
|
||||
rules: {
|
||||
"@typescript-eslint/no-require-imports": "off", // 禁止 require
|
||||
"@typescript-eslint/no-var-requires": "off", // 禁止 require
|
||||
},
|
||||
},
|
||||
|
||||
// Vue 文件配置
|
||||
{
|
||||
files: ["**/*.vue"],
|
||||
languageOptions: {
|
||||
parser: parserVue,
|
||||
parserOptions: {
|
||||
extraFileExtensions: [".vue"],
|
||||
parser: "@typescript-eslint/parser",
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
vue: pluginVue,
|
||||
},
|
||||
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",
|
||||
"vue/html-self-closing": [
|
||||
"error",
|
||||
{
|
||||
html: {
|
||||
void: "always",
|
||||
normal: "always",
|
||||
component: "always",
|
||||
},
|
||||
svg: "always",
|
||||
math: "always",
|
||||
},
|
||||
], // 自闭合标签
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user