.eslintrc.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. name: 'qs',
  90. message: 'Please use query-string instead of qs',
  91. },
  92. {
  93. name: 'moment',
  94. message: 'Please import moment-timezone instead of moment',
  95. },
  96. ],
  97. },
  98. ],
  99. // TODO(@anonrig): Remove this from eslint-sentry-config
  100. 'space-infix-ops': 'off',
  101. 'object-shorthand': 'off',
  102. 'object-curly-spacing': 'off',
  103. 'import/no-amd': 'off',
  104. 'no-danger-with-children': 'off',
  105. 'no-fallthrough': 'off',
  106. 'no-obj-calls': 'off',
  107. 'array-bracket-spacing': 'off',
  108. 'computed-property-spacing': 'off',
  109. 'react/no-danger-with-children': 'off',
  110. 'jest/no-disabled-tests': 'off',
  111. },
  112. // JSON file formatting is handled by Biome. ESLint should not be linting
  113. // and formatting these files.
  114. ignorePatterns: ['*.json'],
  115. overrides: [
  116. {
  117. files: ['static/app/components/devtoolbar/**/*.{ts,tsx}'],
  118. rules: {
  119. 'no-restricted-imports': [
  120. 'error',
  121. {
  122. paths: [
  123. {
  124. name: 'sentry/utils/queryClient',
  125. message:
  126. 'Import from `@tanstack/react-query` and `./hooks/useFetchApiData` or `./hooks/useFetchInfiniteApiData` instead.',
  127. },
  128. ],
  129. },
  130. ],
  131. },
  132. },
  133. {
  134. files: ['static/**/*.spec.{ts,js}', 'tests/js/**/*.{ts,js}'],
  135. extends: ['plugin:testing-library/react', 'sentry-app/strict'],
  136. rules: {
  137. // TODO(@anonrig): Remove this from eslint-sentry-config
  138. 'space-infix-ops': 'off',
  139. 'object-shorthand': 'off',
  140. 'object-curly-spacing': 'off',
  141. 'import/no-amd': 'off',
  142. 'no-danger-with-children': 'off',
  143. 'no-fallthrough': 'off',
  144. 'no-obj-calls': 'off',
  145. 'array-bracket-spacing': 'off',
  146. 'computed-property-spacing': 'off',
  147. 'react/no-danger-with-children': 'off',
  148. 'jest/no-disabled-tests': 'off',
  149. },
  150. },
  151. {
  152. // We specify rules explicitly for the sdk-loader here so we do not have
  153. // eslint ignore comments included in the source file, which is consumed
  154. // by users.
  155. files: ['**/js-sdk-loader.ts'],
  156. rules: {
  157. 'no-console': 'off',
  158. },
  159. },
  160. ],
  161. };