.eslintrc.js
2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module.exports = {
root: true,
env: {
browser: true,
node: true,
es2021: true
},
extends: [
'eslint:recommended'
// 暂时不使用 '@vue/eslint-config-prettier',手动配置规则避免冲突
],
plugins: ['vue'],
parser: 'vue-eslint-parser', // 使用 Vue parser
parserOptions: {
parser: 'espree', // JavaScript parser
ecmaVersion: 2021,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
rules: {
// Vue 规则(手动配置)
'vue/multi-word-component-names': 'off', // 允许单词组件名
'vue/no-v-html': 'warn', // 警告使用 v-html(XSS 风险)
'vue/require-default-prop': 'off', // 不强制 prop 默认值
'vue/require-prop-types': 'off', // 不强制 prop 类型(使用 JSDoc)
'vue/no-unused-vars': 'warn', // 警告未使用的变量
'vue/no-unused-components': 'warn', // 警告未使用的组件
// 通用规则
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], // 警告未使用的变量
'prefer-const': 'error', // 优先使用 const
'no-var': 'error', // 禁止使用 var
'eqeqeq': ['error', 'always'], // 强制使用 === 和 !==
'curly': ['error', 'all'], // 强制使用大括号
'brace-style': ['error', '1tbs'], // 大括号风格
'quotes': ['error', 'single', { avoidEscape: true }], // 单引号
'semi': ['error', 'never'], // 不使用分号
'comma-dangle': ['error', 'never'], // 不允许尾随逗号
'arrow-parens': ['error', 'as-needed'], // 箭头函数参数括号
'object-curly-spacing': ['error', 'always'], // 对象大括号空格
'array-bracket-spacing': ['error', 'never'], // 数组方括号无空格
// 代码质量
'no-duplicate-imports': 'error', // 禁止重复导入
'no-useless-return': 'error', // 禁止无用的 return
'no-else-return': 'error', // 禁止 else return(提前 return)
'prefer-template': 'error', // 优先使用模板字符串
'template-curly-spacing': 'error', // 模板字符串大括号内无空格
'object-shorthand': ['error', 'always'], // 对象属性简写
// 放宽一些规则,避免过多警告
'no-prototype-builtins': 'off', // 允许使用原型方法
'no-nested-ternary': 'off', // 允许嵌套三元表达式
'no-param-reassign': 'off', // 允许修改参数
'consistent-return': 'off' // 不要求一致的 return
},
globals: {
// Taro 全局变量
wx: 'readonly',
getCurrentPages: 'readonly',
getApp: 'readonly',
// NutUI 全局变量
NutUI: 'readonly'
},
overrides: [
// 测试文件规则
{
files: ['**/__tests__/**/*', '**/*.test.js', '**/*.spec.js'],
env: {
jest: true,
node: true
},
rules: {
'no-console': 'off'
}
}
]
}