Skip to content

Commit bff1c24

Browse files
committed
fix(config/eslint): only set react/prop-types for React projects
1 parent d99b931 commit bff1c24

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/config/helpers/eslint.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ const prettier = withBaseConfig('eslint-config-prettier')
1111

1212
const hasReact = hasAnyDep('react')
1313

14-
const parserRules = (typescript = false) => {
14+
const parserRules = (typescript = false, react = false) => {
1515
const isOff = off => (off ? 'off' : 'error')
1616

17+
const propTypes = react ? {'react/prop-types': isOff(typescript)} : {}
18+
1719
return {
1820
'no-implied-eval': isOff(typescript),
1921
'no-throw-literal': isOff(typescript),
2022
'@typescript-eslint/no-implied-eval': isOff(!typescript),
2123
'@typescript-eslint/no-throw-literal': isOff(!typescript),
22-
'react/prop-types': isOff(typescript),
24+
...propTypes,
2325
}
2426
}
2527

2628
const buildConfig = ({withReact = false} = {}) => {
27-
const ifReact = (t, f) => (withReact || hasReact ? t : f)
29+
const isReact = withReact || hasReact
30+
const ifReact = (t, f) => (isReact ? t : f)
2831

2932
return {
3033
plugins: ['prettier', 'jest', ifReact('react-hooks')].filter(Boolean),
@@ -52,7 +55,7 @@ const buildConfig = ({withReact = false} = {}) => {
5255
optionalDependencies: false,
5356
},
5457
],
55-
...parserRules(),
58+
...parserRules(false, isReact),
5659
},
5760
overrides: [
5861
{
@@ -61,7 +64,7 @@ const buildConfig = ({withReact = false} = {}) => {
6164
'plugin:@typescript-eslint/recommended-requiring-type-checking',
6265
],
6366
rules: {
64-
...parserRules(true),
67+
...parserRules(true, isReact),
6568
},
6669
},
6770
{

0 commit comments

Comments
 (0)