Skip to content

Commit d9531c3

Browse files
committed
propTypes: add VFC to react generic list
Fixes #3230
1 parent d8602ac commit d9531c3

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99
* [`no-unused-state`]: avoid a crash on type-only gDSFP declarations ([#3225][] @ljharb)
1010
* [`jsx-curly-brace-presence`]: the string "never" defaults to `propElementValues` as `ignore` ([#3228][] @ljharb)
11+
* [`propTypes`]: add `VFC` to react generic list ([#3230][] @ljharb)
1112

13+
[#3230]: https://github.com/yannickcr/eslint-plugin-react/issues/3230
1214
[#3228]: https://github.com/yannickcr/eslint-plugin-react/issues/3228
1315
[#3225]: https://github.com/yannickcr/eslint-plugin-react/issues/3225
1416

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(['forwardRef', 'ForwardRefRenderFunction', 'VoidFunctionComponent', 'PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
103+
const allowedGenericTypes = new Set(['forwardRef', 'ForwardRefRenderFunction', 'VFC', 'VoidFunctionComponent', 'PropsWithChildren', 'SFC', 'StatelessComponent', 'FunctionComponent', 'FC']);
104104
const genericTypeParamIndexWherePropsArePresent = {
105105
ForwardRefRenderFunction: 1,
106106
forwardRef: 1,

tests/lib/rules/prop-types.js

+61
Original file line numberDiff line numberDiff line change
@@ -7746,6 +7746,27 @@ ruleTester.run('prop-types', rule, {
77467746
],
77477747
features: ['ts', 'no-babel'],
77487748
},
7749+
{
7750+
code: `
7751+
import React, { VFC } from 'react'
7752+
7753+
interface Props {
7754+
age: number
7755+
}
7756+
const Hello: VFC<Props> = function Hello(props) {
7757+
const { test } = props;
7758+
7759+
return <div>Hello {name}</div>;
7760+
}
7761+
`,
7762+
errors: [
7763+
{
7764+
messageId: 'missingPropType',
7765+
data: { name: 'test' },
7766+
},
7767+
],
7768+
features: ['ts', 'no-babel'],
7769+
},
77497770
{
77507771
code: `
77517772
import React from 'react'
@@ -7771,6 +7792,27 @@ ruleTester.run('prop-types', rule, {
77717792
code: `
77727793
import React from 'react'
77737794
7795+
interface Props {
7796+
age: number
7797+
}
7798+
const Hello: React.VFC<Props> = function Hello(props) {
7799+
const { test } = props;
7800+
7801+
return <div>Hello {name}</div>;
7802+
}
7803+
`,
7804+
errors: [
7805+
{
7806+
messageId: 'missingPropType',
7807+
data: { name: 'test' },
7808+
},
7809+
],
7810+
features: ['ts', 'no-babel'],
7811+
},
7812+
{
7813+
code: `
7814+
import React from 'react'
7815+
77747816
type IfooProps = { e: string };
77757817
const Foo: React.ForwardRefRenderFunction<HTMLDivElement, IfooProps> = function Foo (props, ref) {
77767818
const { name } = props;
@@ -7971,6 +8013,25 @@ ruleTester.run('prop-types', rule, {
79718013
],
79728014
features: ['ts', 'no-babel'],
79738015
},
8016+
{
8017+
code: `
8018+
import React from 'react';
8019+
8020+
export interface PersonProps {
8021+
username: string;
8022+
}
8023+
const Person: React.VFC<PersonProps> = (props): React.ReactElement => (
8024+
<div>{props.nonExistent}</div>
8025+
);
8026+
`,
8027+
errors: [
8028+
{
8029+
messageId: 'missingPropType',
8030+
data: { name: 'nonExistent' },
8031+
},
8032+
],
8033+
features: ['ts', 'no-babel'],
8034+
},
79748035
{
79758036
code: `
79768037
const Foo = ({ foo }) => {

0 commit comments

Comments
 (0)