2025-06-09 10:23:45 +08:00
|
|
|
// .eslintrc.cjs
|
2025-06-09 17:10:41 +08:00
|
|
|
const path = require('path')
|
|
|
|
|
|
2025-06-09 10:23:45 +08:00
|
|
|
module.exports = {
|
2025-06-09 17:10:41 +08:00
|
|
|
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: {
|
2025-06-10 18:48:41 +08:00
|
|
|
// 允许使用 router-link 和 router-view 组件
|
|
|
|
|
'vue/no-undef-components': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
ignorePatterns: ['router-link', 'router-view']
|
|
|
|
|
}
|
|
|
|
|
],
|
2025-06-09 17:10:41 +08:00
|
|
|
// 针对非 Vue 文件禁用 Vue 规则
|
|
|
|
|
// 'vue/no-unregistered-components': [
|
|
|
|
|
// 'error',
|
|
|
|
|
// { ignorePatterns: ['^router$', '^store$'] } // 可选:忽略特定组件名称
|
|
|
|
|
// ],
|
2025-06-10 18:48:41 +08:00
|
|
|
'vue/multi-word-component-names': 'off',
|
|
|
|
|
// 'vue/multi-word-component-names': [
|
|
|
|
|
// 'error',
|
|
|
|
|
// {
|
|
|
|
|
// ignores: ['Test'] // 可选:忽略特定组件名
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
2025-06-09 10:23:45 +08:00
|
|
|
|
2025-06-09 17:10:41 +08:00
|
|
|
// 其他自定义规则
|
|
|
|
|
'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'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|