Skip to content

Commit e27ef81

Browse files
crnhrvljharb
authored andcommitted
[Fix] prop-types: null-check rootNode before calling getScope
1 parent 417e1ca commit e27ef81

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv)
10+
11+
[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762
12+
813
## [7.34.2] - 2024.05.24
914

1015
### Fixed

lib/util/propTypes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
372372
*/
373373
function resolveValueForIdentifierNode(node, rootNode, callback) {
374374
if (
375-
node
375+
rootNode
376+
&& node
376377
&& node.type === 'Identifier'
377378
) {
378379
const scope = getScope(context, rootNode);

tests/lib/rules/prop-types.js

+34
Original file line numberDiff line numberDiff line change
@@ -3361,6 +3361,20 @@ ruleTester.run('prop-types', rule, {
33613361
`,
33623362
features: ['ts', 'no-babel'],
33633363
},
3364+
{
3365+
code: `
3366+
import React from "react";
3367+
3368+
const returnTypeProp = (someProp: any) => ({ someProp });
3369+
3370+
const SomeComponent: React.FunctionComponent<
3371+
ReturnType<typeof returnTypeProp>
3372+
> = ({ someProp }) => {
3373+
return <div>{someProp}</div>;
3374+
};
3375+
`,
3376+
features: ['ts', 'no-babel'],
3377+
},
33643378
{
33653379
code: `
33663380
export const EuiSuperSelectControl: <T extends string>(
@@ -7840,6 +7854,26 @@ ruleTester.run('prop-types', rule, {
78407854
],
78417855
features: ['ts', 'no-babel'],
78427856
},
7857+
{
7858+
code: `
7859+
import React from "react";
7860+
7861+
const returnTypeProp = (someProp: any) => ({ someProp });
7862+
7863+
const SomeComponent: React.FunctionComponent<
7864+
ReturnType<typeof returnTypeProp>
7865+
> = ({ someIncorrectProp }) => {
7866+
return <div>{someProp}</div>;
7867+
};
7868+
`,
7869+
errors: [
7870+
{
7871+
messageId: 'missingPropType',
7872+
data: { name: 'someIncorrectProp' },
7873+
},
7874+
],
7875+
features: ['ts', 'no-babel'],
7876+
},
78437877
{
78447878
code: `
78457879
import React from 'react';

0 commit comments

Comments
 (0)