-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy path.eslintrc.cjs
More file actions
85 lines (79 loc) · 1.86 KB
/
.eslintrc.cjs
File metadata and controls
85 lines (79 loc) · 1.86 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
84
85
module.exports = {
root: true,
env: {
node: true,
es2021: true,
commonjs: true
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 'latest'
},
plugins: ['prettier'],
rules: {
// 基础规则
'no-console': 'off', // Node.js 项目允许 console
'consistent-return': 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
'prettier/prettier': 'error',
// 变量相关
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrors: 'none'
}
],
'prefer-const': 'error',
'no-var': 'error',
'no-shadow': 'error',
// 代码质量
eqeqeq: ['error', 'always'],
curly: ['error', 'all'],
'no-throw-literal': 'error',
'prefer-promise-reject-errors': 'error',
// 代码风格
'object-shorthand': 'error',
'prefer-template': 'error',
'template-curly-spacing': ['error', 'never'],
// Node.js 特定规则
'no-path-concat': 'error',
'handle-callback-err': 'error',
// ES6+ 规则
'arrow-body-style': ['error', 'as-needed'],
'prefer-arrow-callback': 'error',
'prefer-destructuring': [
'error',
{
array: false,
object: true
}
],
// 格式化规则(由 Prettier 处理)
semi: 'off',
quotes: 'off',
indent: 'off',
'comma-dangle': 'off'
},
overrides: [
{
// CLI 和脚本文件
files: ['cli/**/*.js', 'scripts/**/*.js'],
rules: {
'no-process-exit': 'off' // CLI 脚本允许 process.exit
}
},
{
// 测试文件
files: ['**/*.test.js', '**/*.spec.js', 'tests/**/*.js'],
env: {
jest: true
},
rules: {
'no-unused-expressions': 'off'
}
}
]
}