eslint.config.mjs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. // @ts-check
  2. /**
  3. * To get started with this ESLint Configuration list be sure to read at least
  4. * these sections of the docs:
  5. * - https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
  6. * - https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects
  7. * - https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects
  8. *
  9. * This is your friend:
  10. * `npx eslint --inspect-config`
  11. */
  12. import * as emotion from '@emotion/eslint-plugin';
  13. import eslint from '@eslint/js';
  14. import prettier from 'eslint-config-prettier';
  15. // @ts-expect-error TS(7016): Could not find a declaration file
  16. import importPlugin from 'eslint-plugin-import';
  17. import jest from 'eslint-plugin-jest';
  18. import jestDom from 'eslint-plugin-jest-dom';
  19. import react from 'eslint-plugin-react';
  20. // @ts-expect-error TS(7016): Could not find a declaration file
  21. import reactHooks from 'eslint-plugin-react-hooks';
  22. // @ts-expect-error TS(7016): Could not find a declaration file
  23. import sentry from 'eslint-plugin-sentry';
  24. import simpleImportSort from 'eslint-plugin-simple-import-sort';
  25. import testingLibrary from 'eslint-plugin-testing-library';
  26. // @ts-expect-error TS (7016): Could not find a declaration file
  27. import typescriptSortKeys from 'eslint-plugin-typescript-sort-keys';
  28. import unicorn from 'eslint-plugin-unicorn';
  29. import globals from 'globals';
  30. import invariant from 'invariant';
  31. // biome-ignore lint/correctness/noNodejsModules: Need to get the list of things!
  32. import {builtinModules} from 'node:module';
  33. import typescript from 'typescript-eslint';
  34. invariant(react.configs.flat, 'For typescript');
  35. invariant(react.configs.flat.recommended, 'For typescript');
  36. invariant(react.configs.flat['jsx-runtime'], 'For typescript');
  37. const restrictedImportPatterns = [
  38. {
  39. group: ['sentry/components/devtoolbar/*'],
  40. message: 'Do not depend on toolbar internals',
  41. },
  42. ];
  43. const restrictedImportPaths = [
  44. {
  45. name: '@testing-library/react',
  46. message:
  47. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  48. },
  49. {
  50. name: '@testing-library/react-hooks',
  51. message:
  52. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  53. },
  54. {
  55. name: '@testing-library/user-event',
  56. message:
  57. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  58. },
  59. {
  60. name: '@sentry/browser',
  61. message:
  62. 'Please import from `@sentry/react` to ensure consistency throughout the codebase.',
  63. },
  64. {
  65. name: 'marked',
  66. message:
  67. "Please import marked from 'app/utils/marked' so that we can ensure sanitation of marked output",
  68. },
  69. {
  70. name: 'lodash',
  71. message:
  72. "Please import lodash utilities individually. e.g. `import isEqual from 'lodash/isEqual';`. See https://github.com/getsentry/frontend-handbook#lodash from for information",
  73. },
  74. {
  75. name: 'lodash/get',
  76. message:
  77. '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',
  78. },
  79. {
  80. name: 'sentry/utils/theme',
  81. importNames: ['lightColors', 'darkColors'],
  82. message:
  83. "'lightColors' and 'darkColors' exports intended for use in Storybook only. Instead, use theme prop from emotion or the useTheme hook.",
  84. },
  85. {
  86. name: 'react-router',
  87. importNames: ['withRouter'],
  88. message:
  89. "Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
  90. },
  91. {
  92. name: 'sentry/utils/withSentryRouter',
  93. message:
  94. "Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
  95. },
  96. {
  97. name: 'qs',
  98. message: 'Please use query-string instead of qs',
  99. },
  100. {
  101. name: 'moment',
  102. message: 'Please import moment-timezone instead of moment',
  103. },
  104. ];
  105. // Used by both: `languageOptions` & `parserOptions`
  106. const ecmaVersion = 6; // TODO(ryan953): change to 'latest'
  107. export default typescript.config([
  108. {
  109. // Main parser & linter options
  110. // Rules are defined below and inherit these properties
  111. // https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects
  112. name: 'eslint/global/languageOptions',
  113. languageOptions: {
  114. ecmaVersion,
  115. sourceType: 'module',
  116. globals: {
  117. // TODO(ryan953): globals.browser seems to have a bug with trailing whitespace
  118. ...Object.fromEntries(Object.keys(globals.browser).map(k => [k.trim(), false])),
  119. ...globals.jest,
  120. MockApiClient: true,
  121. tick: true,
  122. },
  123. parser: typescript.parser,
  124. parserOptions: {
  125. ecmaFeatures: {
  126. globalReturn: false,
  127. },
  128. ecmaVersion,
  129. // https://typescript-eslint.io/packages/parser/#emitdecoratormetadata
  130. emitDecoratorMetadata: undefined,
  131. // https://typescript-eslint.io/packages/parser/#experimentaldecorators
  132. experimentalDecorators: undefined,
  133. // https://typescript-eslint.io/packages/parser/#jsdocparsingmode
  134. jsDocParsingMode: process.env.SENTRY_DETECT_DEPRECATIONS ? 'all' : 'none',
  135. // https://typescript-eslint.io/packages/parser/#project
  136. project: process.env.SENTRY_DETECT_DEPRECATIONS ? './tsconfig.json' : false,
  137. // https://typescript-eslint.io/packages/parser/#projectservice
  138. // `projectService` is recommended, but slower, with our current tsconfig files.
  139. // projectService: true,
  140. // tsconfigRootDir: import.meta.dirname,
  141. },
  142. },
  143. linterOptions: {
  144. noInlineConfig: false,
  145. reportUnusedDisableDirectives: 'error',
  146. },
  147. settings: {
  148. react: {
  149. version: '18.2.0',
  150. defaultVersion: '18.2',
  151. },
  152. 'import/parsers': {'@typescript-eslint/parser': ['.ts', '.tsx']},
  153. 'import/resolver': {typescript: {}},
  154. 'import/extensions': ['.js', '.jsx'],
  155. },
  156. },
  157. {
  158. name: 'eslint/global/files',
  159. // Default file selection
  160. // https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores
  161. files: ['**/*.js', '**/*.mjs', '**/*.ts', '**/*.jsx', '**/*.tsx'],
  162. },
  163. {
  164. name: 'eslint/global/ignores',
  165. // Global ignores
  166. // https://eslint.org/docs/latest/use/configure/configuration-files#globally-ignoring-files-with-ignores
  167. ignores: [
  168. '.devenv/**/*',
  169. '.github/**/*',
  170. '.mypy_cache/**/*',
  171. '.pytest_cache/**/*',
  172. '.venv/**/*',
  173. '**/*.benchmark.ts',
  174. '**/*.d.ts',
  175. '**/dist/**/*',
  176. '**/tests/**/fixtures/**/*',
  177. '**/vendor/**/*',
  178. 'build-utils/**/*',
  179. 'config/chartcuterie/config.js', // TODO: see if this file exists
  180. 'fixtures/artifact_bundle/**/*',
  181. 'fixtures/artifact_bundle_debug_ids/**/*',
  182. 'fixtures/artifact_bundle_duplicated_debug_ids/**/*',
  183. 'fixtures/profiles/embedded.js',
  184. 'jest.config.ts',
  185. 'api-docs/**/*',
  186. 'src/sentry/static/sentry/js/**/*',
  187. 'src/sentry/templates/sentry/**/*',
  188. 'stylelint.config.js',
  189. ],
  190. },
  191. /**
  192. * Rules are grouped by plugin. If you want to override a specific rule inside
  193. * the recommended set, then it's recommended to spread the new rule on top
  194. * of the predefined ones.
  195. *
  196. * For example: if you want to enable a new plugin in the codebase and their
  197. * recommended rules (or a new rule that's part of an existing plugin)
  198. *
  199. * 1. First you'd setup a configuration object for that plugin:
  200. * {
  201. * name: 'my-plugin/recommended',
  202. * ...myPlugin.configs.recommended,
  203. * },
  204. *
  205. * 2. Second you'd override the rule you want to deal with, maybe making it a
  206. * warning to start:
  207. * {
  208. * name: 'my-plugin/recommended',
  209. * ...myPlugin.configs.recommended,
  210. * rules: {
  211. * ['a-rule-outside-the-recommended-list']: 'error',
  212. *
  213. * ...myPlugin.configs.recommended.rules,
  214. * ['a-recommended-rule']: 'warn',
  215. * }
  216. * },
  217. *
  218. * 3. Finally, once all warnings are fixed, update from 'warning' to 'error',
  219. * or remove the override and rely on the recommended rules again.
  220. */
  221. {
  222. name: 'eslint/rules',
  223. // https://eslint.org/docs/latest/rules/
  224. rules: {
  225. 'array-callback-return': 'error',
  226. 'block-scoped-var': 'error',
  227. 'consistent-return': 'error',
  228. 'default-case': 'error',
  229. 'dot-notation': 'error',
  230. eqeqeq: 'error',
  231. 'guard-for-in': 'off', // TODO(ryan953): Fix violations and enable this rule
  232. 'multiline-comment-style': ['error', 'separate-lines'],
  233. 'no-alert': 'error',
  234. 'no-caller': 'error',
  235. 'no-console': 'error',
  236. 'no-else-return': ['error', {allowElseIf: false}],
  237. 'no-eval': 'error',
  238. 'no-extend-native': 'error',
  239. 'no-extra-bind': 'error',
  240. 'no-floating-decimal': 'error',
  241. 'no-implied-eval': 'error',
  242. 'no-inner-declarations': 'error',
  243. 'no-lone-blocks': 'error',
  244. 'no-loop-func': 'error',
  245. 'no-multi-str': 'error',
  246. 'no-native-reassign': 'error',
  247. 'no-new-func': 'error',
  248. 'no-new-wrappers': 'error',
  249. 'no-new': 'error',
  250. 'no-octal-escape': 'error',
  251. 'no-param-reassign': 'off', // TODO(ryan953): Fix violations and enable this rule
  252. 'no-proto': 'error',
  253. 'no-restricted-imports': [
  254. 'error',
  255. {patterns: restrictedImportPatterns, paths: restrictedImportPaths},
  256. ],
  257. 'no-return-assign': 'error',
  258. 'no-script-url': 'error',
  259. 'no-self-compare': 'error',
  260. 'no-sequences': 'error',
  261. 'no-throw-literal': 'error',
  262. 'object-shorthand': ['error', 'properties'],
  263. radix: 'error',
  264. 'require-await': 'error', // Enabled in favor of @typescript-eslint/require-await, which requires type info
  265. 'spaced-comment': [
  266. 'error',
  267. 'always',
  268. {
  269. line: {markers: ['/'], exceptions: ['-', '+']},
  270. block: {exceptions: ['*'], balanced: true},
  271. },
  272. ],
  273. strict: 'error',
  274. 'vars-on-top': 'off',
  275. 'wrap-iife': ['error', 'any'],
  276. yoda: 'error',
  277. // https://github.com/eslint/eslint/blob/main/packages/js/src/configs/eslint-recommended.js
  278. ...eslint.configs.recommended.rules,
  279. 'no-cond-assign': ['error', 'always'],
  280. 'no-prototype-builtins': 'off',
  281. 'no-useless-escape': 'off',
  282. },
  283. },
  284. {
  285. // https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
  286. ...importPlugin.flatConfigs.recommended,
  287. name: 'plugin/import',
  288. rules: {
  289. 'import/newline-after-import': 'error', // https://prettier.io/docs/en/rationale.html#empty-lines
  290. 'import/no-absolute-path': 'error',
  291. 'import/no-amd': 'error',
  292. 'import/no-anonymous-default-export': 'error',
  293. 'import/no-duplicates': 'error',
  294. 'import/no-named-default': 'error',
  295. 'import/no-nodejs-modules': 'error',
  296. 'import/no-webpack-loader-syntax': 'error',
  297. // https://github.com/import-js/eslint-plugin-import/blob/main/config/recommended.js
  298. ...importPlugin.flatConfigs.recommended.rules,
  299. 'import/default': 'off', // Disabled in favor of typescript-eslint
  300. 'import/named': 'off', // Disabled in favor of typescript-eslint
  301. 'import/namespace': 'off', // Disabled in favor of typescript-eslint
  302. 'import/no-named-as-default-member': 'off', // Disabled in favor of typescript-eslint
  303. 'import/no-named-as-default': 'off', // TODO(ryan953): Fix violations and enable this rule
  304. 'import/no-unresolved': 'off', // Disabled in favor of typescript-eslint
  305. },
  306. },
  307. {
  308. name: 'plugin/react',
  309. // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules
  310. plugins: {
  311. ...react.configs.flat.recommended.plugins,
  312. ...react.configs.flat['jsx-runtime'].plugins,
  313. },
  314. rules: {
  315. 'react/function-component-definition': 'error',
  316. 'react/jsx-boolean-value': ['error', 'never'],
  317. 'react/jsx-fragments': ['error', 'element'],
  318. 'react/jsx-handler-names': 'off', // TODO(ryan953): Fix violations and enable this rule
  319. 'react/no-did-mount-set-state': 'error',
  320. 'react/no-did-update-set-state': 'error',
  321. 'react/no-redundant-should-component-update': 'error',
  322. 'react/no-typos': 'error',
  323. 'react/self-closing-comp': 'error',
  324. 'react/sort-comp': 'error',
  325. // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/index.js
  326. ...react.configs.flat.recommended.rules,
  327. ...react.configs.flat['jsx-runtime'].rules,
  328. 'react/display-name': 'off', // TODO(ryan953): Fix violations and delete this line
  329. 'react/no-unescaped-entities': 'off',
  330. 'react/no-unknown-property': ['error', {ignore: ['css']}],
  331. 'react/prop-types': 'off', // TODO(ryan953): Fix violations and delete this line
  332. },
  333. },
  334. {
  335. name: 'plugin/react-hooks',
  336. // https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks
  337. plugins: {'react-hooks': reactHooks},
  338. rules: {
  339. 'react-hooks/exhaustive-deps': [
  340. 'error',
  341. {additionalHooks: '(useEffectAfterFirstRender|useMemoWithPrevious)'},
  342. ],
  343. 'react-hooks/rules-of-hooks': 'error',
  344. },
  345. },
  346. {
  347. name: 'plugin/typescript-eslint/custom',
  348. rules: {
  349. 'no-shadow': 'off', // Disabled in favor of @typescript-eslint/no-shadow
  350. 'no-use-before-define': 'off', // See also @typescript-eslint/no-use-before-define
  351. '@typescript-eslint/naming-convention': [
  352. 'error',
  353. {selector: 'typeLike', format: ['PascalCase'], leadingUnderscore: 'allow'},
  354. {selector: 'enumMember', format: ['UPPER_CASE']},
  355. ],
  356. '@typescript-eslint/no-restricted-types': [
  357. 'error',
  358. {
  359. types: {
  360. // TODO(scttcper): Turn object on to make our types more strict
  361. // object: {
  362. // message: 'The `object` type is hard to use. Use `Record<string, unknown>` instead. See: https://github.com/typescript-eslint/typescript-eslint/pull/848',
  363. // fixWith: 'Record<string, unknown>'
  364. // },
  365. Buffer: {
  366. message:
  367. 'Use Uint8Array instead. See: https://sindresorhus.com/blog/goodbye-nodejs-buffer',
  368. suggest: ['Uint8Array'],
  369. },
  370. '[]': "Don't use the empty array type `[]`. It only allows empty arrays. Use `SomeType[]` instead.",
  371. '[[]]':
  372. "Don't use `[[]]`. It only allows an array with a single element which is an empty array. Use `SomeType[][]` instead.",
  373. '[[[]]]': "Don't use `[[[]]]`. Use `SomeType[][][]` instead.",
  374. },
  375. },
  376. ],
  377. '@typescript-eslint/no-shadow': 'error',
  378. '@typescript-eslint/no-use-before-define': 'off', // Enabling this will cause a lot of thrash to the git history
  379. '@typescript-eslint/no-useless-empty-export': 'error',
  380. },
  381. },
  382. // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/base.ts
  383. // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended-raw.ts
  384. // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
  385. // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict.ts
  386. // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic.ts
  387. ...typescript.configs.strict.map(c => ({...c, name: `plugin/${c.name}`})),
  388. ...typescript.configs.stylistic.map(c => ({...c, name: `plugin/${c.name}`})),
  389. {
  390. name: 'plugin/typescript-eslint/overrides',
  391. // https://typescript-eslint.io/rules/
  392. plugins: {'@typescript-eslint': typescript.plugin},
  393. rules: {
  394. 'prefer-spread': 'off',
  395. '@typescript-eslint/prefer-enum-initializers': 'error',
  396. // Recommended overrides
  397. '@typescript-eslint/no-empty-object-type': 'off', // TODO(ryan953): Fix violations and delete this line
  398. '@typescript-eslint/no-explicit-any': 'off',
  399. '@typescript-eslint/no-namespace': 'off',
  400. '@typescript-eslint/no-non-null-asserted-optional-chain': 'off', // TODO(ryan953): Fix violations and delete this line
  401. '@typescript-eslint/no-require-imports': 'off', // TODO(ryan953): Fix violations and delete this line
  402. '@typescript-eslint/no-this-alias': 'off', // TODO(ryan953): Fix violations and delete this line
  403. '@typescript-eslint/no-unsafe-function-type': 'off', // TODO(ryan953): Fix violations and delete this line
  404. // Strict overrides
  405. '@typescript-eslint/no-dynamic-delete': 'off', // TODO(ryan953): Fix violations and delete this line
  406. '@typescript-eslint/no-invalid-void-type': 'off', // TODO(ryan953): Fix violations and delete this line
  407. '@typescript-eslint/no-non-null-assertion': 'off', // TODO(ryan953): Fix violations and delete this line
  408. '@typescript-eslint/unified-signatures': 'off',
  409. // Stylistic overrides
  410. '@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
  411. '@typescript-eslint/class-literal-property-style': 'off', // TODO(ryan953): Fix violations and delete this line
  412. '@typescript-eslint/consistent-generic-constructors': 'off', // TODO(ryan953): Fix violations and delete this line
  413. '@typescript-eslint/consistent-indexed-object-style': 'off', // TODO(ryan953): Fix violations and delete this line
  414. '@typescript-eslint/consistent-type-definitions': 'off', // TODO(ryan953): Fix violations and delete this line
  415. '@typescript-eslint/no-empty-function': 'off', // TODO(ryan953): Fix violations and delete this line
  416. '@typescript-eslint/no-inferrable-types': 'off', // TODO(ryan953): Fix violations and delete this line
  417. // Customization
  418. '@typescript-eslint/no-unused-vars': [
  419. 'error',
  420. {
  421. vars: 'all',
  422. args: 'all',
  423. // TODO(scttcper): We could enable this to enforce catch (error)
  424. // https://eslint.org/docs/latest/rules/no-unused-vars#caughterrors
  425. caughtErrors: 'none',
  426. // Ignore vars that start with an underscore
  427. // e.g. if you want to omit a property using object spread:
  428. //
  429. // const {name: _name, ...props} = this.props;
  430. //
  431. varsIgnorePattern: '^_',
  432. argsIgnorePattern: '^_',
  433. destructuredArrayIgnorePattern: '^_',
  434. },
  435. ],
  436. },
  437. },
  438. {
  439. name: 'plugin/typescript-eslint/process.env.SENTRY_DETECT_DEPRECATIONS=1',
  440. rules: {
  441. '@typescript-eslint/no-deprecated': process.env.SENTRY_DETECT_DEPRECATIONS
  442. ? 'error'
  443. : 'off',
  444. },
  445. },
  446. {
  447. name: 'plugin/typescript-sort-keys',
  448. // https://github.com/infctr/eslint-plugin-typescript-sort-keys
  449. plugins: {'typescript-sort-keys': typescriptSortKeys},
  450. rules: {
  451. 'typescript-sort-keys/interface': [
  452. 'error',
  453. 'asc',
  454. {caseSensitive: true, natural: false, requiredFirst: true},
  455. ],
  456. },
  457. },
  458. {
  459. name: 'plugin/simple-import-sort',
  460. // https://github.com/lydell/eslint-plugin-simple-import-sort
  461. plugins: {'simple-import-sort': simpleImportSort},
  462. rules: {
  463. 'import/order': 'off',
  464. 'sort-imports': 'off',
  465. 'simple-import-sort/imports': [
  466. 'error',
  467. {
  468. groups: [
  469. // Side effect imports.
  470. [String.raw`^\u0000`],
  471. // Node.js builtins.
  472. [`^(${builtinModules.join('|')})(/|$)`],
  473. // Packages. `react` related packages come first.
  474. ['^react', String.raw`^@?\w`],
  475. // Test should be separate from the app
  476. ['^(sentry-test|getsentry-test)(/.*|$)'],
  477. // Internal packages.
  478. ['^(sentry-locale|sentry-images)(/.*|$)'],
  479. ['^(getsentry-images)(/.*|$)'],
  480. ['^(app|sentry)(/.*|$)'],
  481. // Getsentry packages.
  482. ['^(admin|getsentry)(/.*|$)'],
  483. // Style imports.
  484. [String.raw`^.+\.less$`],
  485. // Parent imports. Put `..` last.
  486. [String.raw`^\.\.(?!/?$)`, String.raw`^\.\./?$`],
  487. // Other relative imports. Put same-folder imports and `.` last.
  488. [String.raw`^\./(?=.*/)(?!/?$)`, String.raw`^\.(?!/?$)`, String.raw`^\./?$`],
  489. ],
  490. },
  491. ],
  492. },
  493. },
  494. {
  495. name: 'plugin/sentry',
  496. // https://github.com/getsentry/eslint-config-sentry/tree/master/packages/eslint-plugin-sentry/docs/rules
  497. plugins: {sentry},
  498. rules: {
  499. 'sentry/no-digits-in-tn': 'error',
  500. 'sentry/no-dynamic-translations': 'error', // TODO(ryan953): There are no docs for this rule
  501. 'sentry/no-styled-shortcut': 'error',
  502. },
  503. },
  504. {
  505. name: 'plugin/@emotion',
  506. // https://github.com/emotion-js/emotion/tree/main/packages/eslint-plugin/docs/rules
  507. plugins: {'@emotion': emotion},
  508. rules: {
  509. '@emotion/import-from-emotion': 'off', // Not needed, in v11 we import from @emotion/react
  510. '@emotion/jsx-import': 'off', // Not needed, handled by babel
  511. '@emotion/no-vanilla': 'error',
  512. '@emotion/pkg-renaming': 'off', // Not needed, we have migrated to v11 and the old package names cannot be used anymore
  513. '@emotion/styled-import': 'error',
  514. '@emotion/syntax-preference': ['error', 'string'],
  515. },
  516. },
  517. {
  518. name: 'plugin/unicorn',
  519. plugins: {unicorn},
  520. rules: {
  521. // The recommended rules are very opinionated. We don't need to enable them.
  522. 'unicorn/no-instanceof-array': 'error',
  523. 'unicorn/prefer-array-flat-map': 'error',
  524. 'unicorn/prefer-node-protocol': 'error',
  525. },
  526. },
  527. {
  528. name: 'plugin/jest',
  529. files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
  530. // https://github.com/jest-community/eslint-plugin-jest/tree/main/docs/rules
  531. plugins: jest.configs['flat/recommended'].plugins,
  532. rules: {
  533. 'jest/max-nested-describe': 'error',
  534. 'jest/no-duplicate-hooks': 'error',
  535. 'jest/no-large-snapshots': ['error', {maxSize: 2000}], // We don't recommend snapshots, but if there are any keep it small
  536. // https://github.com/jest-community/eslint-plugin-jest/blob/main/src/index.ts
  537. ...jest.configs['flat/recommended'].rules,
  538. ...jest.configs['flat/style'].rules,
  539. 'jest/expect-expect': 'off', // Disabled as we have many tests which render as simple validations
  540. 'jest/no-conditional-expect': 'off', // TODO(ryan953): Fix violations then delete this line
  541. 'jest/no-disabled-tests': 'error', // `recommended` set this to warn, we've upgraded to error
  542. },
  543. },
  544. {
  545. name: 'plugin/jest-dom',
  546. files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
  547. // https://github.com/testing-library/eslint-plugin-jest-dom/tree/main?tab=readme-ov-file#supported-rules
  548. ...jestDom.configs['flat/recommended'],
  549. },
  550. {
  551. name: 'plugin/testing-library',
  552. files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
  553. // https://github.com/testing-library/eslint-plugin-testing-library/tree/main/docs/rules
  554. ...testingLibrary.configs['flat/react'],
  555. rules: {
  556. // https://github.com/testing-library/eslint-plugin-testing-library/blob/main/lib/configs/react.ts
  557. ...testingLibrary.configs['flat/react'].rules,
  558. 'testing-library/no-unnecessary-act': 'off',
  559. 'testing-library/render-result-naming-convention': 'off',
  560. },
  561. },
  562. {
  563. name: 'plugin/prettier',
  564. ...prettier,
  565. },
  566. {
  567. name: 'files/*.config.*',
  568. files: ['**/*.config.*'],
  569. languageOptions: {
  570. globals: {
  571. ...globals.commonjs,
  572. ...globals.node,
  573. },
  574. },
  575. rules: {
  576. 'import/no-nodejs-modules': 'off',
  577. },
  578. },
  579. {
  580. name: 'files/scripts',
  581. files: ['scripts/**/*.{js,ts}', 'tests/js/test-balancer/index.js'],
  582. languageOptions: {
  583. sourceType: 'commonjs',
  584. globals: {
  585. ...globals.commonjs,
  586. ...globals.node,
  587. },
  588. },
  589. rules: {
  590. 'no-console': 'off',
  591. 'import/no-nodejs-modules': 'off',
  592. },
  593. },
  594. {
  595. name: 'files/jest related',
  596. files: [
  597. 'tests/js/jest-pegjs-transform.js',
  598. 'tests/js/sentry-test/echartsMock.js',
  599. 'tests/js/sentry-test/importStyleMock.js',
  600. 'tests/js/sentry-test/loadFixtures.ts',
  601. 'tests/js/sentry-test/svgMock.js',
  602. 'tests/js/setup.ts',
  603. ],
  604. languageOptions: {
  605. sourceType: 'commonjs',
  606. globals: {
  607. ...globals.commonjs,
  608. },
  609. },
  610. rules: {
  611. 'import/no-nodejs-modules': 'off',
  612. },
  613. },
  614. {
  615. name: 'files/devtoolbar',
  616. files: ['static/app/components/devtoolbar/**/*.{ts,tsx}'],
  617. rules: {
  618. 'no-restricted-imports': [
  619. 'error',
  620. {
  621. paths: [
  622. ...restrictedImportPaths,
  623. {
  624. name: 'sentry/utils/queryClient',
  625. message:
  626. 'Import from `@tanstack/react-query` and `./hooks/useFetchApiData` or `./hooks/useFetchInfiniteApiData` instead.',
  627. },
  628. ],
  629. },
  630. ],
  631. },
  632. },
  633. {
  634. name: 'files/sentry-test',
  635. files: ['**/*.spec.{ts,js,tsx,jsx}', 'tests/js/**/*.{ts,js,tsx,jsx}'],
  636. rules: {
  637. 'no-loss-of-precision': 'off', // Sometimes we have wild numbers hard-coded in tests
  638. 'no-restricted-imports': [
  639. 'error',
  640. {
  641. patterns: restrictedImportPatterns,
  642. paths: [
  643. ...restrictedImportPaths,
  644. {
  645. name: 'sentry/locale',
  646. message: 'Translations are not needed in tests.',
  647. },
  648. ],
  649. },
  650. ],
  651. },
  652. },
  653. {
  654. name: 'files/sentry-stories',
  655. files: ['**/*.stories.tsx'],
  656. rules: {
  657. 'no-loss-of-precision': 'off', // Sometimes we have wild numbers hard-coded in stories
  658. },
  659. },
  660. {
  661. // We specify rules explicitly for the sdk-loader here so we do not have
  662. // eslint ignore comments included in the source file, which is consumed
  663. // by users.
  664. name: 'files/js-sdk-loader.ts',
  665. files: ['**/js-sdk-loader.ts'],
  666. rules: {
  667. 'no-console': 'off',
  668. },
  669. },
  670. ]);