Skip to content

Commit

Permalink
[Fix] prop-types: null-check rootNode before calling getScope
Browse files Browse the repository at this point in the history
  • Loading branch information
crnhrv authored and ljharb committed May 30, 2024
1 parent 417e1ca commit e27ef81
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof returnTypeProp>
> = ({ someProp }) => {
return <div>{someProp}</div>;
};
`,
features: ['ts', 'no-babel'],
},
{
code: `
export const EuiSuperSelectControl: <T extends string>(
Expand Down Expand Up @@ -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<typeof returnTypeProp>
> = ({ someIncorrectProp }) => {
return <div>{someProp}</div>;
};
`,
errors: [
{
messageId: 'missingPropType',
data: { name: 'someIncorrectProp' },
},
],
features: ['ts', 'no-babel'],
},
{
code: `
import React from 'react';
Expand Down

0 comments on commit e27ef81

Please sign in to comment.