Skip to content

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

Closed

Description

@s0

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.

Activity

  1. xiemaisi commented on Dec 10, 2018

    @xiemaisi

    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
  2. s0 commented on Dec 10, 2018

    @s0
    ContributorAuthor

    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!

  3. xiemaisi commented on Dec 11, 2018

    @xiemaisi

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions