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 on function parameter decorator with default value #2394

Closed
LandazuriPaul opened this issue Aug 14, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists 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

@LandazuriPaul
Copy link

LandazuriPaul commented Aug 14, 2020

Reproduction

I noticed that when the @typescript-eslint/no-unused-vars) rule is enabled (either warn or error mode) :

{
  "rules": {
    "@typescript-eslint/no-unused-vars": ["warn"]
  }
}

it triggers a false positive for function parameter decorators when the parameter for which it's used has a default value.

For example, in the following code case:

import { Controller, Get, Query } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(@Query('foo') foo = 'bar'): string {
    console.log(foo);
    return this.appService.getHello();
  }
}

the Query decorator will be marked as unused (Line 1). But if we remove the default 'bar' value, then there is no more false positive.

Expected Result

The linter shouldn't raise a warning/error on such circumstances.

Actual Result

The linter raises a warning/error.

Additional Info

I've created a reproduction repository with the above example.

Versions

package version
@typescript-eslint/eslint-plugin 3.9.0
@typescript-eslint/parser 3.9.0
TypeScript 3.9.7
ESLint 7.6.0
node 12.18.3
npm 6.14.6
@LandazuriPaul LandazuriPaul added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 14, 2020
@bradzacher
Copy link
Member

#1856

Please use the search.

@bradzacher bradzacher added 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 Aug 14, 2020
@bradzacher bradzacher added the duplicate This issue or pull request already exists label Aug 14, 2020
@LandazuriPaul
Copy link
Author

LandazuriPaul commented Aug 14, 2020

@bradzacher Thank you for pointing to the original issue.

I did « use the search », and didn't find it as it's quite meta and didn't appear for what I was looking for...

EDIT: I just found #1649 which has been merged into #1856 and which was the exact same issue. Sorry for the duplicate.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists 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