Javascript: Unused variables when destructuring?

Created on 23 Jul 2015  路  2Comments  路  Source: airbnb/javascript

I just wrote this code:

  dirtyProperties() {
    return this._getProperties()
      .filter(([ prop ]) => prop.isDirty())
      .map(([ _, propName ]) => propName);
  }

and eslint threw a no-unused-vars error because of the _ variable.

Is this against the Airbnb style guide? I feel like using _ to ignore the first destructured variable should be pretty well understood and not using destructuring would make the code more verboe.

Most helpful comment

Ooops, I just realized I can do [ , propName ].

All 2 comments

_ is just a convention. However, https://github.com/airbnb/javascript/blob/master/linters/.eslintrc#L46-L49 allows what you want in _arguments_ - I think this is just something eslint hasn't handled yet.

If I'm correct (and we're not just missing a rule for this) I'd suggest opening a bug on eslint itself, and request that rule exception.

Ooops, I just realized I can do [ , propName ].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SimenB picture SimenB  路  34Comments

AugustinLF picture AugustinLF  路  30Comments

MartialSeron picture MartialSeron  路  153Comments

josmardias picture josmardias  路  37Comments

ljharb picture ljharb  路  36Comments