Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] propTypes: add VoidFunctionComponent to react generic list #3092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`no-unused-class-component-methods`]: Handle unused class component methods ([#2166][] @jakeleventhal @pawelnvk)
* add [`no-arrow-function-lifecycle`] ([#1980][] @ngtan)

### Fixed
* [`propTypes`]: add `VoidFunctionComponent` to react generic list ([#3092][] @vedadeepta)

[#3092]: https://github.com/yannickcr/eslint-plugin-react/pull/3092
[#2166]: https://github.com/yannickcr/eslint-plugin-react/pull/2166
[#1980]: https://github.com/yannickcr/eslint-plugin-react/pull/1980

Expand Down
2 changes: 1 addition & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module.exports = function propTypesInstructions(context, components, utils) {
const defaults = {customValidators: []};
const configuration = Object.assign({}, defaults, context.options[0] || {});
const customValidators = configuration.customValidators;
const allowedGenericTypes = new Set(['PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
const allowedGenericTypes = new Set(['VoidFunctionComponent', 'PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
const genericReactTypesImport = new Set();

/**
Expand Down
72 changes: 72 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,36 @@ ruleTester.run('prop-types', rule, {
};
`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React, { VoidFunctionComponent } from 'react'

interface Props {
age: number
}
const Hello: VoidFunctionComponent<Props> = function Hello(props) {
const { age } = props;

return <div>Hello {age}</div>;
}
`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React from 'react'

interface Props {
age: number
}
const Hello: React.VoidFunctionComponent<Props> = function Hello(props) {
const { age } = props;

return <div>Hello {age}</div>;
}
`,
parser: parsers['@TYPESCRIPT_ESLINT']
}
]),
{
Expand Down Expand Up @@ -6896,6 +6926,48 @@ ruleTester.run('prop-types', rule, {
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React, { VoidFunctionComponent } from 'react'

interface Props {
age: number
}
const Hello: VoidFunctionComponent<Props> = function Hello(props) {
const { test } = props;

return <div>Hello {name}</div>;
}
`,
errors: [
{
messageId: 'missingPropType',
data: {name: 'test'}
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React from 'react'

interface Props {
age: number
}
const Hello: React.VoidFunctionComponent<Props> = function Hello(props) {
const { test } = props;

return <div>Hello {name}</div>;
}
`,
errors: [
{
messageId: 'missingPropType',
data: {name: 'test'}
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
)
Expand Down