54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
|
|
/**
|
|||
|
|
* ESLint Flat 配置(ESLint 9)
|
|||
|
|
* 适用于:Vue 3 + TypeScript + Prettier
|
|||
|
|
*/
|
|||
|
|
import pluginVue from 'eslint-plugin-vue' // Vue 官方 ESLint 插件
|
|||
|
|
import {
|
|||
|
|
defineConfigWithVueTs, // 用于组合 Vue + TS 的 Flat 配置
|
|||
|
|
vueTsConfigs, // 官方提供的 TypeScript 推荐规则集合
|
|||
|
|
} from '@vue/eslint-config-typescript'
|
|||
|
|
import prettierPlugin from 'eslint-plugin-prettier' // 将 Prettier 作为 ESLint 规则使用
|
|||
|
|
import prettierConfig from 'eslint-config-prettier' // 关闭与 Prettier 冲突的 ESLint 规则
|
|||
|
|
|
|||
|
|
export default defineConfigWithVueTs(
|
|||
|
|
// 1. 全局忽略配置(必须放在最前面)
|
|||
|
|
{
|
|||
|
|
// 不对构建产物和依赖目录进行 ESLint 校验
|
|||
|
|
ignores: ['dist/**', 'node_modules/**'],
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 2. Vue 相关基础规则(包含模板语法支持)
|
|||
|
|
pluginVue.configs['flat/essential'],
|
|||
|
|
|
|||
|
|
// 3. TypeScript 推荐规则(脚本逻辑部分)
|
|||
|
|
vueTsConfigs.recommended,
|
|||
|
|
|
|||
|
|
// 4. Prettier 相关配置:只负责格式化,不干扰语义规则
|
|||
|
|
{
|
|||
|
|
// 注册需要用到的插件
|
|||
|
|
plugins: {
|
|||
|
|
prettier: prettierPlugin, // Prettier 插件
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 自定义规则
|
|||
|
|
rules: {
|
|||
|
|
// 关闭与 Prettier 冲突的 ESLint 规则
|
|||
|
|
...prettierConfig.rules,
|
|||
|
|
|
|||
|
|
// 将 Prettier 的格式化结果作为 ESLint 的告警输出
|
|||
|
|
'prettier/prettier': 'warn',
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
// 5. 自定义规则
|
|||
|
|
{
|
|||
|
|
rules: {
|
|||
|
|
// Vue 规则
|
|||
|
|
'vue/multi-word-component-names': 'off',
|
|||
|
|
|
|||
|
|
// TypeScript 规则
|
|||
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
)
|