Handle TSTypeReference in no-unused-prop-types - #3195
Conversation
Co-authored-by: Markus Olsson <j.markus.olsson@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
commented
Feb 1, 2022
|
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? |
commented
Feb 1, 2022
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 |
commented
Feb 1, 2022
|
ahhh gotcha, it's the TS version specifically? What version of the TS eslint parser are you using? |
commented
Feb 1, 2022
|
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.
|
commented
Feb 1, 2022
|
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
commented
Feb 1, 2022
|
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-typerule instead of thereact-unused-props-and-statefrom the obsoletetslint-microsoft-contribpackage.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 lintDoing so very haphazardly troubleshooting I noticed that when encountering our prop types in
propTypes.jsthey were of typeTSTypeReferencewhich was not being handled in the switch case. Spotting thatDeclarePropTypesForTSTypeAnnotationseemed to be able to handle bothTSTypeAnnotationandTSTypeReferenceinternally 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.