.eslintrc.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* eslint-env node */
  2. const detectDeprecations = !!process.env.SENTRY_DETECT_DEPRECATIONS;
  3. module.exports = {
  4. root: true,
  5. extends: detectDeprecations
  6. ? ['sentry-app/strict', 'plugin:deprecation/recommended']
  7. : ['sentry-app/strict'],
  8. parserOptions: detectDeprecations
  9. ? {
  10. project: './tsconfig.json',
  11. }
  12. : {},
  13. globals: {
  14. require: false,
  15. expect: false,
  16. MockApiClient: true,
  17. tick: true,
  18. jest: true,
  19. },
  20. rules: {
  21. 'react-hooks/exhaustive-deps': [
  22. 'error',
  23. {additionalHooks: '(useEffectAfterFirstRender|useMemoWithPrevious)'},
  24. ],
  25. 'no-restricted-imports': [
  26. 'error',
  27. {
  28. patterns: [
  29. {
  30. group: ['sentry/components/devtoolbar/*'],
  31. message: 'Do not depend on toolbar internals',
  32. },
  33. ],
  34. paths: [
  35. {
  36. name: '@testing-library/react',
  37. message:
  38. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  39. },
  40. {
  41. name: '@testing-library/react-hooks',
  42. message:
  43. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  44. },
  45. {
  46. name: '@testing-library/user-event',
  47. message:
  48. 'Please import from `sentry-test/reactTestingLibrary` instead so that we can ensure consistency throughout the codebase',
  49. },
  50. {
  51. name: '@sentry/browser',
  52. message:
  53. 'Please import from `@sentry/react` to ensure consistency throughout the codebase.',
  54. },
  55. {
  56. name: 'marked',
  57. message:
  58. "Please import marked from 'app/utils/marked' so that we can ensure sanitation of marked output",
  59. },
  60. {
  61. name: 'lodash',
  62. message:
  63. "Please import lodash utilities individually. e.g. `import isEqual from 'lodash/isEqual';`. See https://github.com/getsentry/frontend-handbook#lodash from for information",
  64. },
  65. {
  66. name: 'lodash/get',
  67. message:
  68. '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',
  69. },
  70. {
  71. name: 'sentry/utils/theme',
  72. importNames: ['lightColors', 'darkColors'],
  73. message:
  74. "'lightColors' and 'darkColors' exports intended for use in Storybook only. Instead, use theme prop from emotion or the useTheme hook.",
  75. },
  76. {
  77. name: 'react-router',
  78. importNames: ['withRouter'],
  79. message:
  80. "Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
  81. },
  82. {
  83. name: 'sentry/utils/withSentryRouter',
  84. importNames: ['withSentryRouter'],
  85. message:
  86. "Use 'useLocation', 'useParams', 'useNavigate', 'useRoutes' from sentry/utils instead.",
  87. },
  88. ],
  89. },
  90. ],
  91. // TODO(@anonrig): Remove this from eslint-sentry-config
  92. 'space-infix-ops': 'off',
  93. 'object-shorthand': 'off',
  94. 'object-curly-spacing': 'off',
  95. 'import/no-amd': 'off',
  96. 'no-danger-with-children': 'off',
  97. 'no-fallthrough': 'off',
  98. 'no-obj-calls': 'off',
  99. 'array-bracket-spacing': 'off',
  100. 'computed-property-spacing': 'off',
  101. 'react/no-danger-with-children': 'off',
  102. 'jest/no-disabled-tests': 'off',
  103. },
  104. // JSON file formatting is handled by Biome. ESLint should not be linting
  105. // and formatting these files.
  106. ignorePatterns: ['*.json'],
  107. overrides: [
  108. {
  109. files: ['static/app/components/devtoolbar/**/*.{ts,tsx}'],
  110. rules: {
  111. 'no-restricted-imports': [
  112. 'error',
  113. {
  114. paths: [
  115. {
  116. name: 'sentry/utils/queryClient',
  117. message:
  118. 'Import from `@tanstack/react-query` and `./hooks/useFetchApiData` or `./hooks/useFetchInfiniteApiData` instead.',
  119. },
  120. ],
  121. },
  122. ],
  123. },
  124. },
  125. {
  126. files: ['static/**/*.spec.{ts,js}', 'tests/js/**/*.{ts,js}'],
  127. extends: ['plugin:testing-library/react', 'sentry-app/strict'],
  128. rules: {
  129. // TODO(@anonrig): Remove this from eslint-sentry-config
  130. 'space-infix-ops': 'off',
  131. 'object-shorthand': 'off',
  132. 'object-curly-spacing': 'off',
  133. 'import/no-amd': 'off',
  134. 'no-danger-with-children': 'off',
  135. 'no-fallthrough': 'off',
  136. 'no-obj-calls': 'off',
  137. 'array-bracket-spacing': 'off',
  138. 'computed-property-spacing': 'off',
  139. 'react/no-danger-with-children': 'off',
  140. 'jest/no-disabled-tests': 'off',
  141. },
  142. },
  143. {
  144. // We specify rules explicitly for the sdk-loader here so we do not have
  145. // eslint ignore comments included in the source file, which is consumed
  146. // by users.
  147. files: ['**/js-sdk-loader.ts'],
  148. rules: {
  149. 'no-console': 'off',
  150. },
  151. },
  152. ],
  153. };