-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy patheslint.config.mjs
More file actions
312 lines (299 loc) · 8.73 KB
/
Copy patheslint.config.mjs
File metadata and controls
312 lines (299 loc) · 8.73 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
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import globals from 'globals';
// TypeScript plugins and parsers
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import tseslint from 'typescript-eslint';
// React plugins
import eslintReactPlugin from '@eslint-react/eslint-plugin';
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import reactRefreshPlugin from 'eslint-plugin-react-refresh';
// Other plugins
import importPlugin from 'eslint-plugin-import';
import linguiPlugin from 'eslint-plugin-lingui';
import prettierPlugin from 'eslint-plugin-prettier';
import turboPlugin from 'eslint-plugin-turbo';
import unicornPlugin from 'eslint-plugin-unicorn';
import unusedImportsPlugin from 'eslint-plugin-unused-imports';
import vitestPlugin from 'eslint-plugin-vitest';
// Compatibility layer for traditional configs
const compat = new FlatCompat({
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default defineConfig([
// Commonly ignores
{
ignores: [
// Build and dependency directories
'**/node_modules/*',
'**/dist',
'**/.netlify',
// Configuration files
'**/*.config.{js,mjs,ts,mts}',
'**/*.setup.{js,mjs,ts,mts}',
// Generated code (use a more consistent pattern)
'**/typechain/**',
'**/src/{types,contracts,subgraphs}/**',
'**/*.gen.ts',
],
},
// Base TypeScript configuration for all TypeScript files
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tsParser,
sourceType: 'module',
ecmaVersion: 2020,
globals: {
...globals.node,
},
parserOptions: {
// Enable project service for better TypeScript integration
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
'@typescript-eslint': typescriptEslintEslintPlugin,
import: importPlugin,
lingui: linguiPlugin,
prettier: prettierPlugin,
turbo: turboPlugin,
unicorn: unicornPlugin,
'unused-imports': unusedImportsPlugin,
vitest: vitestPlugin,
},
extends: [
...tseslint.configs.recommended,
...compat.extends(
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:prettier/recommended',
'prettier',
),
],
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
// Import plugin rules
'import/no-unresolved': 'error',
'import/named': 'warn',
'import/default': 'error',
'import/namespace': 'error',
'import/export': 'error',
'import/order': [
'warn',
{
groups: [
'type',
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
],
pathGroups: [
{
pattern: 'react',
group: 'builtin',
position: 'before',
},
{
pattern: '**/*.{css,scss,sass,less,module.css,module.scss}',
group: 'object',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ['react', 'builtin'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
// Lingui plugin rules
'lingui/no-unlocalized-strings': 'off',
'lingui/t-call-in-function': 'error',
'lingui/no-single-variables-to-translate': 'error',
// Unicorn plugin rules
'unicorn/better-regex': 'error',
'unicorn/no-nested-ternary': 'error',
// Unused imports plugin rules
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
// Prettier rules
'prettier/prettier': 'warn',
},
settings: {
...importPlugin.configs.typescript.settings,
'import/resolver': {
...importPlugin.configs.typescript.settings['import/resolver'],
typescript: {
project: './tsconfig.json',
},
},
},
},
// nouns-docs specific configuration
{
files: ['**/packages/nouns-docs/**/*.{ts,tsx}'],
settings: {
...importPlugin.configs.typescript.settings,
'import/resolver': {
...importPlugin.configs.typescript.settings['import/resolver'],
typescript: {
project: 'packages/nouns-docs/tsconfig.json',
},
},
},
},
// Additional React-specific rules only for the webapp package
{
files: ['**/packages/nouns-webapp/**/*.{ts,tsx}'],
settings: {
...importPlugin.configs.typescript.settings,
'import/resolver': {
...importPlugin.configs.typescript.settings['import/resolver'],
typescript: {
project: 'packages/nouns-webapp/tsconfig.json',
},
},
},
languageOptions: {
globals: {
...globals.browser,
},
},
plugins: {
react: reactPlugin,
'react-hooks': reactHooksPlugin,
'react-refresh': reactRefreshPlugin,
prettier: prettierPlugin,
},
extends: [
...compat.extends('plugin:react/recommended', 'plugin:prettier/recommended'),
eslintReactPlugin.configs['recommended-typescript'],
],
rules: {
// React hooks rules
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
// React rules
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
'react/prop-types': 'error',
'react/react-in-jsx-scope': 'off', // Not needed in React 17+
// ESLint React rules
'@eslint-react/no-class-component': 'error',
// Typescript eslint rules
'@typescript-eslint/strict-boolean-expressions': [
'error',
{
allowNullableString: true,
},
],
'no-restricted-imports': [
'warn',
{
paths: [
{
name: '@apollo/client',
message:
'Use @tanstack/react-query instead. ref: https://the-guild.dev/graphql/codegen/docs/guides/react-query#type-safe-graphql-operation-execution',
},
{
name: 'react-bootstrap',
message: 'Use tailwindcss instead',
},
],
patterns: [
{
regex: '.*redux.*',
message: 'Use jotai and @tanstack/react-query instead',
},
{
group: ['lucide-react'],
allowImportNamePattern: '^(IconNode|LucideIcon|LucideProps|SVGAttributes|.+Icon)$',
message:
'Import specific *Icon exports instead of generic names. e.g. DownloadIcon instead of Download',
},
],
},
],
// Prettier rules
'prettier/prettier': 'error',
},
},
// Base JS configuration
{
files: ['**/*.js', '**/*.mjs'],
extends: [js.configs.recommended, ...compat.extends('plugin:prettier/recommended')],
languageOptions: {
ecmaVersion: 2020,
globals: {
...globals.node,
},
},
plugins: {
import: importPlugin,
prettier: prettierPlugin,
},
rules: {
// Import plugin rules for JS files
'import/no-unresolved': 'error',
'import/named': 'warn',
'import/default': 'error',
'import/namespace': 'error',
'import/export': 'error',
// Prettier rules
'prettier/prettier': 'warn',
},
},
// nouns-api specific configuration (Ponder)
{
files: ['**/packages/nouns-api/**/*.{ts,tsx}'],
extends: [...compat.extends('ponder')],
languageOptions: {
parserOptions: {
project: ['packages/nouns-api/tsconfig.json'],
},
},
settings: {
...importPlugin.configs.typescript.settings,
'import/resolver': {
...importPlugin.configs.typescript.settings['import/resolver'],
typescript: {
project: 'packages/nouns-api/tsconfig.json',
},
},
},
rules: {
// Disable import/no-unresolved for Ponder virtual modules
'import/no-unresolved': [
'error',
{
ignore: ['^ponder:'],
},
],
},
},
// Global ignores
globalIgnores(['**/*.d.ts']),
]);