-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy patheslint.config.mjs
148 lines (137 loc) · 3.94 KB
/
eslint.config.mjs
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
import { defineConfig, globalIgnores } from 'eslint/config';
import reactRefresh from 'eslint-plugin-react-refresh';
import reactCompiler from 'eslint-plugin-react-compiler';
import reactHooks from 'eslint-plugin-react-hooks';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Use FlatCompat only for the React plugin which doesn't fully support flat config yet
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});
// Get React recommended config through FlatCompat
const reactRecommendedConfig = compat.extends('plugin:react/recommended');
export default defineConfig([
// Global ignores
globalIgnores([
'**/dist',
'**/.eslintrc.cjs',
'src/components/ui/*.tsx',
'cli/**',
'**/node_modules/',
'public/**',
'functions/**'
]),
// Base JavaScript config (ESLint recommended)
js.configs.recommended,
// React recommended config from compat (filtered to exclude react-in-jsx-scope rule)
{
...reactRecommendedConfig[0],
rules: {
...reactRecommendedConfig[0].rules,
// Disable rules that aren't applicable to React 19
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
}
},
// Base config for all files with React-related rules
{
files: ['**/*.{js,jsx,ts,tsx,mjs,cjs}'],
ignores: ['vite.config.ts'],
plugins: {
'react-refresh': reactRefresh,
'react-compiler': reactCompiler,
'react-hooks': reactHooks,
},
linterOptions: {
reportUnusedDisableDirectives: false,
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
// React Refresh rules
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react-compiler/react-compiler': 'error',
// React Hooks recommended rules
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
// Disable the index as key rule
'react/no-array-index-key': 'off',
},
settings: {
react: {
version: 'detect',
},
},
},
// TypeScript specific configuration using recommended rules
{
files: ['**/*.{ts,tsx}'],
plugins: {
'@typescript-eslint': tsPlugin
},
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaFeatures: { jsx: true },
},
},
// Use recommended rules as a base
rules: {
...tsPlugin.configs.recommended.rules,
// Add our own custom rule on top of recommended
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
},
settings: {
react: {
version: 'detect',
},
},
},
// Vite config special handling
{
files: ['vite.config.ts'],
plugins: {
'@typescript-eslint': tsPlugin
},
languageOptions: {
parser: tsParser,
parserOptions: {
tsconfigRootDir: process.cwd(),
project: './tsconfig.node.json',
},
},
rules: {
// Turn off TypeScript rules that would cause issues with Vite config
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
},
settings: {
react: {
version: 'detect',
},
},
},
]);