-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
497 lines (447 loc) · 14 KB
/
eslint.config.js
File metadata and controls
497 lines (447 loc) · 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
import js from '@eslint/js';
import pluginVue from 'eslint-plugin-vue';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';
import vueParser from 'vue-eslint-parser';
import functional from 'eslint-plugin-functional';
import unicorn from 'eslint-plugin-unicorn';
import prettierConfig from 'eslint-config-prettier';
export default [
// Base recommended configs
js.configs.recommended,
...pluginVue.configs['flat/essential'],
// Global ignores
{
ignores: [
'**/dist/**',
'**/node_modules/**',
'**/.vite/**',
'**/documentation/.docusaurus/**',
'**/documentation/build/**',
'**/coverage/**',
],
},
// Main configuration for JS/TS files (Vue handled separately)
{
files: ['**/*.{js,mjs,cjs,ts,mts}'],
plugins: {
'@typescript-eslint': tseslint,
functional,
unicorn,
},
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parser: tsparser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
projectService: true,
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.vue'],
},
globals: {
process: 'readonly',
console: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
requestAnimationFrame: 'readonly',
cancelAnimationFrame: 'readonly',
document: 'readonly',
window: 'readonly',
navigator: 'readonly',
HTMLCanvasElement: 'readonly',
HTMLVideoElement: 'readonly',
HTMLImageElement: 'readonly',
Image: 'readonly',
File: 'readonly',
Blob: 'readonly',
URL: 'readonly',
Worker: 'readonly',
MessageEvent: 'readonly',
Event: 'readonly',
CustomEvent: 'readonly',
KeyboardEvent: 'readonly',
MouseEvent: 'readonly',
WheelEvent: 'readonly',
TouchEvent: 'readonly',
PointerEvent: 'readonly',
GamepadEvent: 'readonly',
ResizeObserver: 'readonly',
IntersectionObserver: 'readonly',
MutationObserver: 'readonly',
performance: 'readonly',
AudioContext: 'readonly',
webkitAudioContext: 'readonly',
// TypeScript globals
Record: 'readonly',
Partial: 'readonly',
Required: 'readonly',
Readonly: 'readonly',
Pick: 'readonly',
Omit: 'readonly',
Exclude: 'readonly',
Extract: 'readonly',
NonNullable: 'readonly',
ReturnType: 'readonly',
InstanceType: 'readonly',
Parameters: 'readonly',
ConstructorParameters: 'readonly',
},
},
rules: {
// ====================
// FUNCTIONAL PROGRAMMING RULES
// ====================
// Prevent classes (align with project philosophy)
'functional/no-classes': 'error', // Keep as error - no classes allowed
// Prevent mutations
'functional/immutable-data': ['error', {
ignoreIdentifierPattern: '^(this|module|exports)',
ignoreAccessorPattern: [
'**.current.**', // Allow React refs
'**.value', // Allow Vue refs
'**.position.**', // Allow Three.js mutations
'**.rotation.**',
'**.scale.**',
'**.material.**',
'**.userData.**',
],
}],
// Prefer functional alternatives but allow loops when necessary
'functional/no-loop-statements': 'warn',
// Prefer const over let
'functional/no-let': ['warn', {
allowInForLoopInit: false,
allowInFunctions: true, // Allow let in function scope for closures
}],
// Prevent try-catch (use Result types instead)
'functional/no-try-statements': 'off', // Too strict for real-world apps
// ====================
// UNICORN RULES (Modern Best Practices)
// ====================
// Prevent abbreviations (prefer full words)
'unicorn/prevent-abbreviations': ['error', {
allowList: {
// Common abbreviations to allow
args: true,
db: true,
dir: true,
e: true, // Event in catch
env: true,
fn: true,
i: true, // Index in specific contexts
id: true,
params: true,
props: true,
ref: true,
refs: true,
req: true,
res: true,
src: true,
url: true,
http: true,
https: true,
// Three.js specific
ctx: true,
x: true,
y: true,
z: true,
// Common dev abbreviations
dev: true,
prod: true,
temp: true,
// Game dev & physics
max: true,
min: true,
fps: true,
// Ref-like is common pattern
RefLike: true,
},
}],
// Prefer modern array methods
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-array-find': 'error',
// Prefer spread over Array.from
'unicorn/prefer-spread': 'error',
// Consistent error handling
'unicorn/prefer-modern-math-apis': 'error',
// Better regex
'unicorn/better-regex': 'error',
'unicorn/numeric-separators-style': 'off',
// ====================
// COMPLEXITY RULES
// ====================
// Max cyclomatic complexity (McCabe's recommended max)
'complexity': ['warn', { max: 10 }],
// Max nested callbacks
'max-depth': ['error', { max: 4 }],
// Max lines per function
'max-lines-per-function': ['warn', {
max: 100,
skipBlankLines: true,
skipComments: true,
IIFEs: true,
}],
// Max parameters
'max-params': ['warn', { max: 5 }],
// ====================
// TYPESCRIPT NAMING CONVENTIONS
// ====================
// Disabled because it requires type information which isn't available for all files
'@typescript-eslint/naming-convention': 'off',
// Use simpler camelcase rule
'camelcase': ['warn', {
properties: 'never',
ignoreDestructuring: true,
ignoreImports: true,
allow: ['^UNSAFE_', '^unstable_', '^_'], // React conventions and private vars
}],
// ====================
// MAGIC NUMBERS
// ====================
'no-magic-numbers': ['warn', {
ignore: [0, 1, -1, 2, 3, 4, 5, 10, 100, 1000], // Common constants
ignoreArrayIndexes: true,
ignoreDefaultValues: true,
ignoreClassFieldInitialValues: true,
enforceConst: true,
detectObjects: false,
}],
// ====================
// GENERAL CODE QUALITY
// ====================
// Prefer const
'prefer-const': 'error',
// No var
'no-var': 'error',
// Arrow functions for callbacks
'prefer-arrow-callback': 'error',
// Template literals over concatenation
'prefer-template': 'error',
// No console in production
'no-console': ['warn', { allow: ['warn', 'error'] }],
// No debugger in production
'no-debugger': 'warn',
// Consistent return
'consistent-return': 'warn',
// No unused vars
'no-unused-vars': 'off', // Turn off base rule
'@typescript-eslint/no-unused-vars': ['warn', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
}],
// Explicit function return types
'@typescript-eslint/explicit-function-return-type': 'off', // Too verbose for all cases
// No explicit any
'@typescript-eslint/no-explicit-any': 'warn',
// ====================
// VUE-SPECIFIC OVERRIDES
// ====================
'vue/multi-word-component-names': 'off', // Allow single-word components
},
},
// Vue files specific configuration
{
files: ['**/*.vue'],
plugins: {
'@typescript-eslint': tseslint,
functional,
unicorn,
},
languageOptions: {
parser: vueParser,
parserOptions: {
parser: tsparser,
ecmaVersion: 'latest',
sourceType: 'module',
projectService: false,
extraFileExtensions: ['.vue'],
},
globals: {
process: 'readonly',
console: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
requestAnimationFrame: 'readonly',
cancelAnimationFrame: 'readonly',
document: 'readonly',
window: 'readonly',
navigator: 'readonly',
HTMLCanvasElement: 'readonly',
HTMLVideoElement: 'readonly',
HTMLImageElement: 'readonly',
Image: 'readonly',
File: 'readonly',
Blob: 'readonly',
URL: 'readonly',
Worker: 'readonly',
MessageEvent: 'readonly',
Event: 'readonly',
CustomEvent: 'readonly',
KeyboardEvent: 'readonly',
MouseEvent: 'readonly',
WheelEvent: 'readonly',
TouchEvent: 'readonly',
PointerEvent: 'readonly',
GamepadEvent: 'readonly',
Gamepad: 'readonly',
ResizeObserver: 'readonly',
IntersectionObserver: 'readonly',
MutationObserver: 'readonly',
Performance: 'readonly',
performance: 'readonly',
AudioContext: 'readonly',
AudioBuffer: 'readonly',
GainNode: 'readonly',
fetch: 'readonly',
Response: 'readonly',
Headers: 'readonly',
TextEncoder: 'readonly',
TextDecoder: 'readonly',
Float32Array: 'readonly',
Uint8Array: 'readonly',
Uint16Array: 'readonly',
Uint32Array: 'readonly',
Int8Array: 'readonly',
Int16Array: 'readonly',
Int32Array: 'readonly',
ArrayBuffer: 'readonly',
DataView: 'readonly',
WebSocket: 'readonly',
WebGLRenderingContext: 'readonly',
WebGL2RenderingContext: 'readonly',
localStorage: 'readonly',
sessionStorage: 'readonly',
location: 'readonly',
history: 'readonly',
screen: 'readonly',
crypto: 'readonly',
atob: 'readonly',
btoa: 'readonly',
structuredClone: 'readonly',
postMessage: 'readonly',
onmessage: 'readonly',
onerror: 'readonly',
self: 'readonly',
importScripts: 'readonly',
close: 'readonly',
DOMParser: 'readonly',
XMLSerializer: 'readonly',
alert: 'readonly',
confirm: 'readonly',
prompt: 'readonly',
},
},
rules: {
// Disable type-aware rules for Vue files (no projectService)
// vue-tsc handles type checking for Vue files
'functional/immutable-data': 'off',
'functional/no-let': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'consistent-return': 'off',
'vue/multi-word-component-names': 'off',
'no-undef': 'off', // TypeScript handles this via vue-tsc
'no-unused-vars': 'off', // TypeScript handles this via vue-tsc
},
},
// Three.js files - allow necessary mutations for 3D objects
{
files: ['packages/threejs/**/*.ts', 'src/views/**/*.ts'],
rules: {
// Three.js requires mutating objects for position, rotation, etc.
'functional/immutable-data': 'warn',
'max-lines-per-function': ['warn', { max: 150 }],
'complexity': ['warn', { max: 15 }],
},
},
// Animation package - timeline management requires mutable state
{
files: ['packages/animation/**/*.ts'],
rules: {
'functional/immutable-data': 'warn',
'functional/no-let': 'warn',
},
},
// Declaration files - skip type checking and no-undef
{
files: ['**/*.d.ts'],
languageOptions: {
parserOptions: {
projectService: false,
},
},
rules: {
'no-undef': 'off', // Declaration files define types
'@typescript-eslint/no-unused-vars': 'off',
'no-redeclare': 'off', // Type declarations are redeclaring types
},
},
// Utility files often need to mutate state
{
files: ['src/utils/**/*.ts', 'src/router/**/*.ts', 'src/config/**/*.ts', 'packages/controls/**/*.ts', 'packages/audio/**/*.ts', 'packages/game/**/*.ts', 'packages/recording/**/*.ts'],
rules: {
'functional/immutable-data': 'warn',
'functional/no-let': 'warn',
},
},
// Test files specific configuration
{
files: ['**/*.test.ts', '**/*.test.js', '**/*.spec.ts', '**/*.spec.js'],
languageOptions: {
parserOptions: {
projectService: false,
},
},
rules: {
// Relax some rules for tests
'max-lines-per-function': 'off',
'no-magic-numbers': 'off',
'@typescript-eslint/naming-convention': 'off',
'functional/no-let': 'off',
'functional/immutable-data': 'off',
},
},
// Config files and scripts - disable type checking
{
files: ['*.config.{js,ts,mjs,cjs}', '.eslintrc.{js,cjs}', '**/vite.config.ts', 'scripts/**/*.js'],
languageOptions: {
parserOptions: {
projectService: false,
},
},
rules: {
// Relax rules for config files
'no-magic-numbers': 'off',
'@typescript-eslint/naming-convention': 'off',
'unicorn/prevent-abbreviations': 'off',
'no-undef': 'off',
},
},
// JavaScript files - disable TypeScript-specific rules
{
files: ['**/*.js', '**/*.mjs', '**/*.cjs'],
languageOptions: {
parserOptions: {
projectService: false,
},
},
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'no-undef': 'off',
'functional/immutable-data': 'off', // Can't use type info on JS files
'consistent-return': 'off',
},
},
// Apply Prettier config (should be last to override formatting rules)
prettierConfig,
];