79 lines
2.1 KiB
JavaScript
79 lines
2.1 KiB
JavaScript
// .eslintrc.cjs
|
||
const path = require('path')
|
||
|
||
module.exports = {
|
||
root: true,
|
||
env: {
|
||
browser: true,
|
||
node: true,
|
||
es6: true
|
||
},
|
||
extends: [
|
||
'eslint:recommended',
|
||
'plugin:vue/vue3-recommended', // 加载 Vue 3 推荐规则
|
||
'@vue/eslint-config-typescript', // 加载 TypeScript 支持
|
||
'plugin:prettier/recommended' // 确保放在最后
|
||
],
|
||
parser: 'vue-eslint-parser', // 解析 Vue 模板
|
||
parserOptions: {
|
||
parser: '@typescript-eslint/parser', // 解析 TypeScript 代码
|
||
project: path.resolve(__dirname, 'tsconfig.app.json'), // 使用正确的 TSConfig
|
||
tsconfigRootDir: __dirname,
|
||
ecmaVersion: 'latest',
|
||
sourceType: 'module'
|
||
},
|
||
plugins: ['vue', 'prettier', '@typescript-eslint'], // 显式注册所有插件
|
||
rules: {
|
||
// 允许使用 router-link 和 router-view 组件
|
||
'vue/no-undef-components': [
|
||
'error',
|
||
{
|
||
ignorePatterns: [
|
||
'router-link',
|
||
'router-view',
|
||
'ElTabs',
|
||
'ElTabPane',
|
||
'ElButton',
|
||
'ElPagination',
|
||
// 添加其他使用的 Element Plus 组件
|
||
'RouterLink',
|
||
'RouterView'
|
||
]
|
||
// 允许的组件前缀(Element Plus 组件以 El 开头)
|
||
// allowComponentPrefixes: ['El']
|
||
}
|
||
],
|
||
// 针对非 Vue 文件禁用 Vue 规则
|
||
// 'vue/no-unregistered-components': [
|
||
// 'error',
|
||
// { ignorePatterns: ['^router$', '^store$'] } // 可选:忽略特定组件名称
|
||
// ],
|
||
'vue/multi-word-component-names': 'off',
|
||
// 'vue/multi-word-component-names': [
|
||
// 'error',
|
||
// {
|
||
// ignores: ['Test'] // 可选:忽略特定组件名
|
||
// }
|
||
// ],
|
||
|
||
// 其他自定义规则
|
||
'prettier/prettier': 'error',
|
||
'@typescript-eslint/no-unused-vars': 'warn',
|
||
'max-len': 'off'
|
||
},
|
||
overrides: [
|
||
// {
|
||
// files: ['*.vue'], // 仅对 Vue 文件应用 Vue 规则
|
||
// rules: {
|
||
// 'vue/no-unregistered-components': 'error'
|
||
// }
|
||
// },
|
||
{
|
||
files: ['*.ts', '*.js'], // 非 Vue 文件不应用 Vue 规则
|
||
rules: {
|
||
'vue/no-unregistered-components': 'off'
|
||
}
|
||
}
|
||
]
|
||
}
|