.eslintrc.js 5.4 KB

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