|
| 1 | +const {rules} = require('eslint-config-airbnb-typescript/lib/shared') |
| 2 | + |
| 3 | +const {hasAnyDep} = require('../../utils') |
| 4 | +const {testMatch} = require('../jest.config') |
| 5 | + |
| 6 | +const withBaseConfig = base => variant => |
| 7 | + require.resolve(base + (variant ? `/${variant}` : '')) |
| 8 | + |
| 9 | +const airbnb = withBaseConfig('eslint-config-airbnb-typescript') |
| 10 | +const prettier = withBaseConfig('eslint-config-prettier') |
| 11 | + |
| 12 | +const hasReact = hasAnyDep('react') |
| 13 | + |
| 14 | +const buildConfig = ({withReact = false} = {}) => { |
| 15 | + const ifReact = (t, f) => (withReact || hasReact ? t : f) |
| 16 | + |
| 17 | + return { |
| 18 | + plugins: ['prettier', 'jest', ifReact('react-hooks')].filter(Boolean), |
| 19 | + extends: [ |
| 20 | + ifReact(airbnb(), airbnb('base')), |
| 21 | + 'plugin:jest/recommended', |
| 22 | + prettier(), |
| 23 | + prettier('@typescript-eslint'), |
| 24 | + ifReact(prettier('react')), |
| 25 | + ].filter(Boolean), |
| 26 | + rules: { |
| 27 | + 'prettier/prettier': 'error', |
| 28 | + 'import/prefer-default-export': 'off', |
| 29 | + 'import/no-extraneous-dependencies': [ |
| 30 | + 'error', |
| 31 | + { |
| 32 | + devDependencies: rules[ |
| 33 | + 'import/no-extraneous-dependencies' |
| 34 | + ][1].devDependencies.concat('jest/**'), |
| 35 | + optionalDependencies: false, |
| 36 | + }, |
| 37 | + ], |
| 38 | + }, |
| 39 | + overrides: [ |
| 40 | + { |
| 41 | + files: testMatch, |
| 42 | + rules: { |
| 43 | + 'no-empty': ['error', {allowEmptyCatch: true}], |
| 44 | + }, |
| 45 | + }, |
| 46 | + ], |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +module.exports = {buildConfig} |
0 commit comments