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

False positives + query ideas for variables with leading underscores. #655

Closed
s0 opened this issue Dec 10, 2018 · 3 comments
Closed

False positives + query ideas for variables with leading underscores. #655

s0 opened this issue Dec 10, 2018 · 3 comments

Comments

@s0
Copy link
Contributor

s0 commented Dec 10, 2018

js/unused-local-variable has some false positives for variables that are intentionally unused, e.g. for array destructuring, etc...

An example can be seen in Shopify/quilt#434

It's a convention that local variables with leading underscores are designed to be unread, e.g:

const [a, _, c, d, e, f] = something
// or
const [a, _b, _c, d, e, f] = something

Moreover, tslint recently temporarily deprecated their no-unused-variable rule in favour of the new compiler flags which take leading underscores into account.

I suggest we:

  • ignore variables that start with an underscore in js/unused-local-variable
  • create a new query that finds variables that suggests they should be unused, but are actually used.
@xiemaisi
Copy link

It's a convention (...)

I'm sure you're right, but could we have a reference for that convention? I'd also like to point out that in the examples you give you should be able to just omit the _* variables altogether:

const [a, , c, d, e, f] = something

@s0
Copy link
Contributor Author

s0 commented Dec 10, 2018

I'm sure you're right, but could we have a reference for that convention?

Here are a few of places:

I'd also like to point out that in the examples you give you should be able to just omit the _* variables altogether

Ah yes!

@xiemaisi
Copy link

OK, thanks, that looks fairly widely accepted.

If we decide it's not a widely-enough used convention for JS, we could potentially enable it for TS only

We could, but to be honest I doubt we'll lose any interesting results by enabling it for JS as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants