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

Conversation

crnhrv
Copy link
Contributor

@crnhrv crnhrv commented May 30, 2024

I'm getting this error while linting some valid React/TS code after upgrading to the latest version (7.34.2):

Stack trace
Oops! Something went wrong! :(

  ESLint: 8.57.0
  
  TypeError: Missing required argument: node.
  Occurred while linting ./OptionsTable.tsx:599
  Rule: "react/display-name"
      at SourceCode.getScope (./node_modules/eslint/lib/source-code/source-code.js:773:19)
      at getScope (./node_modules/eslint-plugin-react/lib/util/eslint.js:19:23)
      at resolveValueForIdentifierNode (./node_modules/eslint-plugin-react/lib/util/propTypes.js:378:21)
      at buildReactDeclarationTypes (./node_modules/eslint-plugin-react/lib/util/propTypes.js:420:5)
      at ./node_modules/eslint-plugin-react/lib/util/propTypes.js:788:39
      at iterateProperties (./node_modules/eslint-plugin-react/lib/util/propTypes.js:71:7)
      at ./node_modules/eslint-plugin-react/lib/util/propTypes.js:773:23
      at Array.forEach (<anonymous>)
      at DeclarePropTypesForTSTypeAnnotation.convertReturnTypeToPropTypes (./node_modules/eslint-plugin-react/lib/util/propTypes.js:762:34)
      at DeclarePropTypesForTSTypeAnnotation.searchDeclarationByName (./node_modules/eslint-plugin-react/lib/util/propTypes.js:667:14)

I don't really understand enough about the codebase to say whether this is the correct fix, or if this really should be passing in node instead of rootNode to getScope or something like that. This resolves the immediate issue for me at least and seemed reasonable to check the value is valid before it tries to call something that requires it.

@crnhrv crnhrv changed the title Null check rootNode before calling getScope with it [Fix] Null check rootNode before calling getScope with it May 30, 2024
@ljharb
Copy link
Member

ljharb commented May 30, 2024

Thanks - we'd need a regression test in order to land this tho.

@crnhrv
Copy link
Contributor Author

crnhrv commented May 31, 2024

@ljharb I've attempted to add some regression tests by trying to find a minimal reproduction. I think the issue relates to using ReturnType<typeof object> for the type parameter for a component, but I don't really know the details.

I get the expected failure without the nullcheck:

ishare-1717159133

@crnhrv crnhrv force-pushed the master branch 2 times, most recently from c37344b to f877a50 Compare May 31, 2024 12:29
Copy link

codecov bot commented May 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.76%. Comparing base (417e1ca) to head (f877a50).

Current head f877a50 differs from pull request most recent head e27ef81

Please upload reports for the commit e27ef81 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3762      +/-   ##
==========================================
- Coverage   97.79%   97.76%   -0.04%     
==========================================
  Files         134      134              
  Lines        9613     9614       +1     
  Branches     3486     3487       +1     
==========================================
- Hits         9401     9399       -2     
- Misses        212      215       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@crnhrv
Copy link
Contributor Author

crnhrv commented May 31, 2024

I see that code coverage is failing on some indirect changes related to code beneath a node.type === 'TSParenthesizedType' conditional. Not sure why that would happen, but is this code actually necessary since TSParenthesizedType seems to no longer be generated as a node type?

@ljharb
Copy link
Member

ljharb commented May 31, 2024

@crnhrv that PR seems to be in v5 of the parser, but we still support down to v2

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful, thanks! don't worry about the coverage.

@crnhrv
Copy link
Contributor Author

crnhrv commented May 31, 2024

Cool, thanks for the help. Will leave it with you then

@ljharb ljharb merged commit e27ef81 into jsx-eslint:master May 31, 2024
328 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants