-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
99 lines (89 loc) · 2.73 KB
/
eslint.config.js
File metadata and controls
99 lines (89 loc) · 2.73 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
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* ESLint v9 Flat Config
* 从 .eslintrc.js 迁移而来
*/
const js = require('@eslint/js');
module.exports = [
// ESLint 推荐规则
js.configs.recommended,
// 全局配置
{
languageOptions: {
ecmaVersion: 2021,
sourceType: 'commonjs',
globals: {
// Node.js 全局变量
__dirname: 'readonly',
__filename: 'readonly',
Buffer: 'readonly',
console: 'readonly',
process: 'readonly',
require: 'readonly',
module: 'readonly',
exports: 'writable',
global: 'readonly',
setImmediate: 'readonly',
clearImmediate: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
URL: 'readonly',
queueMicrotask: 'readonly',
}
},
rules: {
// 代码风格
'indent': 'off', // 暂时关闭缩进检查,项目代码风格已稳定
'quotes': ['warn', 'single', { avoidEscape: true }],
'semi': ['error', 'always'],
'no-trailing-spaces': 'warn',
// 最佳实践
'no-unused-vars': ['warn', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
}],
'no-console': 'off', // 允许 console(日志库)
'no-empty': ['error', { allowEmptyCatch: true }],
'no-prototype-builtins': 'off',
// ES6+
'prefer-const': 'warn',
'no-var': 'warn',
'object-shorthand': 'warn',
'prefer-arrow-callback': 'off',
// 异步
'require-await': 'warn',
// 错误预防
'no-undef': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-unreachable': 'error',
}
},
// 测试文件特殊配置
{
files: ['test/**/*.js', '**/*.test.js'],
languageOptions: {
globals: {
describe: 'readonly',
it: 'readonly',
before: 'readonly',
after: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
expect: 'readonly',
}
}
},
// 忽略文件
{
ignores: [
'node_modules/',
'coverage/',
'old/',
'reports/',
'*.min.js',
'.nyc_output/',
]
}
];