.eslintrc.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0 */
  3. const isRelaxed = !!process.env.SENTRY_ESLINT_RELAXED;
  4. const isCi = !!process.env.CI;
  5. // Strict ruleset that runs on pre-commit and in local environments
  6. const ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR =
  7. '(useEffectAfterFirstRender|useMemoWithPrevious)';
  8. const strictRulesNotCi = {
  9. 'react-hooks/exhaustive-deps': [
  10. 'error',
  11. {additionalHooks: ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR},
  12. ],
  13. };
  14. module.exports = {
  15. root: true,
  16. extends: [isRelaxed ? 'sentry-app' : 'sentry-app/strict'],
  17. globals: {
  18. require: false,
  19. expect: false,
  20. sinon: false,
  21. MockApiClient: true,
  22. tick: true,
  23. jest: true,
  24. },
  25. parserOptions: {
  26. project: true,
  27. tsConfigRootDir: __dirname,
  28. },
  29. rules: {
  30. 'react-hooks/exhaustive-deps': [
  31. 'warn',
  32. {additionalHooks: ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR},
  33. ],
  34. ...(!isRelaxed && !isCi ? strictRulesNotCi : {}),
  35. // TODO(@anonrig): Move this to eslint-config-sentry-app
  36. '@typescript-eslint/consistent-type-imports': [
  37. 'error',
  38. {fixStyle: 'separate-type-imports', prefer: 'type-imports'},
  39. ],
  40. '@typescript-eslint/consistent-type-exports': ['error'],
  41. },
  42. // JSON file formatting is handled by Biome. ESLint should not be linting
  43. // and formatting these files.
  44. ignorePatterns: ['*.json'],
  45. overrides: [
  46. {
  47. // Benchmarks are not compiled with the same tsconfig as the rest of the
  48. // app, so we need to disable some rules.
  49. files: ['static/app/**/*.benchmark.ts'],
  50. parserOptions: {
  51. project: false,
  52. },
  53. rules: {
  54. '@typescript-eslint/consistent-type-exports': 'off',
  55. },
  56. },
  57. {
  58. files: ['tests/js/**/*.{ts,js}'],
  59. extends: ['plugin:testing-library/react', 'sentry-app/strict'],
  60. },
  61. {
  62. files: ['*.ts', '*.tsx'],
  63. rules: {},
  64. },
  65. {
  66. // We specify rules explicitly for the sdk-loader here so we do not have
  67. // eslint ignore comments included in the source file, which is consumed
  68. // by users.
  69. files: ['**/js-sdk-loader.ts'],
  70. rules: {
  71. 'no-console': 'off',
  72. },
  73. },
  74. ],
  75. };