60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
|
|
// .eslintrc.cjs
|
|||
|
|
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 支持
|
|||
|
|
'prettier', // 关闭与 Prettier 冲突的规则(需先安装 prettier)
|
|||
|
|
'plugin:prettier/recommended', // 将 Prettier 规则作为 ESLint 规则
|
|||
|
|
],
|
|||
|
|
parserOptions: {
|
|||
|
|
ecmaVersion: 'latest',
|
|||
|
|
sourceType: 'module',
|
|||
|
|
ecmaFeatures: {
|
|||
|
|
jsx: true,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
rules: {
|
|||
|
|
// 自定义规则(根据团队需求调整)
|
|||
|
|
'vue/multi-word-component-names': 'off',
|
|||
|
|
'prettier/prettier': 'error', // 将 Prettier 错误视为 ESLint 错误
|
|||
|
|
// 强制使用 === 而非 ==
|
|||
|
|
'eqeqeq': 'error',
|
|||
|
|
|
|||
|
|
// 组件 props 必须有类型和默认值
|
|||
|
|
'vue/require-default-prop': 'error',
|
|||
|
|
'vue/require-prop-types': 'error',
|
|||
|
|
|
|||
|
|
// 限制每行最大长度
|
|||
|
|
'max-len': ['warn', {code: 120}],
|
|||
|
|
|
|||
|
|
// 禁止使用未定义的组件
|
|||
|
|
'vue/no-unregistered-components': 'error',
|
|||
|
|
|
|||
|
|
// 组件名必须为 PascalCase
|
|||
|
|
'vue/component-name-in-template-casing': ['error', 'PascalCase'],
|
|||
|
|
|
|||
|
|
// 禁止使用 v-html(防止 XSS)
|
|||
|
|
'vue/no-v-html': 'warn',
|
|||
|
|
// 自定义规则(根据团队需求调整)
|
|||
|
|
'vue/multi-word-component-names': 'off', // 允许单字组件名
|
|||
|
|
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
|||
|
|
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
|||
|
|
'@typescript-eslint/no-unused-vars': ['warn', {argsIgnorePattern: '^_'}],
|
|||
|
|
},
|
|||
|
|
overrides: [
|
|||
|
|
// 针对测试文件的规则
|
|||
|
|
{
|
|||
|
|
files: ['**/__tests__/*.{j,t}s?(x)', '**/tests/unit/**/*.spec.{j,t}s?(x)'],
|
|||
|
|
env: {
|
|||
|
|
jest: true,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
],
|
|||
|
|
}
|