-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
155 lines (147 loc) · 5 KB
/
eslint.config.js
File metadata and controls
155 lines (147 loc) · 5 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
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import nextPlugin from '@next/eslint-plugin-next';
import reactPlugin from 'eslint-plugin-react';
import hooksPlugin from 'eslint-plugin-react-hooks';
import prettierConfig from 'eslint-config-prettier';
import globals from 'globals'; // Import globals
// Helper function to remove a specific global from a globals object
const removeGlobal = (globalsObj, globalToRemove) => {
const rest = { ...globalsObj };
delete rest[globalToRemove]; // Delete the key directly
return rest;
};
export default tseslint.config(
// 1. Global ignores and base rules for all files
{
ignores: [
'.next/**',
'.next-validation/**',
'node_modules/**',
'dist/**',
'public/**', // Ignore public dir (service workers, etc.)
'playwright-report/**', // Ignore playwright report dir
'test-results/**', // Ignore test results dir
'**/*.config.cjs', // Ignore .cjs config files for now
],
},
eslint.configs.recommended,
// 2. TypeScript specific configurations (Type-Aware)
{
files: ['**/*.ts', '**/*.tsx'],
extends: [...tseslint.configs.strictTypeChecked],
languageOptions: {
parserOptions: {
project: true, // Automatically find tsconfig.json
tsconfigRootDir: import.meta.dirname,
},
globals: {
...removeGlobal(globals.browser, 'AudioWorkletGlobalScope '), // Remove potential bad one
...globals.node, // Add Node globals if needed in TS files
AudioWorkletGlobalScope: 'readonly', // Add correct one
},
},
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: {
attributes: false,
},
},
],
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/restrict-template-expressions': [
'warn',
{ allowNumber: true, allowBoolean: true },
],
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-redundant-type-constituents': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn', // Downgrade to warn or fix the type
},
},
// 3. JavaScript specific configurations (NO Type-Aware Rules)
{
files: ['**/*.js', '**/*.mjs'], // Removed .cjs, handled by ignores for now
languageOptions: {
globals: {
...globals.node, // Add Node.js globals
...removeGlobal(globals.browser, 'AudioWorkletGlobalScope '), // Remove potential bad one
AudioWorkletGlobalScope: 'readonly', // Add correct one
},
},
rules: {
'no-undef': 'error', // Keep checking for undefined vars
},
},
// 4. Next.js / React specific configurations (Applies to JS/TS/JSX/TSX)
{
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: {
'@next/next': nextPlugin,
react: reactPlugin,
'react-hooks': hooksPlugin,
},
languageOptions: {
globals: {
...removeGlobal(globals.browser, 'AudioWorkletGlobalScope '), // Remove potential bad one
AudioWorkletGlobalScope: 'readonly', // Add correct one
},
},
rules: {
'@next/next/no-html-link-for-pages': 'warn', // Or 'error' based on original config
'@next/next/no-sync-scripts': 'warn', // Or 'error' based on original config
'react-hooks/exhaustive-deps': 'error',
'react/no-unescaped-entities': 'error',
},
settings: {
react: {
version: 'detect',
},
},
},
// 5. Overrides (Apply after main configs)
// Test files override
{
files: ['**/__tests__/**/*.ts?(x)', '**/*.test.ts?(x)', '**/playwright.config.js'],
languageOptions: {
globals: {
...globals.node, // Ensure Node globals for config files
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/await-thenable': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'no-undef': 'off', // Allow undefined vars in tests/configs
'no-unused-vars': 'off', // Allow unused vars in tests/configs
'@typescript-eslint/no-unused-vars': 'off', // Allow unused TS vars in tests/configs
},
},
// Actions override
{
files: ['app/actions/**/*.ts'],
rules: {
'@typescript-eslint/require-await': 'off',
},
},
// 6. Prettier config (Must be LAST)
{
rules: prettierConfig.rules,
}
);