-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eslintrc.js
More file actions
82 lines (79 loc) · 2.14 KB
/
Copy path.eslintrc.js
File metadata and controls
82 lines (79 loc) · 2.14 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
module.exports = {
root: true,
env: {
node: true,
es2022: true,
jest: true,
browser: true, // 浏览器环境(PUPPeteer/前端)
},
extends: [
'eslint:recommended',
],
parserOptions: {
ecmaVersion: 2022,
sourceType: 'script', // CommonJS
},
rules: {
// 错误预防
'no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'no-console': 'off', // 允许 console,但建议使用 logger
'no-debugger': 'warn',
'no-duplicate-imports': 'error',
'no-unreachable': 'error',
'no-constant-condition': 'warn',
'no-useless-escape': 'off', // 正则表达式中的转义字符可以提高可读性
// 最佳实践
'eqeqeq': ['error', 'always', { null: 'ignore' }],
'curly': ['error', 'multi-line'],
'no-var': 'error',
'prefer-const': 'error',
'prefer-arrow-callback': 'warn',
'arrow-body-style': ['warn', 'as-needed'],
'object-shorthand': 'warn',
// 代码风格
'indent': ['error', 2, { SwitchCase: 1 }],
'quotes': ['error', 'single', { avoidEscape: true }],
'semi': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'max-len': ['warn', { code: 120, ignoreUrls: true, ignoreStrings: true }],
'no-trailing-spaces': 'error',
'eol-last': 'error',
// Node.js 特定
'no-process-exit': 'warn',
'no-sync': 'off', // 允许同步操作(SQLite 需要)
},
overrides: [
{
// 测试文件使用更宽松的规则
files: ['tests/**/*.js', '*.test.js'],
rules: {
'no-console': 'off',
},
},
{
// Service Worker 文件 (public/sw.js)
files: ['public/sw.js'],
env: {
serviceworker: true,
},
},
{
// Puppeteer 页面环境脚本
files: ['scrapers/sources/puppeteer.js', 'scrapers/middleware.js', 'scrapers/browser.js', 'inspect_dom.js'],
globals: {
document: 'readonly',
window: 'readonly',
navigator: 'readonly',
},
},
],
ignorePatterns: [
'node_modules/',
'public/app.js',
'dist/',
'build/',
'*.db',
'.vercel/',
'dashboard/',
],
};