-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
eslint.config.mjs
409 lines (383 loc) · 12.1 KB
/
eslint.config.mjs
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Eslint v9.0 and above plugins
import tsEslint from 'typescript-eslint';
import jsEslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import panda from '@pandacss/eslint-plugin';
import pluginCypress from 'eslint-plugin-cypress/flat';
import localRules from 'eslint-plugin-local-rules';
// Eslint v8.0 and below plugins
import reactHooks from 'eslint-plugin-react-hooks';
import promise from 'eslint-plugin-promise';
import unusedImports from 'eslint-plugin-unused-imports';
import deprecation from 'eslint-plugin-deprecation';
/**
* Eslint v8 compatibility packages
*
* This file was migrated from eslintrc.js to eslint.config.mjs using the following command:
* `npx @eslint/migrate-config .eslintrc.js`
*
* After better compatibility for Eslint Flat Config is present in the Eslint plugin
* ecosystem, we should remove `@eslint/compat` and the `fixupConfigRules` and
* `fixupPluginRules` functions.
*
* @see https://github.com/eslint/eslint/issues/18010
*/
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
const compat = new FlatCompat({ baseDirectory: import.meta.dirname });
/**
* REUSED RULE CONFIGURATIONS
*
* This is necessary because Eslint doesn't merge rule configurations
* when they are targeting different paths.
*/
/**
* This rule ensures that "multi-level" imports are not used for `@novu/*` packages.
*/
const noRestrictedImportsMultiLevelNovuPattern = {
group: [
'@novu/*/**/*',
'!@novu/api/**/*', // This allows all imports from @novu/api
// These packages have legitimate exports 1 path part below the root level
// This flatMap logic ignores the path 1 below the root level and prevents deeper imports.
...['framework', 'js', 'novui'].flatMap((pkg) => [`!@novu/${pkg}/**/*`, `@novu/${pkg}/*/**/*`]),
],
message:
"Please import only from the root package entry point. For example, use 'import { Client } from '@novu/node';' instead of 'import { Client } from '@novu/node/src';'",
};
export default tsEslint.config(
/* ******************** RECOMMENDED CONFIG ******************** */
jsEslint.configs.recommended,
...fixupConfigRules(
compat.extends(
/**
* Airbnb is still migrating to Eslint v9.0
*
* @see https://github.com/iamturns/eslint-config-airbnb-typescript/issues/331
*/
'airbnb-base',
'airbnb-typescript'
)
),
eslintPluginPrettierRecommended, // KEEP PRETTIER CONFIG LAST TO AVOID CONFLICTS
/* ******************** IGNORES ******************** */
{
ignores: [
'**/dist/**',
'**/build/**',
'**/node_modules/**',
'**/playwright-report/**',
'**/styled-system/**',
'**/coverage/**',
'**/.next/**',
'**/.storybook/**',
'**/.nx/**',
'**/config-overrides.js',
'**/env-config.js',
'**/*.config.{js,cjs,mjs}',
'**/iframeResizer.contentWindow.js',
'**/size-limit.mjs',
'**/eslint-local-rules.js',
'**/get-packages-folder.mjs',
'**/scripts/**',
'**/jest.setup.js',
'**/check-ee.mjs',
'**/libs/embed/src/shared/**',
'**/*.stories.*',
'**/notifications-cache.test.ts',
'**/novu.test.ts',
'**/swagger.controller.ts',
],
},
/* ******************** TYPESCRIPT FILES ******************** */
{
plugins: {
promise: fixupPluginRules(promise),
},
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
rules: {
'unused-imports/no-unused-imports': 'off',
'@typescript-eslint/space-before-blocks': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'error',
'react/jsx-wrap-multilines': 'off',
'react/jsx-filename-extension': 'off',
'multiline-comment-style': ['warn', 'starred-block'],
'promise/catch-or-return': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'react/jsx-closing-bracket-location': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': ['off'],
'mocha/no-mocha-arrows': 'off',
'@typescript-eslint/default-param-last': 'off',
'no-return-await': 'off',
'no-await-in-loop': 'off',
'no-continue': 'off',
'no-console': 'warn',
'no-prototype-builtins': 'off',
'import/no-cycle': 'off',
'class-methods-use-this': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 1,
'no-restricted-syntax': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'no-underscore-dangle': 'off',
'import/prefer-default-export': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-namespace': 'error',
'react/jsx-one-expression-per-line': 'off',
'react/jsx-no-bind': 'off',
'lines-between-class-members': 'off',
'max-classes-per-file': 'off',
'react/react-in-jsx-scope': 'off',
'no-else-return': 'off',
'import/export': 'off',
'consistent-return': 'off',
'no-param-reassign': [
'error',
{
props: true,
ignorePropertyModificationsFor: ['prev', 'acc'], // ignore for Array.reduce
},
],
'max-len': [
'warn',
{
code: 140,
},
],
'@typescript-eslint/return-await': 'off',
'@typescript-eslint/no-base-to-string': 'error',
'no-restricted-imports': [
'error',
{
patterns: [noRestrictedImportsMultiLevelNovuPattern],
},
],
'padding-line-between-statements': [
'error',
{
blankLine: 'any',
prev: ['const', 'let', 'var'],
next: ['if', 'for'],
},
{
blankLine: 'any',
prev: ['const', 'let', 'var'],
next: ['const', 'let', 'var'],
},
{
blankLine: 'always',
prev: '*',
next: 'return',
},
],
'id-length': [
'error',
{
min: 2,
exceptions: ['i', 'e', 'a', 'b', '_', 't'],
properties: 'never',
},
],
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'enumMember',
format: ['UPPER_CASE'],
},
{
selector: 'enum',
format: ['PascalCase'],
suffix: ['Enum'],
},
{
selector: 'class',
format: ['PascalCase'],
},
{
selector: 'variableLike',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: 'interface',
format: ['PascalCase'],
prefix: ['I'],
},
{
selector: ['function'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
],
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
},
/* ******************** JAVASCRIPT FILES ******************** */
{
files: ['**/*.{js,jsx,cjs,mjs}'],
...tsEslint.configs.disableTypeChecked,
},
/* ******************** MONOREPO PACKAGES ******************** */
{
files: ['packages/framework/**'],
plugins: {
'unused-imports': fixupPluginRules(unusedImports),
},
rules: {
'max-len': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'import/prefer-default-export': 0,
'sonarjs/prefer-immediate-return': 0,
'const-case/uppercase': 0,
'unicorn/no-array-reduce': 0,
'unused-imports/no-unused-imports': 'error',
},
},
{
files: ['packages/providers/**'],
plugins: {
deprecation: fixupPluginRules(deprecation),
},
rules: {
'deprecation/deprecation': 'error',
},
},
{
files: ['apps/api/**'],
rules: {
'func-names': 'off',
'no-restricted-imports': [
'error',
{
patterns: [
noRestrictedImportsMultiLevelNovuPattern,
{
/**
* This rule ensures that the overridden Swagger decorators are used,
* which apply common responses to all API endpoints.
*/
group: ['@nestjs/swagger'],
importNames: [
'ApiOkResponse',
'ApiCreatedResponse',
'ApiAcceptedResponse',
'ApiNoContentResponse',
'ApiMovedPermanentlyResponse',
'ApiFoundResponse',
'ApiBadRequestResponse',
'ApiUnauthorizedResponse',
'ApiTooManyRequestsResponse',
'ApiNotFoundResponse',
'ApiInternalServerErrorResponse',
'ApiBadGatewayResponse',
'ApiConflictResponse',
'ApiForbiddenResponse',
'ApiGatewayTimeoutResponse',
'ApiGoneResponse',
'ApiMethodNotAllowedResponse',
'ApiNotAcceptableResponse',
'ApiNotImplementedResponse',
'ApiPreconditionFailedResponse',
'ApiPayloadTooLargeResponse',
'ApiRequestTimeoutResponse',
'ApiServiceUnavailableResponse',
'ApiUnprocessableEntityResponse',
'ApiUnsupportedMediaTypeResponse',
'ApiDefaultResponse',
],
message: "Use 'Api<Error>Response' from '/shared/framework/response.decorator' instead.",
},
],
},
],
},
},
/* ******************** WEB PACKAGES ******************** */
{
files: [
'libs/design-system/**',
'libs/novui/**',
'apps/widget/**',
'apps/web/**',
'packages/notification-center/**',
],
extends: [pluginCypress.configs.recommended],
plugins: {
'@pandacss': panda,
'react-hooks': fixupPluginRules(reactHooks),
},
rules: {
...panda.configs.recommended.rules,
'func-names': 'off',
'react/jsx-props-no-spreading': 'off',
'react/no-array-index-key': 'off',
'no-empty-pattern': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'react/no-unescaped-entities': 'off',
'react/jsx-closing-bracket-location': 'off',
'@typescript-eslint/ban-types': 'off',
'react/jsx-wrap-multilines': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'promise/catch-or-return': 'off',
'react/jsx-one-expression-per-line': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'jsx-a11y/aria-role': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'react/require-default-props': 'off',
'react/no-danger': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'@typescript-eslint/naming-convention': [
'error',
{
filter: '_',
selector: 'variableLike',
leadingUnderscore: 'allow',
format: ['PascalCase', 'camelCase', 'UPPER_CASE'],
},
],
'@pandacss/no-config-function-in-source': 'off',
},
},
/* ******************** INBOX PACKAGES ******************** */
{
files: ['packages/js/**', 'packages/react/**'],
plugins: {
'local-rules': localRules,
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
filter: '_',
selector: 'variableLike',
leadingUnderscore: 'allow',
format: ['PascalCase', 'camelCase', 'UPPER_CASE'],
},
],
'local-rules/no-class-without-style': 'error',
'id-length': 'off',
'@typescript-eslint/no-shadow': 'off',
},
}
);