85 lines
2.5 KiB
JavaScript
85 lines
2.5 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: {
|
||
'vue/no-v-html': 'warn', // 从 error 改为 warn(或 'off' 完全关闭)
|
||
|
||
// 限制 v-html 使用,仅允许明确标记为安全的内容
|
||
// 'vue/no-v-html': ['warn', { allow: ['trusted', 'safe'] }],
|
||
|
||
// 允许使用 router-link 和 router-view 组件
|
||
'vue/no-undef-components': [
|
||
'error',
|
||
{
|
||
ignorePatterns: [
|
||
'router-link',
|
||
'router-view',
|
||
// 添加其他使用的 Element Plus 组件
|
||
'RouterLink',
|
||
'RouterView',
|
||
'el-.*',
|
||
'El.*'
|
||
]
|
||
}
|
||
],
|
||
// 针对非 Vue 文件禁用 Vue 规则
|
||
// 'vue/no-unregistered-components': [
|
||
// 'error',
|
||
// { ignorePatterns: ['^router$', '^store$'] } // 可选:忽略特定组件名称
|
||
// ],
|
||
// -------------------- 解决 vue/valid-template-root --------------------
|
||
// 要求模板必须有且只有一个根元素(必填,否则组件报错)
|
||
'vue/valid-template-root': 'error',
|
||
|
||
// -------------------- 可选:关闭组件命名规则(如需) --------------------
|
||
'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'
|
||
}
|
||
}
|
||
]
|
||
}
|