-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy patheslint.config.js
More file actions
266 lines (259 loc) · 7.86 KB
/
Copy patheslint.config.js
File metadata and controls
266 lines (259 loc) · 7.86 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
const js = require('@eslint/js');
const fecConfig = require('@redhat-cloud-services/eslint-config-redhat-cloud-services');
const { defineConfig } = require('eslint/config');
const prettierConfig = require('eslint-config-prettier');
const pluginImport = require('eslint-plugin-import');
const jestDom = require('eslint-plugin-jest-dom');
const pluginJsxA11y = require('eslint-plugin-jsx-a11y');
const pluginPlaywright = require('eslint-plugin-playwright');
const pluginReact = require('eslint-plugin-react');
const pluginReactHooks = require('eslint-plugin-react-hooks');
const pluginReactRedux = require('eslint-plugin-react-redux');
const pluginTestingLibrary = require('eslint-plugin-testing-library');
const globals = require('globals');
const tseslint = require('typescript-eslint');
module.exports = defineConfig([
{
// Ignore programatically generated files and build artifacts
ignores: [
// Build outputs
'dist/**',
'cockpit/public/**',
'.cache/**',
'playwright-report/**',
'pkg/**',
// Generated API code
'**/mockServiceWorker.js',
'**/imageBuilderApi.ts',
'**/hosted/contentSourcesApi.ts',
'**/rhsmApi.ts',
'**/complianceApi.ts',
'**/types/generated.ts',
],
},
{
// Base config for js/ts files
files: ['**/*.{js,ts,jsx,tsx}'],
languageOptions: {
parser: tseslint.parser,
globals: {
...globals.browser,
...globals.node,
JSX: 'readonly',
// vitest
describe: 'readonly',
it: 'readonly',
test: 'readonly',
expect: 'readonly',
vi: 'readonly',
beforeAll: 'readonly',
beforeEach: 'readonly',
afterAll: 'readonly',
afterEach: 'readonly',
},
},
plugins: {
js,
'@typescript-eslint': tseslint.plugin,
react: pluginReact,
'react-hooks': pluginReactHooks,
'react-redux': pluginReactRedux,
import: pluginImport,
'jsx-a11y': pluginJsxA11y,
},
rules: {
...js.configs.recommended.rules,
...tseslint.configs.recommended.rules,
...pluginReact.configs.flat.recommended.rules,
...pluginReactHooks.configs.recommended.rules,
...pluginReactRedux.configs.recommended.rules,
...pluginJsxA11y.configs.recommended.rules,
...fecConfig.rules,
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'sibling',
'parent',
'index',
],
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
'newlines-between': 'always',
pathGroups: [
// ensures the import of React is always on top
{
pattern: 'react',
group: 'builtin',
position: 'before',
},
{
pattern: '@/**',
group: 'internal',
position: 'before',
},
],
pathGroupsExcludedImportTypes: ['react'],
},
],
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
},
],
'no-duplicate-imports': 'error',
// NOTE: we can enable this after the revamp and after summit. We can live with
// the mixture of alias imports and relative imports. We can then enable the warning
// or maybe errors (after summit). We can slowly migrate during the revamp, but adding
// warnings now adds too much noise.
// 'no-restricted-imports': ['warn', {
// patterns: [{
// group: ['../../*'],
// message: 'Avoid deep relative imports (../../ or deeper). Use @/ alias instead.',
// }],
// }],
'no-restricted-imports': [
'error',
{
patterns: [
{
group: [
'@/store/slices/wizard/cloud/*',
'@/store/slices/wizard/compliance/*',
'@/store/slices/wizard/content/*',
'@/store/slices/wizard/details/*',
'@/store/slices/wizard/filesystem/*.ts',
'@/store/slices/wizard/output/*',
'@/store/slices/wizard/registration/*',
'@/store/slices/wizard/system/*',
],
message:
'Import from @/store/slices/wizard instead. Direct imports into slice internals bypass the barrel and fragment createSelector memoization caches.',
},
],
},
],
'prefer-const': [
'error',
{
destructuring: 'any',
},
],
'no-console': 'error',
eqeqeq: 'error',
'array-callback-return': 'warn',
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': true,
'ts-check': true,
minimumDescriptionLength: 5,
},
],
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unsafe-function-type': 'error',
'no-unused-vars': 'off', // disable js rule in favor of @typescript-eslint's rule
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'react-hooks/set-state-in-effect': 'warn', // TODO address issues and enable the rule
'no-restricted-syntax': [
'error',
{
selector: "ImportSpecifier[imported.name='useAppStore']",
message:
'useAppStore exposes the raw store — only use it for store.getState() inside event handlers, never during render. Add an eslint-disable with justification if this usage is intentional.',
},
],
},
settings: {
react: {
version: 'detect', // Automatically detect React version
},
},
},
{
// TypeScript parser with project for source files only
files: ['src/**/*.{js,ts,jsx,tsx}', 'playwright/**/*.ts'],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: [
'./tsconfig.json',
'./tsconfig.vitest.json',
'./playwright/tsconfig.json',
],
},
},
rules: {
// Type-aware rules that require parserOptions.project
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-condition': 'error',
},
},
{
// Override for test files (legacy integration tests + co-located unit tests)
files: [
'src/test/**/*.{ts,tsx}',
'**/*.test.{ts,tsx}',
'**/tests/**/*.{ts,tsx}',
],
plugins: {
'jest-dom': jestDom,
'testing-library': pluginTestingLibrary,
},
rules: {
...jestDom.configs.recommended.rules,
...pluginTestingLibrary.configs.react.rules,
'react/display-name': 'off',
'react/prop-types': 'off',
'testing-library/no-debugging-utils': 'error',
},
},
{
// Override for Playwright tests
files: ['playwright/**/*.ts'],
plugins: {
playwright: pluginPlaywright,
},
rules: {
...pluginPlaywright.configs.recommended.rules,
'playwright/no-conditional-in-test': 'off',
'playwright/no-conditional-expect': 'off',
'playwright/no-skipped-test': [
'error',
{
allowConditional: true,
},
],
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-floating-promises': 'error',
},
},
{
files: [
'playwright/BootTests/helpers/OpenStackWrapper.ts',
'playwright/BootTests/helpers/imageBuilding.ts',
],
rules: {
'no-console': 'off',
},
},
prettierConfig,
]);