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鈥檒l 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

Conversation

@kdmadej
Copy link
Contributor

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 馃槄

鈥hen 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
@ljharb ljharb added the typescript label Jan 1, 2020
Copy link
Collaborator

ljharb left a comment

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 force-pushed the kdmadej:fix/2517-no-unused-prop-types-ts-type-assertion branch from 7c32709 to d1dc277 Jan 15, 2020
@ljharb
ljharb approved these changes Jan 15, 2020
@ljharb ljharb merged commit d1dc277 into yannickcr:master Jan 15, 2020
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.008%) to 97.606%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can鈥檛 perform that action at this time.