-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
eslint.config.mjs
843 lines (728 loc) · 28.5 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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
// @ts-check
/**
* Understanding & making changes to this file:
*
* This is your friend:
* `npx eslint --inspect-config`
*/
import * as emotion from '@emotion/eslint-plugin';
import prettier from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import jest from 'eslint-plugin-jest';
import jestDom from 'eslint-plugin-jest-dom';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import sentry from 'eslint-plugin-sentry';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import testingLibrary from 'eslint-plugin-testing-library';
import typescriptSortKeys from 'eslint-plugin-typescript-sort-keys';
import globals from 'globals';
import invariant from 'invariant';
// biome-ignore lint/correctness/noNodejsModules: Need to get the list of things!
import {builtinModules} from 'node:module';
import typescript from 'typescript-eslint';
invariant(react.configs.flat, 'For typescript');
const restrictedImportPatterns = [
{
group: ['sentry/components/devtoolbar/*'],
message: 'Do not depend on toolbar internals',
},
];
const restrictedImportPaths = [
{
name: '@testing-library/react',
message:
'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
},
{
name: '@testing-library/react-hooks',
message:
'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
},
{
name: '@testing-library/user-event',
message:
'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
},
{
name: '@sentry/browser',
message:
'Please import from `@sentry/react` to ensure consistency throughout the codebase.',
},
{
name: 'marked',
message:
"Please import marked from 'app/utils/marked' so that we can ensure sanitation of marked output",
},
{
name: 'lodash',
message:
"Please import lodash utilities individually. e.g. `import isEqual from 'lodash/isEqual';`. See https://github.com/getsentry/frontend-handbook#lodash from for information",
},
{
name: 'lodash/get',
message:
'Optional chaining `?.` and nullish coalescing operators `??` are available and preferred over using `lodash/get`. See https://github.com/getsentry/frontend-handbook#new-syntax for more information',
},
{
name: 'sentry/utils/theme',
importNames: ['lightColors', 'darkColors'],
message:
"'lightColors' and 'darkColors' exports intended for use in Storybook only. Instead, use theme prop from emotion or the useTheme hook.",
},
{
name: 'react-router',
importNames: ['withRouter'],
message:
"Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
},
{
name: 'sentry/utils/withSentryRouter',
message:
"Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
},
{
name: 'qs',
message: 'Please use query-string instead of qs',
},
{
name: 'moment',
message: 'Please import moment-timezone instead of moment',
},
];
// Used by both: `languageOptions` & `parserOptions`
const ecmaVersion = 6; // TODO(ryan953): change to 'latest'
/**
* To get started with this ESLint Configuration list be sure to read at least
* these sections of the docs:
* - https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
* - https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects
*/
export default typescript.config([
{
// Main parser & linter options
// Rules are defined below and inherit these properties
// https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects
name: 'eslint/global/languageOptions',
languageOptions: {
ecmaVersion,
sourceType: 'module',
globals: {
// TODO(ryan953): globals.browser seems to have a bug with trailing whitespace
...Object.fromEntries(
Object.keys(globals.browser).map(key => [key.trim(), false])
),
...globals.jest,
MockApiClient: true,
tick: true,
},
parser: typescript.parser,
parserOptions: {
ecmaFeatures: {
globalReturn: false,
},
ecmaVersion,
// https://typescript-eslint.io/packages/parser/#emitdecoratormetadata
emitDecoratorMetadata: undefined,
// https://typescript-eslint.io/packages/parser/#experimentaldecorators
experimentalDecorators: undefined,
// https://typescript-eslint.io/packages/parser/#jsdocparsingmode
jsDocParsingMode: process.env.SENTRY_DETECT_DEPRECATIONS ? 'all' : 'none',
// https://typescript-eslint.io/packages/parser/#project
project: process.env.SENTRY_DETECT_DEPRECATIONS ? './tsconfig.json' : false,
// https://typescript-eslint.io/packages/parser/#projectservice
// `projectService` is recommended, but slower, with our current tsconfig files.
// projectService: true,
// tsconfigRootDir: import.meta.dirname,
},
},
linterOptions: {
noInlineConfig: false,
reportUnusedDisableDirectives: 'error',
},
settings: {
react: {
version: '18.2.0',
defaultVersion: '18.2',
},
'import/parsers': {'@typescript-eslint/parser': ['.ts', '.tsx']},
'import/resolver': {typescript: {}},
'import/extensions': ['.js', '.jsx'],
},
},
{
name: 'eslint/global/files',
// Default file selection
// https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
files: ['**/*.js', '**/*.mjs', '**/*.ts', '**/*.jsx', '**/*.tsx'],
},
{
name: 'eslint/global/ignores',
// Global ignores
// https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
ignores: [
'.devenv/**/*',
'.github/**/*',
'.mypy_cache/**/*',
'.pytest_cache/**/*',
'.venv/**/*',
'**/*.benchmark.ts',
'**/*.d.ts',
'**/dist/**/*',
'**/tests/**/fixtures/**/*',
'**/vendor/**/*',
'build-utils/**/*',
'config/chartcuterie/config.js', // TODO: see if this file exists
'fixtures/artifact_bundle/**/*',
'fixtures/artifact_bundle_debug_ids/**/*',
'fixtures/artifact_bundle_duplicated_debug_ids/**/*',
'fixtures/profiles/embedded.js',
'jest.config.ts',
'api-docs/**/*',
'src/sentry/static/sentry/js/**/*',
'src/sentry/templates/sentry/**/*',
'stylelint.config.js',
],
},
/**
* Global Rules
* Any ruleset that does not include `files` or `ignores` fields
*
* Plugins are configured within each configuration object.
* https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects
*
* Rules are grouped by plugin. If you want to override a specific rule inside
* the recommended set, then it's recommended to spread the new rule on top
* of the predefined ones.
*
* For example: if you want to enable a new plugin in the codebase and their
* recommended rules (or a new rule that's part of an existing plugin)
* First you'd setup a configuration object for that plugin:
* {
* name: 'my-plugin/recommended',
* ...myPlugin.configs.recommended,
* },
* Second you'd override the rule you want to deal with, maybe making it a
* warning to start:
* {
* name: 'my-plugin/recommended',
* ...myPlugin.configs.recommended,
* rules: {
* ...myPlugin.configs.recommended.rules,
* ['the-rule']: 'warn',
* }
* },
* Finally, once all warnings are fixed, update from 'warning' to 'error', or
* remove the override and rely on the recommended rules again.
*/
{
name: 'eslint/rules',
rules: {
// https://eslint.org/docs/rules/strict
strict: ['error', 'global'],
/**
* Variables
*/
// https://eslint.org/docs/rules/no-shadow-restricted-names
'no-shadow-restricted-names': 'error',
/**
* Possible errors
*/
// https://eslint.org/docs/rules/no-cond-assign
'no-cond-assign': ['error', 'always'],
// https://eslint.org/docs/rules/no-alert
'no-alert': 'error',
// https://eslint.org/docs/rules/no-constant-condition
'no-constant-condition': 'warn',
// https://eslint.org/docs/rules/no-empty
'no-empty': 'error',
// https://eslint.org/docs/rules/no-ex-assign
'no-ex-assign': 'error',
// https://eslint.org/docs/rules/no-extra-boolean-cast
'no-extra-boolean-cast': 'error',
// https://eslint.org/docs/rules/no-func-assign
'no-func-assign': 'error',
// https://eslint.org/docs/rules/no-inner-declarations
'no-inner-declarations': 'error',
// https://eslint.org/docs/rules/no-invalid-regexp
'no-invalid-regexp': 'error',
// https://eslint.org/docs/rules/no-irregular-whitespace
'no-irregular-whitespace': 'error',
// https://eslint.org/docs/rules/no-obj-calls
'no-obj-calls': 'error',
// https://eslint.org/docs/rules/no-sparse-arrays
'no-sparse-arrays': 'error',
// https://eslint.org/docs/rules/block-scoped-var
'block-scoped-var': 'error',
/**
* Best practices
*/
// https://eslint.org/docs/rules/consistent-return
'consistent-return': 'error',
// https://eslint.org/docs/rules/default-case
'default-case': 'error',
// https://eslint.org/docs/rules/dot-notation
'dot-notation': ['error', {allowKeywords: true}],
// https://eslint.org/docs/rules/guard-for-in [REVISIT ME]
'guard-for-in': 'off',
// https://eslint.org/docs/rules/no-caller
'no-caller': 'error',
// https://eslint.org/docs/rules/no-eval
'no-eval': 'error',
// https://eslint.org/docs/rules/no-extend-native
'no-extend-native': 'error',
// https://eslint.org/docs/rules/no-extra-bind
'no-extra-bind': 'error',
// https://eslint.org/docs/rules/no-fallthrough
'no-fallthrough': 'error',
// https://eslint.org/docs/rules/no-floating-decimal
'no-floating-decimal': 'error',
// https://eslint.org/docs/rules/no-implied-eval
'no-implied-eval': 'error',
// https://eslint.org/docs/rules/no-lone-blocks
'no-lone-blocks': 'error',
// https://eslint.org/docs/rules/no-loop-func
'no-loop-func': 'error',
// https://eslint.org/docs/rules/no-multi-str
'no-multi-str': 'error',
// https://eslint.org/docs/rules/no-native-reassign
'no-native-reassign': 'error',
// https://eslint.org/docs/rules/no-new
'no-new': 'error',
// https://eslint.org/docs/rules/no-new-func
'no-new-func': 'error',
// https://eslint.org/docs/rules/no-new-wrappers
'no-new-wrappers': 'error',
// https://eslint.org/docs/rules/no-octal
'no-octal': 'error',
// https://eslint.org/docs/rules/no-octal-escape
'no-octal-escape': 'error',
// https://eslint.org/docs/rules/no-param-reassign [REVISIT ME]
'no-param-reassign': 'off',
// https://eslint.org/docs/rules/no-proto
'no-proto': 'error',
// https://eslint.org/docs/rules/no-return-assign
'no-return-assign': 'error',
// https://eslint.org/docs/rules/no-script-url
'no-script-url': 'error',
// https://eslint.org/docs/rules/no-self-compare
'no-self-compare': 'error',
// https://eslint.org/docs/rules/no-sequences
'no-sequences': 'error',
// https://eslint.org/docs/rules/no-throw-literal
'no-throw-literal': 'error',
// https://eslint.org/docs/rules/no-with
'no-with': 'error',
// https://eslint.org/docs/rules/radix
radix: 'error',
// https://eslint.org/docs/rules/object-shorthand
'object-shorthand': ['error', 'properties'],
// https://eslint.org/docs/rules/vars-on-top
'vars-on-top': 'off',
// https://eslint.org/docs/rules/wrap-iife
'wrap-iife': ['error', 'any'],
// https://eslint.org/docs/rules/array-callback-return
'array-callback-return': 'error',
// https://eslint.org/docs/rules/yoda
yoda: 'error',
// https://eslint.org/docs/rules/no-else-return
'no-else-return': ['error', {allowElseIf: false}],
// https://eslint.org/docs/rules/require-await
'require-await': 'error',
// https://eslint.org/docs/rules/multiline-comment-style
'multiline-comment-style': ['error', 'separate-lines'],
// https://eslint.org/docs/rules/spaced-comment
'spaced-comment': [
'error',
'always',
{
line: {markers: ['/'], exceptions: ['-', '+']},
block: {exceptions: ['*'], balanced: true},
},
],
// Let formatter handle this
'arrow-body-style': 'off',
/**
* Restricted imports, e.g. deprecated libraries, etc
*
* See: https://eslint.org/docs/rules/no-restricted-imports
*/
'no-restricted-imports': [
'error',
{
patterns: restrictedImportPatterns,
paths: restrictedImportPaths,
},
],
// https://eslint.org/docs/rules/no-console
'no-console': 'error',
},
},
{
...importPlugin.flatConfigs.recommended,
name: 'plugin/import',
rules: {
// We override all the rules that are in the recommended, react, and typescript rulesets
// From the recommended ruleset:
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/export.md
'import/export': 'error',
// 5 rules not recommended to be enabled with typescript-eslint
// https://typescript-eslint.io/troubleshooting/typed-linting/performance/#slow-eslint-rules
'import/named': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
// Require a newline after the last import/require in a group
// Why doesn't prettier handle this? https://prettier.io/docs/en/rationale.html#empty-lines
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/newline-after-import.md
'import/newline-after-import': 'error',
// do not allow a default import name to match a named export (airbnb: error)
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md
'import/no-named-as-default': 'off',
// Prevent importing the default as if it were named
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-named-default.md
'import/no-named-default': 'error',
// disallow AMD require/define
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-amd.md
'import/no-amd': 'error',
// disallow duplicate imports
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md
'import/no-duplicates': 'error',
// Forbid import of modules using absolute paths
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-absolute-path.md
'import/no-absolute-path': 'error',
// Forbid Webpack loader syntax in imports
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-webpack-loader-syntax.md
'import/no-webpack-loader-syntax': 'error',
// Reports if a module"s default export is unnamed
// https://github.com/benmosher/eslint-plugin-import/blob/main/docs/rules/no-anonymous-default-export.md
'import/no-anonymous-default-export': 'error',
},
},
{
name: 'plugin/react',
plugins: {
...react.configs.flat.recommended.plugins,
// @ts-ignore noUncheckedIndexedAccess
...react.configs.flat['jsx-runtime'].plugins,
},
rules: {
...react.configs.flat.recommended.rules,
// @ts-ignore noUncheckedIndexedAccess
...react.configs.flat['jsx-runtime'].rules,
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
'react/display-name': 'off',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
'react/no-multi-comp': ['off', {ignoreStateless: true}],
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md
'react/jsx-fragments': ['error', 'element'],
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
// Ensures that any component or prop methods used to handle events are correctly prefixed.
'react/jsx-handler-names': [
'off',
{eventHandlerPrefix: 'handle', eventHandlerPropPrefix: 'on'},
],
// Disabled as we use the newer JSX transform babel plugin.
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
'react/jsx-uses-react': 'off',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
'react/no-did-mount-set-state': 'error',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md"
'react/no-did-update-set-state': 'error',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-redundant-should-component-update.md
'react/no-redundant-should-component-update': 'error',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-typos.md
'react/no-typos': 'error',
// Prevent invalid characters from appearing in markup
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
'react/no-unescaped-entities': 'off',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
'react/no-unknown-property': ['error', {ignore: ['css']}],
// We do not need proptypes since we're using typescript
'react/prop-types': 'off',
// Disabled as we are using the newer JSX transform babel plugin.
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
'react/react-in-jsx-scope': 'off',
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
'react/self-closing-comp': 'error',
// This also causes issues with typescript
// See: https://github.com/yannickcr/eslint-plugin-react/issues/2066
//
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
'react/sort-comp': 'warn',
// Consistent <Component booleanProp /> (never add ={true})
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
'react/jsx-boolean-value': ['error', 'never'],
// Consistent function component declaration styles
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
'react/function-component-definition': [
'error',
{namedComponents: 'function-declaration'},
],
},
},
{
name: 'plugin/react-hooks',
plugins: {'react-hooks': reactHooks},
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': [
'error',
{additionalHooks: '(useEffectAfterFirstRender|useMemoWithPrevious)'},
],
},
},
{
name: 'plugin/@typescript-eslint',
plugins: {'@typescript-eslint': typescript.plugin},
rules: {
// no-undef is redundant with typescript as tsc will complain
// A downside is that we won't get eslint errors about it, but your editors should
// support tsc errors so....
// https://eslint.org/docs/rules/no-undef
'no-undef': 'off',
/**
* Need to use typescript version of these rules
* https://eslint.org/docs/rules/no-shadow
*/
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
// This only override the `args` rule (which is "none"). There are too many errors and it's difficult to manually
// fix them all, so we'll have to incrementally update.
// https://eslint.org/docs/rules/no-unused-vars
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'all',
// TODO(scttcper): We could enable this to enforce catch (error)
// https://eslint.org/docs/latest/rules/no-unused-vars#caughterrors
caughtErrors: 'none',
// Ignore vars that start with an underscore
// e.g. if you want to omit a property using object spread:
//
// const {name: _name, ...props} = this.props;
//
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
},
],
// https://eslint.org/docs/rules/no-use-before-define
'no-use-before-define': 'off',
// This seems to have been turned on while previously it had been off
'@typescript-eslint/no-use-before-define': 'off',
// https://github.com/xojs/eslint-config-xo-typescript/blob/9791a067d6a119a21a4db72c02f1da95e25ffbb6/index.js#L95
'@typescript-eslint/no-restricted-types': [
'error',
{
types: {
// TODO(scttcper): Turn object on to make our types more strict
// object: {
// message: 'The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848',
// fixWith: 'Record<string, unknown>'
// },
Buffer: {
message:
'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer',
suggest: ['Uint8Array'],
},
'[]': "Don't use the empty array type `[]`. It only allows empty arrays. Use `SomeType[]` instead.",
'[[]]':
"Don't use `[[]]`. It only allows an array with a single element which is an empty array. Use `SomeType[][]` instead.",
'[[[]]]': "Don't use `[[[]]]`. Use `SomeType[][][]` instead.",
},
},
],
// TODO(scttcper): Turn no-empty-object-type on to make our types more strict
// '@typescript-eslint/no-empty-object-type': 'error',
// TODO(scttcper): Turn no-function on to make our types more strict
// '@typescript-eslint/no-unsafe-function-type': 'error',
'@typescript-eslint/no-wrapper-object-types': 'error',
// Naming convention enforcements
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'typeLike',
format: ['PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: 'enumMember',
format: ['UPPER_CASE'],
},
],
},
},
{
name: 'plugin/@typescript-eslint && process.env.SENTRY_DETECT_DEPRECATIONS',
rules: {
'@typescript-eslint/no-deprecated': process.env.SENTRY_DETECT_DEPRECATIONS
? 'error'
: 'off',
},
},
{
name: 'plugin/typescript-sort-keys',
plugins: {'typescript-sort-keys': typescriptSortKeys},
rules: {
'typescript-sort-keys/interface': [
'error',
'asc',
{caseSensitive: true, natural: false, requiredFirst: true},
],
},
},
{
name: 'plugin/simple-import-sort',
plugins: {'simple-import-sort': simpleImportSort},
rules: {
/**
* Better import sorting
*/
'sort-imports': 'off',
'simple-import-sort/imports': [
'error',
{
groups: [
// Side effect imports.
['^\\u0000'],
// Node.js builtins.
[`^(${builtinModules.join('|')})(/|$)`],
// Packages. `react` related packages come first.
['^react', '^@?\\w'],
// Test should be separate from the app
['^(sentry-test|getsentry-test)(/.*|$)'],
// Internal packages.
['^(sentry-locale|sentry-images)(/.*|$)'],
['^(getsentry-images)(/.*|$)'],
['^(app|sentry)(/.*|$)'],
// Getsentry packages.
['^(admin|getsentry)(/.*|$)'],
// Style imports.
['^.+\\.less$'],
// Parent imports. Put `..` last.
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
// Other relative imports. Put same-folder imports and `.` last.
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
],
},
],
},
},
{
name: 'plugin/sentry',
plugins: {sentry},
rules: {
'sentry/no-digits-in-tn': 'error',
'sentry/no-dynamic-translations': 'error',
'sentry/no-styled-shortcut': 'error',
},
},
{
name: 'plugin/@emotion',
plugins: {'@emotion': emotion},
rules: {
'@emotion/import-from-emotion': 'off', // Not needed, in v11 we import from @emotion/react
'@emotion/jsx-import': 'off', // Not needed, handled by babel
'@emotion/no-vanilla': 'error',
'@emotion/pkg-renaming': 'off', // Not needed, we have migrated to v11 and the old package names cannot be used anymore
'@emotion/styled-import': 'error',
'@emotion/syntax-preference': ['off', 'string'], // TODO(ryan953): Enable this so `css={css``}` is required
},
},
{
name: 'plugin/jest',
files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
plugins: jest.configs['flat/recommended'].plugins,
rules: {
...jest.configs['flat/recommended'].rules,
...jest.configs['flat/style'].rules,
// `recommended` set this to warn, we've upgraded to error
'jest/no-disabled-tests': 'error',
// `recommended` set this to warn, we've downgraded to off
// Disabled as we have many tests which render as simple validations
'jest/expect-expect': 'off',
// Disabled as we have some comment out tests that cannot be
// uncommented due to typescript errors.
'jest/no-commented-out-tests': 'off', // TODO(ryan953): Fix violations then delete this line
// Disabled as we do sometimes have conditional expects
'jest/no-conditional-expect': 'off', // TODO(ryan953): Fix violations then delete this line
// We don't recommend snapshots, but if there are any keep it small
'jest/no-large-snapshots': ['error', {maxSize: 2000}],
'jest/no-alias-methods': 'off', // TODO(ryan953): Fix violations then delete this line
'jest/prefer-to-be': 'off', // TODO(ryan953): Fix violations then delete this line
'jest/prefer-to-contain': 'off', // TODO(ryan953): Fix violations then delete this line
'jest/prefer-to-have-length': 'off', // TODO(ryan953): Fix violations then delete this line
},
},
{
name: 'plugin/jest-dom',
files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
...jestDom.configs['flat/recommended'],
},
{
name: 'plugin/testing-library',
files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
...testingLibrary.configs['flat/react'],
rules: {
...testingLibrary.configs['flat/react'].rules,
'testing-library/render-result-naming-convention': 'off',
'testing-library/no-unnecessary-act': 'off',
},
},
{
name: 'plugin/prettier',
...prettier,
},
{
name: 'files/devtoolbar',
files: ['static/app/components/devtoolbar/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
...restrictedImportPaths,
{
name: 'sentry/utils/queryClient',
message:
'Import from `@tanstack/react-query` and `./hooks/useFetchApiData` or `./hooks/useFetchInfiniteApiData` instead.',
},
],
},
],
},
},
{
name: 'files/sentry-test',
files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: restrictedImportPatterns,
paths: [
...restrictedImportPaths,
{
name: 'sentry/locale',
message: 'Translations are not needed in tests.',
},
],
},
],
},
},
{
// We specify rules explicitly for the sdk-loader here so we do not have
// eslint ignore comments included in the source file, which is consumed
// by users.
name: 'files/js-sdk-loader.ts',
files: ['**/js-sdk-loader.ts'],
rules: {
'no-console': 'off',
},
},
]);