forked from frontend-collective/react-sortable-tree
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy patheslint.config.mjs
More file actions
262 lines (248 loc) · 6.88 KB
/
eslint.config.mjs
File metadata and controls
262 lines (248 loc) · 6.88 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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import globals from 'globals';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
// Plugins
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
import importPlugin from 'eslint-plugin-import';
import promisePlugin from 'eslint-plugin-promise';
import unicornPlugin from 'eslint-plugin-unicorn';
import sonarjsPlugin from 'eslint-plugin-sonarjs';
import storybookPlugin from 'eslint-plugin-storybook';
import prettierPlugin from 'eslint-plugin-prettier';
import prettierConfig from 'eslint-config-prettier';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default defineConfig(
// Global Ignores
{
ignores: [
'**/node_modules/**',
'**/dist/**',
'**/lib/**',
'**/build/**',
'**/coverage/**',
'**/storybook-static/**',
'**/*.d.ts',
],
},
// Base Configuration (JS & TS) - source files only (covered by tsconfig.json)
{
extends: [
js.configs.recommended,
...tseslint.configs.recommended,
// ...tseslint.configs.recommendedTypeChecked, // Uncomment if you want strict type-aware rules
],
files: ['src/**/*.{ts,tsx}'],
ignores: ['src/stories/**'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
},
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
plugins: {
'import': importPlugin,
'promise': promisePlugin,
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
node: true,
},
},
rules: {
// Import Rules
'import/no-unresolved': 'error',
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
],
'newlines-between': 'never',
alphabetize: { order: 'asc', caseInsensitive: true },
},
],
// Common Overrides
'no-console': ['warn', { allow: ['warn', 'error'] }],
'no-underscore-dangle': 'off',
'no-nested-ternary': 'off',
'no-plusplus': 'off',
// Allow _-prefixed variables as intentionally unused markers
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
},
// Stories files - use default project (no tsconfig coverage needed)
{
extends: [
js.configs.recommended,
...tseslint.configs.recommended,
],
files: ['src/stories/**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
},
parserOptions: {
project: null,
},
},
plugins: {
'import': importPlugin,
'promise': promisePlugin,
},
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
node: true,
},
},
rules: {
'import/no-unresolved': 'error',
'no-console': 'off',
'no-underscore-dangle': 'off',
'no-nested-ternary': 'off',
'no-plusplus': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
// Relax strict rules for demo/story code
'@typescript-eslint/no-explicit-any': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/prefer-spread': 'off',
'sonarjs/pseudo-random': 'off',
'sonarjs/cognitive-complexity': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
},
},
// Config and other JS/MJS files (not covered by tsconfig)
{
extends: [
js.configs.recommended,
],
files: ['*.{js,mjs,cjs}'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: {
...globals.node,
...globals.es2021,
},
},
},
// React Specifics
{
files: ['**/*.{jsx,tsx}'],
extends: [
reactPlugin.configs.flat.recommended,
reactPlugin.configs.flat['jsx-runtime'], // React 17+
reactHooksPlugin.configs.flat['recommended-latest'],
jsxA11yPlugin.flatConfigs.recommended,
],
settings: {
react: { version: 'detect' },
},
rules: {
// React Rules Overrides
'react/prop-types': 'off', // Not needed with TypeScript
'react/require-default-props': 'off',
'react/jsx-props-no-spreading': 'off',
'react/no-unstable-nested-components': ['warn', { allowAsProps: true }],
'react/function-component-definition': [
'warn',
{
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function',
},
],
'react/jsx-filename-extension': ['warn', { extensions: ['.tsx', '.jsx'] }],
},
},
// SonarJS & Unicorn (Code Quality)
{
files: ['**/*.{js,jsx,ts,tsx}'],
extends: [
sonarjsPlugin.configs.recommended,
unicornPlugin.configs['flat/recommended'],
],
rules: {
// Relax some Unicorn rules that can be annoying
'unicorn/prevent-abbreviations': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-null': 'off',
'unicorn/prefer-module': 'off',
'unicorn/no-useless-undefined': 'off',
},
},
// Relaxed rules for demo/story files (overrides stricter rules from block 4)
{
files: ['src/stories/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/prefer-spread': 'off',
'sonarjs/pseudo-random': 'off',
'sonarjs/cognitive-complexity': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'no-console': 'off',
'react/jsx-key': 'off',
},
},
// Storybook Specifics
...storybookPlugin.configs['flat/recommended'],
// Prettier (Must be last)
{
files: ['**/*.{js,jsx,ts,tsx}'],
plugins: {
prettier: prettierPlugin,
},
rules: {
...prettierConfig.rules, // Turns off conflicting ESLint rules
'prettier/prettier': 'error',
},
},
);