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]: false positives for no-unused-... when using TS type assertions #2536

Merged
merged 1 commit into from Jan 15, 2020
Merged

[Fix]: false positives for no-unused-... when using TS type assertions #2536

merged 1 commit into from Jan 15, 2020

Conversation

kdmadej
Copy link
Contributor

@kdmadej kdmadej commented Dec 30, 2019

Fixes #2517:

  • adds an ast util for unwrapping TS as assertion.
  • fixes false positives for no-unused-prop-types
  • fixes false positives for no-unused-state

I tried to reuse as much of the existing solution as possible by handling cases where the as expression might occur.

I'm wondering tho if it would be better to just process the code with anything that would remove TS-specific syntax (type annotations, as assertions, etc.) and then parse the result so the entire logic could be reused. Just thinking out loud 😅

…when using TS type assertions

Fixes #2517

 - add `unwrapTSAsExpression` to `lib/util/ast`
 - change `as any` assertions in tests to `as unknown`
 - add failing test cases
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.

Thanks, only these last comments and we're good :-)

tests/lib/rules/no-unused-prop-types.js Show resolved Hide resolved
tests/lib/rules/no-unused-prop-types.js Show resolved Hide resolved
@ljharb ljharb merged commit d1dc277 into jsx-eslint:master Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

no-unused-prop-types returns false positive when destructuring props cast to a different type
2 participants