-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
204 lines (190 loc) · 7.12 KB
/
Copy patheslint.config.mjs
File metadata and controls
204 lines (190 loc) · 7.12 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
import { includeIgnoreFile } from '@eslint/compat'
import dhis2ReactConfig from '@dhis2/config-eslint/react'
import { defineConfig, globalIgnores } from 'eslint/config'
import { fileURLToPath } from 'node:url'
import testingLibrary from 'eslint-plugin-testing-library'
const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url))
const baseAppRuntimeHooksRestriction = {
importNames: ['useDataQuery', 'useDataMutation', 'useDataEngine'],
message: "Use 'useRtkQuery' and 'useRtkMutation' from 'src/hooks' instead.",
}
export default defineConfig([
includeIgnoreFile(gitignorePath),
{ extends: [dhis2ReactConfig] },
globalIgnores(['.vite/**/*', 'scripts/**/*', '.claude/**']),
// TypeScript-specific custom rules (scoped to files the base config processes)
{
files: ['src/**/*.{ts,mts,cts,tsx}'],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
},
},
// Project-wide custom rules
{
rules: {
// Disable import/named — it produces false positives with path aliases
// and packages like @dhis2/ui since the TS resolver is not configured.
// TypeScript itself catches these errors.
'import/named': 'off',
// Disable React Compiler rules from react-hooks v7 — too
// aggressive for the current codebase.
'react-hooks/immutability': 'off',
'react-hooks/preserve-manual-memoization': 'off',
'react-hooks/use-memo': 'off',
'react-hooks/globals': 'off',
'import/no-default-export': 'error',
'no-console': 'error',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: [
'**/types/dhis2-openapi-schemas',
'**/types/dhis2-openapi-schemas/*',
],
message:
"Import DHIS2 Core schema-types from '@types' instead of directly from generated files.",
},
{
group: ['../*'],
message:
"Relative parent imports are not allowed. Use path aliases (e.g. '@hooks', '@components') instead.",
},
],
paths: [
{
name: '@dhis2/app-runtime',
...baseAppRuntimeHooksRestriction,
},
{
name: '@dhis2/app-service-data',
...baseAppRuntimeHooksRestriction,
},
{
name: 'react-redux',
importNames: [
'useDispatch',
'useSelector',
'useStore',
],
message:
"Use 'useAppDispatch', 'useAppSelector', and 'useAppStore' from 'src/hooks' instead for proper typing.",
},
],
},
],
},
},
// Override: config files and src/locales/index.js need default exports
{
files: ['src/locales/index.js', '*.config.*', '.prettierrc.*'],
rules: {
'import/order': 'off',
'import/no-default-export': 'off',
},
},
// Override: test directories -- allow one level of parent imports
{
files: ['**/__tests__/**/*.{js,jsx,ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['../../*'],
message:
'In __tests__ directories, you may only import from one parent level (../filename). Deeper parent imports are not allowed.',
},
],
},
],
},
},
// Override: generated schema types
{
files: ['src/types/dhis2-openapi-schemas/**/*'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
},
},
// Override: types/index.ts
{
files: ['src/types/index.ts'],
rules: {
'no-restricted-imports': 'off',
},
},
// Override: vitest spec files — apply testing-library/react preset to
// catch missing-await on async utils (`waitFor`, `findBy*`, etc.) and
// other React Testing Library footguns. Scoped to Vitest specs only;
// Cypress component tests use a different auto-retrying query API and
// would produce false positives under these rules.
{
files: ['src/**/*.spec.{ts,tsx}'],
extends: [testingLibrary.configs['flat/react']],
rules: {
// Disabled so we can access DHIS2-UI internals by className etc.
'testing-library/no-node-access': 'off',
'no-restricted-globals': [
'error',
{
name: 'describe',
message:
"Import describe from 'vitest' instead of using the global.",
},
{
name: 'it',
message:
"Import it from 'vitest' instead of using the global.",
},
{
name: 'test',
message:
"Import test from 'vitest' instead of using the global.",
},
{
name: 'expect',
message:
"Import expect from 'vitest' instead of using the global.",
},
{
name: 'beforeEach',
message:
"Import beforeEach from 'vitest' instead of using the global.",
},
{
name: 'afterEach',
message:
"Import afterEach from 'vitest' instead of using the global.",
},
{
name: 'beforeAll',
message:
"Import beforeAll from 'vitest' instead of using the global.",
},
{
name: 'afterAll',
message:
"Import afterAll from 'vitest' instead of using the global.",
},
],
},
},
// Override: Cypress component test files
{
files: ['src/**/*.cy.tsx'],
rules: {
'react/prop-types': 'off',
},
},
// Override: all Cypress files
{
files: ['**/*.cy.ts', '**/*.cy.tsx'],
rules: {
'no-restricted-imports': 'off',
},
},
])