diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d5cd3185..e4bccfaa25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`prop-types`]: null-check rootNode before calling getScope ([#3762][] @crnhrv) + +[#3762]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3762 + ## [7.34.2] - 2024.05.24 ### Fixed diff --git a/lib/util/propTypes.js b/lib/util/propTypes.js index 6f879e2347..22063afb8e 100644 --- a/lib/util/propTypes.js +++ b/lib/util/propTypes.js @@ -372,7 +372,8 @@ module.exports = function propTypesInstructions(context, components, utils) { */ function resolveValueForIdentifierNode(node, rootNode, callback) { if ( - node + rootNode + && node && node.type === 'Identifier' ) { const scope = getScope(context, rootNode); diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index df762d74ef..97206b7d44 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -3361,6 +3361,20 @@ ruleTester.run('prop-types', rule, { `, features: ['ts', 'no-babel'], }, + { + code: ` + import React from "react"; + + const returnTypeProp = (someProp: any) => ({ someProp }); + + const SomeComponent: React.FunctionComponent< + ReturnType + > = ({ someProp }) => { + return
{someProp}
; + }; + `, + features: ['ts', 'no-babel'], + }, { code: ` export const EuiSuperSelectControl: ( @@ -7840,6 +7854,26 @@ ruleTester.run('prop-types', rule, { ], features: ['ts', 'no-babel'], }, + { + code: ` + import React from "react"; + + const returnTypeProp = (someProp: any) => ({ someProp }); + + const SomeComponent: React.FunctionComponent< + ReturnType + > = ({ someIncorrectProp }) => { + return
{someProp}
; + }; + `, + errors: [ + { + messageId: 'missingPropType', + data: { name: 'someIncorrectProp' }, + }, + ], + features: ['ts', 'no-babel'], + }, { code: ` import React from 'react';