eslint.config.mjs 27 KB

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