|
| 1 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 2 | +import js from '@eslint/js'; |
| 3 | +import tsEslintPlugin from '@typescript-eslint/eslint-plugin'; |
| 4 | +import { createRequire } from 'node:module'; |
| 5 | +import path from 'node:path'; |
| 6 | +import { fileURLToPath } from 'node:url'; |
| 7 | + |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = path.dirname(__filename); |
| 10 | +const require = createRequire(import.meta.url); |
| 11 | + |
| 12 | +const compat = new FlatCompat({ |
| 13 | + baseDirectory: __dirname, |
| 14 | + recommendedConfig: js.configs.recommended, |
| 15 | + allConfig: js.configs.all, |
| 16 | +}); |
| 17 | + |
| 18 | +const supportedTsRules = new Set( |
| 19 | + Object.keys(tsEslintPlugin.rules).map(ruleName => `@typescript-eslint/${ruleName}`), |
| 20 | +); |
| 21 | + |
| 22 | +function normalizeConfig(config) { |
| 23 | + const next = { ...config }; |
| 24 | + |
| 25 | + if (next.rules) { |
| 26 | + next.rules = Object.fromEntries( |
| 27 | + Object.entries(next.rules).filter(([ruleName]) => { |
| 28 | + if (ruleName.startsWith('@babel/')) { |
| 29 | + return false; |
| 30 | + } |
| 31 | + return !ruleName.startsWith('@typescript-eslint/') || supportedTsRules.has(ruleName); |
| 32 | + }), |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + return next; |
| 37 | +} |
| 38 | + |
| 39 | +export default [ |
| 40 | + { |
| 41 | + ignores: [ |
| 42 | + 'node_modules/', |
| 43 | + 'coverage/', |
| 44 | + 'es/', |
| 45 | + 'lib/', |
| 46 | + 'dist/', |
| 47 | + 'docs-dist/', |
| 48 | + '.dumi/', |
| 49 | + '.doc/', |
| 50 | + '.vercel/', |
| 51 | + '.eslintrc.js', |
| 52 | + ], |
| 53 | + }, |
| 54 | + ...compat.config(require('./.eslintrc.js')).map(normalizeConfig), |
| 55 | + { |
| 56 | + rules: { |
| 57 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 58 | + '@typescript-eslint/no-unsafe-function-type': 'off', |
| 59 | + '@typescript-eslint/no-unused-vars': 'off', |
| 60 | + '@typescript-eslint/no-useless-constructor': 'off', |
| 61 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 62 | + }, |
| 63 | + }, |
| 64 | +]; |
0 commit comments