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

[no-unused-vars] False positive with parameter decorators with default values #1649

Closed
robin-pham opened this issue Feb 27, 2020 · 4 comments
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser

Comments

@robin-pham
Copy link

robin-pham commented Feb 27, 2020

Repro

{
  "rules": {
    "@typescript-eslint/no-unused-vars": [
      "error",
      {
        "vars": "all",
        "args": "none"
      }
    ]
  }
}
const log = function(target: Object, method: string, index: number): void {
  console.log('decorating %s[%d]', method, index);
};

class Test {
  public sum(a: number, @log b: number = 7): number {
    return a + b;
  }
}

Expected Result

No violation of unused-vars is reported.

Actual Result

It complains that log is assigned a value but never used.

Additional Info

Note: the rule works fine if there is no default value.

Versions
Tried on two sets of versions:

package version
@typescript-eslint/eslint-plugin 2.21.0
@typescript-eslint/parser 2.21.0
TypeScript 3.3.3333
ESLint 6.8.0
node 12.14.1
npm 6.13.4

and

package version
@typescript-eslint/eslint-plugin 1.4.2
@typescript-eslint/parser 1.4.2
TypeScript 3.3.3333
ESLint 5.15.1
node 12.14.1
npm 6.13.4
@robin-pham robin-pham added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 27, 2020
@bradzacher
Copy link
Member

please try switching to our no-unused-vars-experimental rule, it will work in this case.

@bradzacher bradzacher added bug Something isn't working scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser and removed triage Waiting for maintainers to take a look labels Feb 27, 2020
@robin-pham
Copy link
Author

gotcha, tried it out and it works!

sadly though our codebase uses options in no-unused-vars that don't exist in no-unused-vars-experimental :(.

thanks for the quick reply!

@bradzacher
Copy link
Member

Options like what?
Potentially could be built into the new rule.

@bradzacher
Copy link
Member

Merging into #1856

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin scope analyser Issues that are caused by bugs/incomplete cases in the scope analyser
Projects
None yet
Development

No branches or pull requests

2 participants