|
| 1 | +const off = 'off'; |
| 2 | + |
| 3 | +const warn = 'warn'; |
| 4 | + |
| 5 | +const error = 'error'; |
| 6 | + |
| 7 | +const TEST_ONLY_IMPORTS = ['fast-check', 'jest', 'eslint', 'prettier']; |
| 8 | + |
| 9 | +module.exports = { |
| 10 | + extends: [ |
| 11 | + 'eslint:recommended', |
| 12 | + 'plugin:@typescript-eslint/eslint-recommended', |
| 13 | + 'plugin:@typescript-eslint/recommended', |
| 14 | + 'plugin:@typescript-eslint/recommended-requiring-type-checking', |
| 15 | + 'plugin:prettier/recommended', |
| 16 | + 'plugin:import/errors', |
| 17 | + 'plugin:import/warnings', |
| 18 | + 'plugin:import/typescript', |
| 19 | + ], |
| 20 | + env: { |
| 21 | + node: true, |
| 22 | + }, |
| 23 | + plugins: ['@typescript-eslint/eslint-plugin'], |
| 24 | + parser: '@typescript-eslint/parser', |
| 25 | + parserOptions: { |
| 26 | + ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features |
| 27 | + sourceType: 'module', // Allows for the use of imports |
| 28 | + tsconfigRootDir: __dirname, |
| 29 | + project: ['./tsconfig.eslint.json'], |
| 30 | + }, |
| 31 | + rules: { |
| 32 | + 'import/no-extraneous-dependencies': warn, |
| 33 | + // Temporal? |
| 34 | + 'no-console': warn, |
| 35 | + 'no-return-await': warn, |
| 36 | + 'no-unused-vars': warn, |
| 37 | + eqeqeq: [error, 'smart'], |
| 38 | + 'no-else-return': [ |
| 39 | + error, |
| 40 | + { |
| 41 | + allowElseIf: true, |
| 42 | + }, |
| 43 | + ], |
| 44 | + '@typescript-eslint/unbound-method': [ |
| 45 | + error, |
| 46 | + { |
| 47 | + ignoreStatic: true, |
| 48 | + }, |
| 49 | + ], |
| 50 | + 'no-restricted-imports': [ |
| 51 | + 'error', |
| 52 | + { |
| 53 | + paths: TEST_ONLY_IMPORTS.map((name) => { |
| 54 | + return { name, message: `${name} is only available during testing` }; |
| 55 | + }), |
| 56 | + patterns: TEST_ONLY_IMPORTS.map((dep) => `${dep}/*`), |
| 57 | + }, |
| 58 | + ], |
| 59 | + camelcase: off, |
| 60 | + '@typescript-eslint/camelcase': off, |
| 61 | + 'require-await': off, |
| 62 | + '@typescript-eslint/require-await': off, |
| 63 | + '@typescript-eslint/indent': off, |
| 64 | + '@typescript-eslint/explicit-member-accessibility': warn, |
| 65 | + '@typescript-eslint/no-explicit-any': off, |
| 66 | + '@typescript-eslint/no-var-requires': off, |
| 67 | + '@typescript-eslint/no-empty-function': off, |
| 68 | + '@typescript-eslint/no-object-literal-type-assertion': off, |
| 69 | + '@typescript-eslint/no-floating-promises': error, |
| 70 | + }, |
| 71 | + overrides: [ |
| 72 | + { |
| 73 | + files: ['*.ts', '*.tsx'], |
| 74 | + rules: { |
| 75 | + '@typescript-eslint/explicit-function-return-type': [ |
| 76 | + error, |
| 77 | + { |
| 78 | + allowExpressions: true, |
| 79 | + allowTypedFunctionExpressions: true, |
| 80 | + allowHigherOrderFunctions: true, |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | + }, |
| 85 | + { |
| 86 | + // TESTING CONFIGURATION |
| 87 | + files: [ |
| 88 | + '**/*.test.js', |
| 89 | + '**/*.spec.js', |
| 90 | + '**/*.test.ts', |
| 91 | + '**/*.spec.ts', |
| 92 | + 'tests/**/*.js', |
| 93 | + 'tests/**/*.ts', |
| 94 | + '__tests__/**/*.js', |
| 95 | + '__tests__/**/*.ts', |
| 96 | + 'jest.setup.js', |
| 97 | + ], |
| 98 | + |
| 99 | + // https://eslint.org/docs/user-guide/configuring#specifying-environments |
| 100 | + env: { |
| 101 | + jest: true, |
| 102 | + }, |
| 103 | + |
| 104 | + // Can't extend in overrides: https://github.com/eslint/eslint/issues/8813 |
| 105 | + // "extends": ["plugin:jest/recommended"] |
| 106 | + plugins: ['jest'], |
| 107 | + rules: { |
| 108 | + 'jest/no-disabled-tests': warn, |
| 109 | + 'jest/no-focused-tests': error, |
| 110 | + 'jest/no-identical-title': error, |
| 111 | + 'jest/prefer-to-have-length': warn, |
| 112 | + 'jest/valid-expect': error, |
| 113 | + }, |
| 114 | + }, |
| 115 | + ], |
| 116 | +}; |
0 commit comments