Skip to content

Commit 210865e

Browse files
vedadeeptaljharb
authored andcommitted
[Fix] propTypes: add VoidFunctionComponent to react generic list
1 parent 783d4cd commit 210865e

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
99
* [`no-unused-class-component-methods`]: Handle unused class component methods ([#2166][] @jakeleventhal @pawelnvk)
1010
* add [`no-arrow-function-lifecycle`] ([#1980][] @ngtan)
1111

12+
### Fixed
13+
* [`propTypes`]: add `VoidFunctionComponent` to react generic list ([#3092][] @vedadeepta)
14+
15+
[#3092]: https://github.com/yannickcr/eslint-plugin-react/pull/3092
1216
[#2166]: https://github.com/yannickcr/eslint-plugin-react/pull/2166
1317
[#1980]: https://github.com/yannickcr/eslint-plugin-react/pull/1980
1418

lib/util/propTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
100100
const defaults = {customValidators: []};
101101
const configuration = Object.assign({}, defaults, context.options[0] || {});
102102
const customValidators = configuration.customValidators;
103-
const allowedGenericTypes = new Set(['PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
103+
const allowedGenericTypes = new Set(['VoidFunctionComponent', 'PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
104104
const genericReactTypesImport = new Set();
105105

106106
/**

tests/lib/rules/prop-types.js

+72
Original file line numberDiff line numberDiff line change
@@ -3317,6 +3317,36 @@ ruleTester.run('prop-types', rule, {
33173317
};
33183318
`,
33193319
parser: parsers['@TYPESCRIPT_ESLINT']
3320+
},
3321+
{
3322+
code: `
3323+
import React, { VoidFunctionComponent } from 'react'
3324+
3325+
interface Props {
3326+
age: number
3327+
}
3328+
const Hello: VoidFunctionComponent<Props> = function Hello(props) {
3329+
const { age } = props;
3330+
3331+
return <div>Hello {age}</div>;
3332+
}
3333+
`,
3334+
parser: parsers['@TYPESCRIPT_ESLINT']
3335+
},
3336+
{
3337+
code: `
3338+
import React from 'react'
3339+
3340+
interface Props {
3341+
age: number
3342+
}
3343+
const Hello: React.VoidFunctionComponent<Props> = function Hello(props) {
3344+
const { age } = props;
3345+
3346+
return <div>Hello {age}</div>;
3347+
}
3348+
`,
3349+
parser: parsers['@TYPESCRIPT_ESLINT']
33203350
}
33213351
]),
33223352
{
@@ -6896,6 +6926,48 @@ ruleTester.run('prop-types', rule, {
68966926
}
68976927
],
68986928
parser: parsers['@TYPESCRIPT_ESLINT']
6929+
},
6930+
{
6931+
code: `
6932+
import React, { VoidFunctionComponent } from 'react'
6933+
6934+
interface Props {
6935+
age: number
6936+
}
6937+
const Hello: VoidFunctionComponent<Props> = function Hello(props) {
6938+
const { test } = props;
6939+
6940+
return <div>Hello {name}</div>;
6941+
}
6942+
`,
6943+
errors: [
6944+
{
6945+
messageId: 'missingPropType',
6946+
data: {name: 'test'}
6947+
}
6948+
],
6949+
parser: parsers['@TYPESCRIPT_ESLINT']
6950+
},
6951+
{
6952+
code: `
6953+
import React from 'react'
6954+
6955+
interface Props {
6956+
age: number
6957+
}
6958+
const Hello: React.VoidFunctionComponent<Props> = function Hello(props) {
6959+
const { test } = props;
6960+
6961+
return <div>Hello {name}</div>;
6962+
}
6963+
`,
6964+
errors: [
6965+
{
6966+
messageId: 'missingPropType',
6967+
data: {name: 'test'}
6968+
}
6969+
],
6970+
parser: parsers['@TYPESCRIPT_ESLINT']
68996971
}
69006972
])
69016973
)

0 commit comments

Comments
 (0)