|
| 1 | +module.exports = { |
| 2 | + root: true, |
| 3 | + env: { |
| 4 | + node: true, |
| 5 | + }, |
| 6 | + extends: ['prettier', 'eslint:recommended'], |
| 7 | + plugins: ['sentry-sdk', 'jsdoc'], |
| 8 | + ignorePatterns: ['eslint-plugin-sentry-sdk'], |
| 9 | + overrides: [ |
| 10 | + { |
| 11 | + // Configuration for JavaScript files |
| 12 | + files: ['*.js'], |
| 13 | + rules: { |
| 14 | + 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 15 | + }, |
| 16 | + }, |
| 17 | + { |
| 18 | + // Configuration for typescript files |
| 19 | + files: ['*.ts', '*.tsx', '*.d.ts'], |
| 20 | + extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'], |
| 21 | + plugins: ['@typescript-eslint'], |
| 22 | + parser: '@typescript-eslint/parser', |
| 23 | + parserOptions: { |
| 24 | + project: './tsconfig.json', |
| 25 | + }, |
| 26 | + rules: { |
| 27 | + // Unused variables should be removed unless they are marked with and underscore (ex. _varName). |
| 28 | + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], |
| 29 | + |
| 30 | + // Make sure that all ts-ignore comments are given a description. |
| 31 | + '@typescript-eslint/ban-ts-comment': [ |
| 32 | + 'warn', |
| 33 | + { |
| 34 | + 'ts-ignore': 'allow-with-description', |
| 35 | + }, |
| 36 | + ], |
| 37 | + |
| 38 | + // Types usage should be explicit as possible, so we prevent usage of inferrable types. |
| 39 | + // This is especially important because we have a public API, so usage needs to be as |
| 40 | + // easy to understand as possible. |
| 41 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 42 | + |
| 43 | + // Enforce type annotations to maintain consistency. This is especially important as |
| 44 | + // we have a public API, so we want changes to be very explicit. |
| 45 | + '@typescript-eslint/typedef': ['error', { arrowParameter: false }], |
| 46 | + '@typescript-eslint/explicit-function-return-type': 'error', |
| 47 | + |
| 48 | + // Consistent ordering of fields, methods and constructors for classes should be enforced |
| 49 | + '@typescript-eslint/member-ordering': 'error', |
| 50 | + |
| 51 | + // Enforce that unbound methods are called within an expected scope. As we frequently pass data between classes |
| 52 | + // in SDKs, we should make sure that we are correctly preserving class scope. |
| 53 | + '@typescript-eslint/unbound-method': 'error', |
| 54 | + |
| 55 | + // Private and protected members of a class should be prefixed with a leading underscore |
| 56 | + '@typescript-eslint/naming-convention': [ |
| 57 | + 'error', |
| 58 | + { |
| 59 | + selector: 'memberLike', |
| 60 | + modifiers: ['private'], |
| 61 | + format: ['camelCase'], |
| 62 | + leadingUnderscore: 'require', |
| 63 | + }, |
| 64 | + { |
| 65 | + selector: 'memberLike', |
| 66 | + modifiers: ['protected'], |
| 67 | + format: ['camelCase'], |
| 68 | + leadingUnderscore: 'require', |
| 69 | + }, |
| 70 | + ], |
| 71 | + }, |
| 72 | + }, |
| 73 | + { |
| 74 | + // Configuration for files under src |
| 75 | + files: ['src/**/*'], |
| 76 | + rules: { |
| 77 | + // We want to prevent async await usage in our files to prevent uncessary bundle size. |
| 78 | + 'sentry-sdk/no-async-await': 'error', |
| 79 | + |
| 80 | + // JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation, |
| 81 | + // even if it may seems excessive at times, is important to emphasize. Turned off in tests. |
| 82 | + 'jsdoc/require-jsdoc': [ |
| 83 | + 'error', |
| 84 | + { require: { ClassDeclaration: true, MethodDefinition: true }, checkConstructors: false }, |
| 85 | + ], |
| 86 | + }, |
| 87 | + }, |
| 88 | + { |
| 89 | + // Configuration for test files |
| 90 | + env: { |
| 91 | + jest: true, |
| 92 | + }, |
| 93 | + files: ['*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'], |
| 94 | + rules: { |
| 95 | + 'max-lines': 'off', |
| 96 | + }, |
| 97 | + }, |
| 98 | + { |
| 99 | + // Configuration for config files like webpack/rollback |
| 100 | + files: ['*.config.js'], |
| 101 | + parserOptions: { |
| 102 | + sourceType: 'module', |
| 103 | + ecmaVersion: 2018, |
| 104 | + }, |
| 105 | + }, |
| 106 | + ], |
| 107 | + |
| 108 | + rules: { |
| 109 | + // We want to prevent usage of unary operators outside of for loops |
| 110 | + 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], |
| 111 | + |
| 112 | + // Disallow usage of console and alert |
| 113 | + 'no-console': 'error', |
| 114 | + 'no-alert': 'error', |
| 115 | + |
| 116 | + // Prevent reassignment of function parameters, but still allow object properties to be |
| 117 | + // reassigned. We want to enforce immutability when possible, but we shouldn't sacrifice |
| 118 | + // too much efficiency |
| 119 | + 'no-param-reassign': ['error', { props: false }], |
| 120 | + |
| 121 | + // Prefer use of template expression over string literal concatenation |
| 122 | + 'prefer-template': 'error', |
| 123 | + |
| 124 | + // Limit maximum file size to reduce complexity. Turned off in tests. |
| 125 | + 'max-lines': 'error', |
| 126 | + }, |
| 127 | +}; |
0 commit comments