Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

[no-unused-vars] False positive for unused vars inside decorator arguments #126

Closed
ridaamirini opened this issue Apr 18, 2018 · 3 comments
Closed
Labels
bug/incomplete rule parser bug bugs with typescript-eslint-parser / typescript-estree
Milestone

Comments

@ridaamirini
Copy link

ridaamirini commented Apr 18, 2018

From eslint/typescript-eslint-parser#445

What code were you trying to parse?

import { Component, Vue } from 'vue-property-decorator';
import HelloWorld from './components/HelloWorld.vue';

@Component({
  components: {
    HelloWorld
  }
})
export default class App extends Vue {}

What did you expect to happen?

With eslint-plugin-typescript's typescript/no-unused-vars rule enabled, should lint without errors.

What happened?

error: 'HelloWorld' is defined but never used (no-unused-vars)

It looks like the expression in a decorator's argument position is not taken into context when determining unused vars. Also, when using eslint --fix, code inside decorator arguments are sometimes not formatted correctly.

@SunshowerC
Copy link

So could anyone fix it ?

@gwardwell
Copy link

I'm seeing this issue as well. Is there any progress on a fix?

@bradzacher bradzacher changed the title False positive for unused vars inside decorator arguments [no-unused-vars] False positive for unused vars inside decorator arguments Nov 16, 2018
@bradzacher bradzacher added bug/incomplete rule requires investigation bug that require more investigation labels Nov 16, 2018
@bradzacher bradzacher self-assigned this Nov 19, 2018
@bradzacher
Copy link
Owner

https://astexplorer.net/#/gist/9f8a50b0db8e4f6eb6a4232cb3bf4160/618c7989605019cdd3a3b8d023cb8c6fe47a837f

const foo = '';

@deco({
  foo
})
export default class App {}

@deco({
  foo
})
export class App {}

Looking at the AST and comparing it to the markDecoratorAsUsed function, it looks like it was never built to handle decorator arguments.

Having a look, this will be fixed by the new visitorKeys config that the parser added in v20.
So this should be fixed by #166

@bradzacher bradzacher removed the requires investigation bug that require more investigation label Nov 19, 2018
@bradzacher bradzacher added this to the 1.0.0 milestone Nov 19, 2018
@bradzacher bradzacher removed their assignment Nov 19, 2018
armano2 added a commit to armano2/eslint-plugin-typescript that referenced this issue Nov 19, 2018
armano2 added a commit to armano2/eslint-plugin-typescript that referenced this issue Nov 20, 2018
@bradzacher bradzacher added the parser bug bugs with typescript-eslint-parser / typescript-estree label Nov 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/incomplete rule parser bug bugs with typescript-eslint-parser / typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants