.eslintrc.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* eslint-env node */
  2. const isRelaxed = !!process.env.SENTRY_ESLINT_RELAXED;
  3. const isCi = !!process.env.CI;
  4. // Strict ruleset that runs on pre-commit and in local environments
  5. const ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR =
  6. '(useEffectAfterFirstRender|useMemoWithPrevious)';
  7. const strictRulesNotCi = {
  8. 'react-hooks/exhaustive-deps': [
  9. 'error',
  10. {additionalHooks: ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR},
  11. ],
  12. };
  13. module.exports = {
  14. root: true,
  15. extends: [isRelaxed ? 'sentry-app' : 'sentry-app/strict'],
  16. globals: {
  17. require: false,
  18. expect: false,
  19. sinon: false,
  20. MockApiClient: true,
  21. tick: true,
  22. jest: true,
  23. },
  24. rules: {
  25. 'react-hooks/exhaustive-deps': [
  26. 'warn',
  27. {additionalHooks: ADDITIONAL_HOOKS_TO_CHECK_DEPS_FOR},
  28. ],
  29. ...(!isRelaxed && !isCi ? strictRulesNotCi : {}),
  30. // TODO(@anonrig): Remove these rules from eslint-sentry-config.
  31. 'import/no-nodejs-modules': 'off',
  32. semi: 'off',
  33. 'use-isnan': 'off',
  34. curly: 'off',
  35. eqeqeq: 'off',
  36. 'no-extra-semi': 'off',
  37. 'no-eq-null': 'off',
  38. 'comma-dangle': 'off',
  39. 'react/jsx-no-target-blank': 'off',
  40. 'react/jsx-no-duplicate-props': 'off',
  41. 'react-hooks/rules-of-hooks': 'off',
  42. 'no-duplicate-case': 'off',
  43. 'no-dupe-keys': 'off',
  44. 'no-redeclare': 'off',
  45. 'no-debugger': 'off',
  46. 'no-unreachable': 'off',
  47. },
  48. // JSON file formatting is handled by Biome. ESLint should not be linting
  49. // and formatting these files.
  50. ignorePatterns: ['*.json'],
  51. overrides: [
  52. {
  53. files: ['tests/js/**/*.{ts,js}'],
  54. extends: ['plugin:testing-library/react', 'sentry-app/strict'],
  55. rules: {
  56. // TODO(@anonrig): Remove these rules from eslint-sentry-config.
  57. 'import/no-nodejs-modules': 'off',
  58. semi: 'off',
  59. 'use-isnan': 'off',
  60. curly: 'off',
  61. eqeqeq: 'off',
  62. 'no-extra-semi': 'off',
  63. 'no-eq-null': 'off',
  64. 'comma-dangle': 'off',
  65. 'react/jsx-no-target-blank': 'off',
  66. 'react/jsx-no-duplicate-props': 'off',
  67. 'react-hooks/rules-of-hooks': 'off',
  68. 'no-duplicate-case': 'off',
  69. 'no-dupe-keys': 'off',
  70. 'no-redeclare': 'off',
  71. 'no-debugger': 'off',
  72. 'no-unreachable': 'off',
  73. },
  74. },
  75. {
  76. files: ['*.ts', '*.tsx'],
  77. rules: {},
  78. },
  79. {
  80. // We specify rules explicitly for the sdk-loader here so we do not have
  81. // eslint ignore comments included in the source file, which is consumed
  82. // by users.
  83. files: ['**/js-sdk-loader.ts'],
  84. rules: {
  85. 'no-console': 'off',
  86. },
  87. },
  88. ],
  89. };