-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Handle TSTypeReference in no-unused-prop-types #3195
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
Conversation
Co-authored-by: Markus Olsson <j.markus.olsson@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
The fix looks great, but if we don't have a regression test, it will guaranteed be broken again in the future :-) Your repro looks pretty small, so it should be straightforward to adapt it into a test case. Want to give it a shot? |
I'd be happy to but I'm not sure how I should go about it. There's already plenty of tests cases that cover this scenario in the |
ahhh gotcha, it's the TS version specifically? What version of the TS eslint parser are you using? |
Looks like v5.10, and we're already testing on |
Codecov Report
@@ Coverage Diff @@
## master #3195 +/- ##
=======================================
Coverage 97.53% 97.53%
=======================================
Files 120 120
Lines 8301 8302 +1
Branches 2987 2988 +1
=======================================
+ Hits 8096 8097 +1
Misses 205 205
Continue to review full report at Codecov.
|
I reran the passing tests on master from 3 days ago, and they continued to pass: https://github.com/yannickcr/eslint-plugin-react/actions/runs/1767687068 - so we do need some kind of new coverage, or possibly, to upgrade to TS 4.5. That would imply it's a breaking change in TS tho. |
90f1bc2
to
36482a3
Compare
So, I couldn't make this test fail locally. Then, I installed different versions of TS and the TS eslint parser, and was able to make it fail. Then, I couldn't get it to NOT fail (absent the fix). So, I guess we'll land it, but something weird is going on. |
👋 from GitHub Desktop land!
We're currently upgrading to TypeScript 4.5 (desktop/desktop#13768) and while doing that I wanted to start using the
react/no-unused-props-type
rule instead of thereact-unused-props-and-state
from the obsoletetslint-microsoft-contrib
package.Unfortunately I couldn't get the rule to produce any errors. I put up a minimal reproduction repository at https://github.com/niik/no-unused-prop-types-repro which illustrates the problem. To test it just clone and run
yarn lint
Doing so very haphazardly troubleshooting I noticed that when encountering our prop types in
propTypes.js
they were of typeTSTypeReference
which was not being handled in the switch case. Spotting thatDeclarePropTypesForTSTypeAnnotation
seemed to be able to handle bothTSTypeAnnotation
andTSTypeReference
internally I simply tried adding it to the switch and lo-and-behold the rule just started working.Now, obviously I have no idea what I'm doing here so I'm happy to adjust my approach given some guidance from someone who understands eslint/ts-parser internals but running my minimal reproduction repository with my branch (https://github.com/niik/no-unused-prop-types-repro/tree/with-ts-type-reference-fix) reports the error correctly.