forked from equinor/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
267 lines (249 loc) · 7.2 KB
/
Copy patheslint.config.mjs
File metadata and controls
267 lines (249 loc) · 7.2 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
import js from '@eslint/js'
import babelParser from '@babel/eslint-parser'
import tseslint from 'typescript-eslint'
import react from 'eslint-plugin-react'
import reactHooks from 'eslint-plugin-react-hooks'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import importPlugin from 'eslint-plugin-import'
import prettierPlugin from 'eslint-plugin-prettier/recommended'
import testingLibrary from 'eslint-plugin-testing-library'
import storybook from 'eslint-plugin-storybook'
import globals from 'globals'
export default tseslint.config(
// Global ignores (replaces .eslintignore)
{
ignores: [
'**/node_modules/**',
'**/dist/**',
'packages/eds-tokens/build/**',
'packages/eds-tokens/build-generate-variables/**',
'apps/eds-color-palette-generator/**',
'storybook-build/**',
'**/next-env.d.ts',
'.eslintcache',
'node_modules/.cache/**',
'**/build/**',
'**/coverage/**',
'**/.next/**',
'**/playwright-report/**',
'**/test-results/**',
'**/.turbo/**',
],
},
// Base config for all JS/TS files
js.configs.recommended,
// Base JS config (non-TS files)
{
files: ['**/*.{js,jsx,mjs,cjs}'],
languageOptions: {
parser: babelParser,
parserOptions: {
requireConfigFile: false,
sourceType: 'module',
},
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
},
},
plugins: {
import: importPlugin,
},
rules: {
'no-underscore-dangle': 'off',
'no-use-before-define': 'off',
'import/no-unresolved': 'warn',
},
},
// TypeScript files
...tseslint.configs.recommendedTypeChecked.map((config) => ({
...config,
files: ['**/*.{ts,tsx}'],
})),
{
files: ['**/*.{ts,tsx}'],
...react.configs.flat.recommended,
languageOptions: {
...react.configs.flat.recommended.languageOptions,
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2019,
project: [
'./tsconfig.eslint.json',
'./scripts/*/tsconfig.json',
'./packages/*/tsconfig.json',
'./packages/*/*/tsconfig.json',
],
tsconfigRootDir: import.meta.dirname,
},
globals: {
...globals.browser,
...globals.node,
...globals.es2021,
test: true,
expect: true,
},
},
plugins: {
...react.configs.flat.recommended.plugins,
'react-hooks': reactHooks,
'jsx-a11y': jsxA11y,
import: importPlugin,
},
settings: {
react: {
version: 'detect',
},
'import/parsers': {
'@typescript-eslint/parser': ['*.ts', '*.tsx'],
},
'import/resolver': {
typescript: {
project: [
'./packages/*/tsconfig.json',
'./packages/*/*/tsconfig.json',
],
},
},
},
rules: {
// React recommended rules (display-name, jsx-key, no-deprecated, etc.)
...react.configs.flat.recommended.rules,
// Prettier
'prettier/prettier': 'error',
// General
'no-underscore-dangle': 'off',
'no-use-before-define': 'off',
// React
'react/prop-types': 'off',
'react/require-default-props': [
'off',
{ forbidDefaultForRequired: true, functions: 'defaultArguments' },
],
'react/react-in-jsx-scope': 'off',
'react/jsx-pascal-case': 'error',
'react/prefer-stateless-function': 'error',
'react/no-unused-prop-types': 'error',
'react/no-array-index-key': 'error',
'react/no-typos': 'error',
'react/destructuring-assignment': ['error', 'always'],
// React Hooks (v7 — disable React 19-specific rules for React 18 compat)
...reactHooks.configs.recommended.rules,
'react-hooks/refs': 'off',
'react-hooks/set-state-in-effect': 'off',
'react-hooks/immutability': 'off',
'react-hooks/static-components': 'off',
'react-hooks/incompatible-library': 'off',
// Import
'import/default': 'off',
'import/no-default-export': 'error',
'import/newline-after-import': 'error',
'import/prefer-default-export': 'off',
'import/no-named-as-default': 'off',
'import/namespace': ['error', { allowComputed: true }],
// TypeScript
'no-unused-vars': 'off',
'@typescript-eslint/no-empty-object-type': [
'error',
{ allowInterfaces: 'with-single-extends' },
],
'@typescript-eslint/no-unsafe-return': 'warn',
'@typescript-eslint/no-unsafe-assignment': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
// TODO: re-enable and clean up existing violations — see issue #4827
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-misused-promises': [
'error',
{ checksVoidReturn: false },
],
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
enforceForJSX: true,
allowTernary: true,
},
],
// jsx-a11y
...jsxA11y.flatConfigs.recommended.rules,
'jsx-a11y/label-has-associated-control': [
'warn',
{
labelComponents: [],
labelAttributes: [],
controlComponents: [],
assert: 'either',
depth: 25,
},
],
},
},
// Test files
{
files: ['**/*.test.ts', '**/*.test.tsx'],
...testingLibrary.configs['flat/react'],
rules: {
...testingLibrary.configs['flat/react'].rules,
'testing-library/no-await-sync-events': [
'error',
{ eventModules: ['fire-event'] },
],
},
},
// Storybook stories
...storybook.configs['flat/recommended'],
{
files: ['**/*.stories.ts', '**/*.stories.tsx'],
rules: {
'import/no-default-export': 'off',
},
},
// Config files that require default exports (Playwright, Vite, etc.)
{
files: [
'**/playwright.config.ts',
'**/vite.config.ts',
'**/vite.*.config.ts',
'**/vitest.config.ts',
],
rules: {
'import/no-default-export': 'off',
},
},
// Next.js pages/layouts
{
files: [
'**/app/**/page.tsx',
'**/app/**/layout.tsx',
'**/tailwind.config.ts',
],
rules: {
'import/no-default-export': 'off',
},
},
// Docusaurus docs app
{
files: ['apps/design-system-docs/**/*.{js,jsx,ts,tsx}'],
rules: {
'import/no-unresolved': [
2,
{ ignore: ['^@theme', '^@docusaurus', '^@site'] },
],
'import/no-default-export': 'off',
// The docs app isn't part of tsconfig.eslint.json's project graph, so
// typescript-eslint can't resolve React types here. Downgrade these
// type-aware rules to warn — matches how no-unsafe-return / -assignment
// / -argument are handled globally above.
'@typescript-eslint/no-unsafe-call': 'warn',
'@typescript-eslint/no-unsafe-member-access': 'warn',
},
},
// Storybook config files (not in any tsconfig — disable type-checked rules)
{
files: ['**/.storybook/**/*.{ts,tsx}'],
...tseslint.configs.disableTypeChecked,
},
// Prettier must be last to override conflicting rules
prettierPlugin,
)