forked from matt1398/claude-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
591 lines (543 loc) · 17.7 KB
/
eslint.config.js
File metadata and controls
591 lines (543 loc) · 17.7 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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import { defineConfig, globalIgnores } from 'eslint/config';
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import reactPlugin from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import tailwindcss from 'eslint-plugin-tailwindcss';
import sonarjs from 'eslint-plugin-sonarjs';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import importPlugin from 'eslint-plugin-import';
import security from 'eslint-plugin-security';
import boundaries from 'eslint-plugin-boundaries';
import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import globals from 'globals';
export default defineConfig([
// Global ignores
globalIgnores([
'dist/**',
'dist-electron/**',
'build/**',
'node_modules/**',
'*.config.js',
'*.config.cjs',
'*.config.ts',
'out/**',
]),
// Base ESLint recommended rules
js.configs.recommended,
// TypeScript-ESLint recommended with type checking + stylistic
// Using recommended (not strict) for a balanced approach
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
// SonarJS - Code quality and bug detection rules
sonarjs.configs.recommended,
// Security - Catch common security mistakes in AI-generated code
security.configs.recommended,
// TypeScript parser options for type-aware linting
{
name: 'typescript-parser-options',
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
// Import plugin configuration - Main/Preload (uses tsconfig.node.json)
{
name: 'import-plugin-main',
files: ['src/main/**/*.ts', 'src/preload/**/*.ts'],
plugins: {
import: importPlugin,
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.node.json',
},
},
},
rules: {
'import/no-cycle': ['error', { maxDepth: 3, ignoreExternal: true }],
'import/no-unresolved': 'error',
'import/no-default-export': 'warn',
},
},
// Import plugin configuration - Renderer (uses tsconfig.json)
{
name: 'import-plugin-renderer',
files: ['src/renderer/**/*.{ts,tsx}'],
plugins: {
import: importPlugin,
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
},
},
rules: {
'import/no-cycle': ['error', { maxDepth: 3, ignoreExternal: true }],
'import/no-unresolved': 'error',
'import/no-default-export': 'warn',
},
},
// Module boundaries - Enforce Electron three-process architecture
{
name: 'module-boundaries',
files: ['src/**/*.{js,jsx,ts,tsx}'],
plugins: {
boundaries: boundaries,
},
settings: {
'boundaries/elements': [
{ type: 'main', pattern: 'src/main/**', mode: 'folder' },
{ type: 'preload', pattern: 'src/preload/**', mode: 'folder' },
{ type: 'renderer', pattern: 'src/renderer/**', mode: 'folder' },
{ type: 'shared', pattern: 'src/shared/**', mode: 'folder' },
],
'boundaries/ignore': ['**/*.test.ts', '**/*.spec.ts'],
},
rules: {
// Enforce strict module boundaries for Electron architecture
'boundaries/element-types': [
'error',
{
default: 'disallow',
rules: [
// Renderer can only import from renderer and shared
{ from: 'renderer', allow: ['renderer', 'shared'] },
// Main process can only import from main and shared
{ from: 'main', allow: ['main', 'shared'] },
// Preload can only import from preload and shared
{ from: 'preload', allow: ['preload', 'shared'] },
// Shared can import from shared and main (for type re-exports)
{ from: 'shared', allow: ['shared', 'main'] },
],
},
],
// Prevent importing private modules
'boundaries/no-private': 'error',
},
},
// ESLint Comments
{
name: 'eslint-comments',
files: ['src/**/*.{js,jsx,ts,tsx}'],
plugins: {
'@eslint-community/eslint-comments': eslintComments,
},
rules: {
// Prevents blanket-disabling rules
'@eslint-community/eslint-comments/no-unlimited-disable': 'error',
// Require description for disable comments
'@eslint-community/eslint-comments/require-description': [
'error',
{ ignore: [] },
],
// Re-enable rules after disabling
'@eslint-community/eslint-comments/disable-enable-pair': 'error',
// No duplicate disable comments
'@eslint-community/eslint-comments/no-duplicate-disable': 'error',
// Unused disable comments
'@eslint-community/eslint-comments/no-unused-disable': 'error',
},
},
// Import sorting for all JS/TS files
{
name: 'import-sorting',
files: ['src/**/*.{js,jsx,ts,tsx}'],
plugins: {
'simple-import-sort': simpleImportSort,
},
rules: {
'simple-import-sort/imports': [
'error',
{
groups: [
// Side effect imports (e.g., import './styles.css')
['^\\u0000'],
// Node.js builtins (fs, path, etc.)
['^node:'],
// React and related packages
['^react', '^react-dom'],
// External packages from node_modules
['^@?\\w'],
// Internal aliases (@/ paths)
['^@/'],
// Parent imports (../)
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
// Same-folder imports (./)
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
// Type imports
['^.+\\u0000$'],
],
},
],
'simple-import-sort/exports': 'error',
},
},
// Main process (Electron Node.js)
{
name: 'electron-main',
files: ['src/main/**/*.ts'],
languageOptions: {
globals: {
...globals.node,
},
},
rules: {
// Allow console in main process for logging
'no-console': 'off',
},
},
// Preload script (Electron bridge)
{
name: 'electron-preload',
files: ['src/preload/**/*.ts'],
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
},
},
// Renderer process (React + A11y + Tailwind)
{
name: 'renderer-react',
files: ['src/renderer/**/*.{ts,tsx}'],
languageOptions: {
globals: {
...globals.browser,
},
},
plugins: {
react: reactPlugin,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
'jsx-a11y': jsxA11y,
tailwindcss: tailwindcss,
},
settings: {
react: {
version: 'detect',
},
tailwindcss: {
// Tailwind config path (relative to cwd)
config: 'tailwind.config.js',
// Allow custom classnames (e.g., from CSS modules)
callees: ['classnames', 'clsx', 'cn'],
},
},
rules: {
// React recommended rules
...reactPlugin.configs.recommended.rules,
// JSX runtime (React 17+) - no need to import React
...reactPlugin.configs['jsx-runtime'].rules,
// React Hooks rules
...reactHooks.configs.recommended.rules,
// Accessibility rules (recommended)
...jsxA11y.configs.recommended.rules,
// Tailwind CSS rules
...tailwindcss.configs.recommended.rules,
// React Refresh for HMR
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
// Disable prop-types since we use TypeScript
'react/prop-types': 'off',
// A11y rule adjustments for this project
// Allow click handlers on divs when keyboard handlers also present
'jsx-a11y/click-events-have-key-events': 'warn',
'jsx-a11y/no-static-element-interactions': 'warn',
// Allow autofocus for search inputs in desktop apps
'jsx-a11y/no-autofocus': 'off',
// Tailwind CSS rule adjustments
// Warn on class order (Prettier plugin handles sorting)
'tailwindcss/classnames-order': 'off', // Prettier plugin handles this
// Warn on conflicting classes
'tailwindcss/no-contradicting-classname': 'error',
// Warn on custom classnames that don't exist
'tailwindcss/no-custom-classname': 'warn',
// === React-Specific Rules ===
// Consistent component definition
'react/function-component-definition': [
'error',
{
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function',
},
],
// Strengthen exhaustive-deps
'react-hooks/exhaustive-deps': 'error',
// Prevent prop spreading
'react/jsx-props-no-spreading': [
'warn',
{
exceptions: ['input', 'button', 'Input', 'Button', 'textarea', 'select'],
},
],
// Ensure key props
'react/jsx-key': [
'error',
{
checkFragmentShorthand: true,
checkKeyMustBeforeSpread: true,
},
],
// Prevent unnecessary fragments
'react/jsx-no-useless-fragment': 'warn',
// Self-closing components for consistency
'react/self-closing-comp': [
'error',
{
component: true,
html: true,
},
],
},
},
// Test files
{
name: 'test-files',
files: ['test/**/*.ts', '**/*.test.ts', '**/*.spec.ts'],
languageOptions: {
globals: {
...globals.node,
},
parserOptions: {
projectService: false,
project: './tsconfig.test.json',
},
},
rules: {
// Relax TypeScript strict rules for tests
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/unbound-method': 'off',
// Relax function/export rules for tests
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
// Relax naming conventions for tests (allow describe, it, expect patterns)
'@typescript-eslint/naming-convention': 'off',
// Allow magic numbers in tests
'sonarjs/no-hardcoded-ip': 'off',
// Allow floating promises in tests (common with async test helpers)
'@typescript-eslint/no-floating-promises': 'off',
},
},
// Custom rule overrides for all TypeScript files
{
name: 'custom-rules',
files: ['src/**/*.{ts,tsx}'],
rules: {
// === Core JavaScript rules ===
'prefer-const': 'error',
'no-var': 'error',
eqeqeq: ['error', 'always', { null: 'ignore' }],
// === TypeScript Import/Export rules ===
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'inline-type-imports',
},
],
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
// === Unused variables ===
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
// === Relaxed strict rules for practical use ===
// Allow empty functions (useful for callbacks and stubs)
'@typescript-eslint/no-empty-function': 'off',
// Allow numbers/booleans in template literals (common pattern)
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowNullish: false,
},
],
// Allow async functions without await (IPC handlers often need this)
'@typescript-eslint/require-await': 'off',
// Allow floating promises in event handlers (common in Electron)
'@typescript-eslint/no-floating-promises': [
'error',
{
ignoreVoid: true,
ignoreIIFE: true,
},
],
// Allow promises in places that don't expect them (event handlers)
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: {
attributes: false,
arguments: false,
},
},
],
// Allow void expression in arrow functions shorthand
'@typescript-eslint/no-confusing-void-expression': [
'error',
{
ignoreArrowShorthand: true,
ignoreVoidOperator: true,
},
],
// Prefer nullish coalescing but don't error on logical or
'@typescript-eslint/prefer-nullish-coalescing': 'off',
// Allow inferrable types (style preference)
'@typescript-eslint/no-inferrable-types': 'off',
// === Anti-Hallucination Rules ===
// Explicit return types
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
allowDirectConstAssertionInArrowFunctions: true,
},
],
// Explicit types for exported functions (minimum requirement)
'@typescript-eslint/explicit-module-boundary-types': 'warn',
// Prevent variable shadowing
'@typescript-eslint/no-shadow': 'error',
// === Naming Conventions ===
'@typescript-eslint/naming-convention': [
'warn',
// Imports can be camelCase or PascalCase (React, ReactDOM, App, etc.)
{
selector: 'import',
format: ['camelCase', 'PascalCase'],
},
// Default: variables and parameters in camelCase
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
// Static readonly class properties can be UPPER_CASE
{
selector: 'classProperty',
modifiers: ['static', 'readonly'],
format: ['camelCase', 'UPPER_CASE'],
},
// Variables: camelCase or UPPER_CASE for constants
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
},
// Functions: camelCase (includes type guards like isXxx, builders like buildXxx)
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
},
// Parameters: camelCase, allow leading underscore for unused
{
selector: 'parameter',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
// Types and interfaces in PascalCase
{
selector: 'typeLike',
format: ['PascalCase'],
},
// Interfaces should NOT start with I (modern convention)
{
selector: 'interface',
format: ['PascalCase'],
custom: { regex: '^I[A-Z]', match: false },
},
// Enum members in PascalCase or UPPER_CASE
{
selector: 'enumMember',
format: ['PascalCase', 'UPPER_CASE'],
},
// Object literal properties: allow any format (for API compatibility)
{
selector: 'objectLiteralProperty',
format: null,
},
// Type properties: allow any format (for type definitions matching APIs)
{
selector: 'typeProperty',
format: null,
},
],
// === Import Restrictions ===
// Note: boundaries/element-types handles main/renderer separation
'no-restricted-imports': [
'error',
{
patterns: [
// Prevent deep relative imports - use @/ aliases
{
group: ['../**/..'],
message: 'Avoid deep relative imports, use @/ aliases',
},
],
},
],
// === Mutation Prevention ===
'no-param-reassign': [
'error',
{
props: true,
ignorePropertyModificationsFor: ['draft', 'acc', 'ctx', 'state', 'req', 'res'],
},
],
// === SonarJS rule adjustments ===
// Cognitive complexity - warn instead of error for gradual adoption
'sonarjs/cognitive-complexity': 'off',
// Allow some duplication in similar but not identical code
'sonarjs/no-duplicate-string': 'off',
// Relax for Electron IPC patterns (many similar switch cases)
'sonarjs/no-small-switch': 'off',
// Allow nested ternaries in JSX (common React pattern)
'sonarjs/no-nested-conditional': 'off',
// === Security rule adjustments (Code Protection) ===
// These catch common security mistakes
'security/detect-eval-with-expression': 'error',
// Disabled: This is a desktop file reader app - file system access is expected
'security/detect-non-literal-fs-filename': 'off',
// Disabled: Dynamic patterns are intentional in this app
'security/detect-non-literal-regexp': 'off',
// Disabled: Often false positives with typed code
'security/detect-object-injection': 'off',
'security/detect-child-process': 'warn',
'security/detect-non-literal-require': 'warn',
'security/detect-possible-timing-attacks': 'warn',
},
},
// === IMPORTANT: eslint-config-prettier MUST be LAST ===
// This disables all ESLint rules that conflict with Prettier
// Prettier handles formatting, ESLint handles code quality
eslintConfigPrettier,
]);