forked from iwvw/API-Monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
166 lines (162 loc) · 4.8 KB
/
eslint.config.js
File metadata and controls
166 lines (162 loc) · 4.8 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const js = require('@eslint/js');
module.exports = [
js.configs.recommended,
{
// 全局配置
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
// Node.js 全局变量
require: 'readonly',
module: 'readonly',
exports: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
process: 'readonly',
console: 'readonly',
Buffer: 'readonly',
global: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setImmediate: 'readonly',
URL: 'readonly',
fetch: 'readonly',
ReadableStream: 'readonly',
TextEncoder: 'readonly',
TextDecoder: 'readonly',
// 浏览器全局变量
window: 'readonly',
document: 'readonly',
localStorage: 'readonly',
sessionStorage: 'readonly',
navigator: 'readonly',
location: 'readonly',
history: 'readonly',
WebSocket: 'readonly',
Audio: 'readonly',
Image: 'readonly',
HTMLElement: 'readonly',
HTMLCanvasElement: 'readonly',
HTMLVideoElement: 'readonly',
HTMLAudioElement: 'readonly',
Event: 'readonly',
CustomEvent: 'readonly',
MouseEvent: 'readonly',
KeyboardEvent: 'readonly',
ClipboardEvent: 'readonly',
DragEvent: 'readonly',
MutationObserver: 'readonly',
ResizeObserver: 'readonly',
IntersectionObserver: 'readonly',
requestAnimationFrame: 'readonly',
cancelAnimationFrame: 'readonly',
getComputedStyle: 'readonly',
matchMedia: 'readonly',
performance: 'readonly',
FileReader: 'readonly',
Blob: 'readonly',
FormData: 'readonly',
alert: 'readonly',
confirm: 'readonly',
prompt: 'readonly',
URLSearchParams: 'readonly',
// Worker API
Worker: 'readonly',
SharedWorker: 'readonly',
// 媒体 API
MediaMetadata: 'readonly',
// Chart.js
Chart: 'readonly',
// Vue 全局 (CDN 模式)
Vue: 'readonly',
// Socket.IO
io: 'readonly',
// Chrome 扩展 API
chrome: 'readonly',
// Monaco 编辑器
monaco: 'readonly',
// Highlight.js
hljs: 'readonly',
// Html5-QRCode
Html5Qrcode: 'readonly',
// AMLL 背景渲染
amllBgRender: 'writable',
// Vite 编译时常量
__USE_CDN__: 'readonly',
__CDN_PROVIDER__: 'readonly',
// 项目自定义全局 (前端模块间共享)
store: 'readonly',
toast: 'readonly',
app: 'readonly',
auth: 'readonly',
},
},
rules: {
// 基础规则
// TODO: 后续逐步修复未使用变量后,可将此规则改为 'error'
'no-unused-vars': [
'warn',
{
args: 'none', // 不检查函数参数
varsIgnorePattern: '^_|^DEFAULT_|^startTime$|^statusCode$',
caughtErrorsIgnorePattern: '.*',
},
],
'no-console': 'off',
'no-debugger': 'warn',
'no-empty': ['warn', { allowEmptyCatch: true }], // 允许空 catch
'no-constant-condition': 'warn',
// 代码风格(暂时放宽,避免大量改动)
semi: ['warn', 'always'],
quotes: ['warn', 'single', { avoidEscape: true, allowTemplateLiterals: true }],
indent: 'off', // 暂时关闭缩进检查,项目使用混合缩进
'comma-dangle': 'off',
'no-trailing-spaces': 'off',
'eol-last': 'off',
// 最佳实践
eqeqeq: 'off', // 允许 == (项目中很多是有意的)
'no-var': 'warn',
'prefer-const': 'off',
'no-throw-literal': 'warn',
'no-prototype-builtins': 'off',
'no-useless-escape': 'off', // 很多正则有意使用转义
'no-useless-catch': 'off', // 一些 try/catch 是有意保留的
'no-case-declarations': 'off',
'no-control-regex': 'off',
},
},
// 后端文件特定配置
{
files: ['server.js', 'src/**/*.js', 'modules/**/*.js'],
languageOptions: {
sourceType: 'commonjs', // 后端使用 CommonJS
},
},
// 前端文件特定配置
{
files: ['src/js/**/*.js'],
languageOptions: {
sourceType: 'module', // 前端使用 ESM
},
},
{
// 忽略文件
ignores: [
'node_modules/**',
'dist/**',
'public/**',
'data/**',
'tmp/**',
'test/**',
'*.min.js',
'agent-go/**',
'modules/_template/**', // 模板文件包含占位符语法
'plugin/**', // 浏览器扩展使用特殊 API
'src/js/modules/template.js', // 模板文件
'src/*_snippet*.js', // 代码片段
],
},
];