-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy patheslint.config.js
More file actions
155 lines (150 loc) · 5 KB
/
eslint.config.js
File metadata and controls
155 lines (150 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
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
import storybook from 'eslint-plugin-storybook'
import js from '@eslint/js'
import typescript from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import prettier from 'eslint-config-prettier'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import globals from 'globals'
export default [
js.configs.recommended,
prettier,
{
files: ['src/**/*.{ts,tsx}'],
ignores: ['node_modules', 'dist', 'dist-isolation', 'src-tauri', 'thunderbird-*', 'backend'],
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
...globals.node,
React: 'readonly',
Bun: 'readonly',
// TypeScript types
NodeJS: 'readonly',
RequestInfo: 'readonly',
RequestInit: 'readonly',
},
},
plugins: {
'@typescript-eslint': typescript,
react,
'react-hooks': reactHooks,
},
settings: {
react: {
version: 'detect',
},
},
rules: {
// TypeScript rules
// Turn off base rules that conflict with TypeScript equivalents
'no-undef': 'off', // TypeScript handles this
'no-unused-vars': 'off',
'no-redeclare': 'off', // Turn off base rule for TypeScript overloads
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_', // fn args like (_evt)
varsIgnorePattern: '^_', // variables like const _x = ...
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_', // catch ( _err ) { ... }
ignoreRestSiblings: true, // const { used, ..._rest } = obj
},
],
'@typescript-eslint/no-redeclare': 'error', // Use TypeScript-aware version
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off',
// React rules
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
// React Hooks rules
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
// General rules
'no-console': ['warn', { allow: ['warn', 'error'] }],
'prefer-const': 'error',
'no-async-promise-executor': 'off',
// Prevent importing React as default
'no-restricted-imports': [
'error',
{
name: 'react',
importNames: ['default'],
message: 'Do not import default React. Use named imports instead.',
},
],
// Enforce type imports to always use the `type` keyword
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
disallowTypeAnnotations: false,
},
],
// Enforce brackets after if statements
curly: ['error', 'all'],
// Prefer early returns instead of else statements
'no-else-return': ['error', { allowElseIf: false }],
'@typescript-eslint/naming-convention': [
'error',
// Enforce camelCase for variables (const, let)
{
selector: 'variable',
format: ['camelCase'],
leadingUnderscore: 'allow', // Allow _unused variables
},
// Allow PascalCase for React components
{
selector: 'variable',
modifiers: ['const'],
format: ['camelCase', 'PascalCase'],
filter: {
// Allow React components (functions that return JSX)
regex: '^[A-Z]',
match: true,
},
},
// Enforce PascalCase for types, interfaces, classes
{
selector: 'typeLike',
format: ['PascalCase'],
},
// Enforce camelCase for functions
{
selector: 'function',
format: ['camelCase', 'PascalCase'], // PascalCase for React components
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'func-style': ['error', 'expression', { allowArrowFunctions: true }],
'max-depth': ['warn', 4],
'no-restricted-syntax': [
'error',
{
selector: "ExpressionStatement > Literal[value='use client']",
message: "'use client' is not needed in Vite — remove it.",
},
{
selector: "MemberExpression[object.name='React']",
message:
"React namespace access is not allowed. Use direct imports instead (e.g. import { type ReactNode } from 'react').",
},
{
selector: "TSQualifiedName[left.name='React']",
message:
"React namespace access in types is not allowed. Use direct imports instead (e.g. import { type ReactNode } from 'react').",
},
],
},
},
...storybook.configs['flat/recommended'],
]