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] Null check rootNode before calling getScope with it #3762

Merged
merged 1 commit into from
May 31, 2024
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
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
Loading