Skip to content

[no-unused-vars] false positive when generic param name masks name in parent scope #54

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

Closed
armano2 opened this issue Nov 22, 2018 · 2 comments · Fixed by #688
Closed
Labels
bug Something isn't working has pr there is a PR raised to close this package: parser Issues related to @typescript-eslint/parser scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser

Comments

@armano2
Copy link
Collaborator

armano2 commented Nov 22, 2018

Repro

{
  "rules": {
    "no-unused-vars": "off",
    "typescript/no-unused-vars": "error"
  }
}
type Foo = number

function test<Foo>(bar: Foo) {
    return bar
}

Expected Result
error that type Foo is not defined

Actual Result
all is good

Additional Info

There is few issues there:

  • markVariableAsUsed is iterating over all variables even if found first one,
  • type parameters are not validated

Versions

package version
eslint-plugin-typescript 1.0.0-rc.1
typescript-eslint-parser internal
typescript 3.1.1
@bradzacher bradzacher changed the title no-unused-vars incorrect results [no-unused-vars] false positive when generic param name masks name in parent scope Nov 25, 2018
@bradzacher
Copy link
Member

Digging into this, I don't know what we can do about this without significant work.

Right now our rule sits on top of the base rule, so I think we would have to clone the base rule's code in order to handle this case properly.

This would be a good candidate for using the TS parser services if it reports unused vars.

This should be caught by something like no-redeclare. Though it won't because we haven't added ts-specific handling to that rule.

@armano2
Copy link
Collaborator Author

armano2 commented Jan 8, 2019

@bradzacher right now there is no real solution for that. It's require some work on parser before we can start.
I started doing PR with support for additional data in scope for typescript "types" but its not near finish.
When it will be done, we can start thinking about solving this.

I made this issue for now just to inform ppl that we are aware about it and we will work on it.

no-redeclare is not possible now without scope analysis (unless we do it in bad way on our side)


type references and annotations are not in eslint scope for now.

@JamesHenry JamesHenry transferred this issue from bradzacher/eslint-plugin-typescript Jan 18, 2019
@bradzacher bradzacher added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: parser Issues related to @typescript-eslint/parser and removed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin labels Jan 18, 2019
@bradzacher bradzacher added the scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser label Apr 15, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Jul 16, 2019
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
@bradzacher bradzacher added this to the scope analysis rewrite milestone Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: parser Issues related to @typescript-eslint/parser scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants