|
| 1 | +const stylistic = require('@stylistic/eslint-plugin'); |
| 2 | +const js = require('@eslint/js'); |
| 3 | +const tseslint = require('typescript-eslint'); |
| 4 | + |
| 5 | +const ts = require('@typescript-eslint/eslint-plugin'); |
| 6 | +const tsParser = require('@typescript-eslint/parser'); |
| 7 | +// When it works again do `npm install --save-dev eslint-plugin-import` |
| 8 | +// const imprt = require('eslint-plugin-import'); |
| 9 | +// https://github.com/eslint/eslint/issues/18087 |
| 10 | +// https://github.com/import-js/eslint-plugin-import/pull/2829 |
| 11 | +const globals = require('globals'); |
| 12 | +const jest = require('eslint-plugin-jest'); |
| 13 | +const off = 'off'; |
| 14 | + |
| 15 | +const warn = 'warn'; |
| 16 | + |
| 17 | +const error = 'error'; |
| 18 | + |
| 19 | +// const TEST_ONLY_IMPORTS = ['fast-check', 'jest']; |
| 20 | + |
| 21 | +/** |
| 22 | + * set of typescript-eslint any rules |
| 23 | + * @param {'error' | 'warn' | 'off'} level |
| 24 | + * @returns |
| 25 | + */ |
| 26 | +const any_rules = (level) => { |
| 27 | + return { |
| 28 | + '@typescript-eslint/no-unsafe-return': level, |
| 29 | + '@typescript-eslint/no-var-requires': level, |
| 30 | + '@typescript-eslint/no-unsafe-member-access': level, |
| 31 | + '@typescript-eslint/no-unsafe-assignment': level, |
| 32 | + '@typescript-eslint/no-unsafe-argument': level, |
| 33 | + '@typescript-eslint/no-unsafe-call': level, |
| 34 | + '@typescript-eslint/no-explicit-any': level, |
| 35 | + }; |
| 36 | +}; |
| 37 | + |
| 38 | +module.exports = [ |
| 39 | + js.configs.recommended, |
| 40 | + ...tseslint.configs.recommended, |
| 41 | + { |
| 42 | + languageOptions: { |
| 43 | + globals: globals.node, |
| 44 | + parser: tsParser, |
| 45 | + parserOptions: { |
| 46 | + ecmaVersion: 2022, |
| 47 | + sourceType: 'module', |
| 48 | + tsconfigRootDir: __dirname, |
| 49 | + project: [ |
| 50 | + './tsconfig.eslint.json', |
| 51 | + './tsconfig.json', |
| 52 | + '/tsconfig.prod.json', |
| 53 | + ], |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + stylistic.configs['recommended-flat'], |
| 58 | + stylistic.configs.customize({ |
| 59 | + // the following options are the default values |
| 60 | + semi: true, |
| 61 | + }), |
| 62 | + { |
| 63 | + languageOptions: { parser: tsParser }, |
| 64 | + plugins: { |
| 65 | + // 'import': imprt, |
| 66 | + '@stylistic': stylistic, |
| 67 | + ts, |
| 68 | + }, |
| 69 | + }, |
| 70 | + { |
| 71 | + ignores: [ |
| 72 | + '**/node_modules', |
| 73 | + '**/dist', |
| 74 | + '**/build', |
| 75 | + '**/__snapshots__', |
| 76 | + '**/mocks', |
| 77 | + '**/coverage', |
| 78 | + '**/report', |
| 79 | + ], |
| 80 | + }, |
| 81 | + { |
| 82 | + rules: { |
| 83 | + ...ts.configs['eslint-recommended'].rules, |
| 84 | + ...ts.configs['recommended'].rules, |
| 85 | + ...ts.configs['recommended-requiring-type-checking'].rules, |
| 86 | + // ...imprt.configs['errors'].rules, |
| 87 | + // ...imprt.configs['warnings'].rules, |
| 88 | + // ...imprt.configs['typescript'].rules, |
| 89 | + // "import/no-extraneous-dependencies": error, |
| 90 | + 'no-console': error, |
| 91 | + '@typescript-eslint/return-await': ['error', 'always'], |
| 92 | + 'no-unused-vars': off, |
| 93 | + '@typescript-eslint/no-unused-vars': error, |
| 94 | + 'eqeqeq': [error, 'smart'], |
| 95 | + 'no-else-return': [ |
| 96 | + error, |
| 97 | + { |
| 98 | + allowElseIf: true, |
| 99 | + }, |
| 100 | + ], |
| 101 | + '@typescript-eslint/require-await': error, |
| 102 | + '@typescript-eslint/unbound-method': [ |
| 103 | + error, |
| 104 | + { |
| 105 | + ignoreStatic: true, |
| 106 | + }, |
| 107 | + ], |
| 108 | + // See https://github.com/orgs/react-hook-form/discussions/8622#discussioncomment-4060570 |
| 109 | + '@typescript-eslint/no-misused-promises': [ |
| 110 | + error, |
| 111 | + { |
| 112 | + checksVoidReturn: { |
| 113 | + attributes: false, |
| 114 | + }, |
| 115 | + }, |
| 116 | + ], |
| 117 | + // 'no-restricted-imports': [ |
| 118 | + // 'error', |
| 119 | + // { |
| 120 | + // paths: TEST_ONLY_IMPORTS.map((name) => { |
| 121 | + // return { name, |
| 122 | + // message: `${name} is only available during testing` }; |
| 123 | + // }), |
| 124 | + // patterns: TEST_ONLY_IMPORTS.map(dep => `${dep}/*`), |
| 125 | + // }, |
| 126 | + // ], |
| 127 | + '@typescript-eslint/explicit-member-accessibility': warn, |
| 128 | + '@typescript-eslint/no-explicit-any': warn, |
| 129 | + '@typescript-eslint/explicit-function-return-type': off, |
| 130 | + // '@typescript-eslint/no-var-requires': off, |
| 131 | + '@typescript-eslint/no-empty-function': off, |
| 132 | + '@typescript-eslint/no-floating-promises': error, |
| 133 | + }, |
| 134 | + }, |
| 135 | + { |
| 136 | + files: ['.*.js', '.*.cjs', '*.config.cjs', '*.config.js', '*.config.ts'], |
| 137 | + rules: { |
| 138 | + 'no-restricted-imports': off, |
| 139 | + // Consider if this is too leanient for tests |
| 140 | + ...any_rules('off'), |
| 141 | + }, |
| 142 | + }, |
| 143 | + { |
| 144 | + files: [ |
| 145 | + '**/*.test.js', |
| 146 | + '**/*.spec.js', |
| 147 | + '**/*.test.ts', |
| 148 | + '**/*.spec.ts', |
| 149 | + 'tests/**/*.js', |
| 150 | + 'tests/**/*.ts', |
| 151 | + '__tests__/**/*.js', |
| 152 | + '__tests__/**/*.ts', |
| 153 | + 'jest.*.js', |
| 154 | + 'jest.*.ts', |
| 155 | + ], |
| 156 | + // https://eslint.org/docs/user-guide/configuring#specifying-environments |
| 157 | + languageOptions: { globals: globals.jest }, |
| 158 | + plugins: { jest }, |
| 159 | + rules: { |
| 160 | + ...jest.configs['recommended'].rules, |
| 161 | + // 'no-restricted-imports': off, |
| 162 | + 'jest/expect-expect': [ |
| 163 | + error, |
| 164 | + { |
| 165 | + assertFunctionNames: ['expect', 'fc.assert'], |
| 166 | + }, |
| 167 | + ], |
| 168 | + ...any_rules('off'), |
| 169 | + }, |
| 170 | + }, |
| 171 | +]; |
0 commit comments