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

Allow _ to be an unused variable #800

Closed
feross opened this issue Feb 23, 2017 · 5 comments
Closed

Allow _ to be an unused variable #800

feross opened this issue Feb 23, 2017 · 5 comments

Comments

@feross
Copy link
Member

feross commented Feb 23, 2017

In React, it's common to do:

const { width, height, ...restProps } = props
return <div ...restProps>

This assigns all the properties of props except width and height to the <div>.

Currently standard warns about width and height being unused. Would be nice if we could assign these variables to _ and _2 to mark them as unused (since we can't assign them both to _ in one assignment).

const { width: _, height: _2, ...restProps } = props
return <div ...restProps>

@dcousens Didn't you say that you have a rule modification that you use for this purpose? Can you share it?

@dcousens
Copy link
Member

dcousens commented Feb 23, 2017

#419 (comment)

"no-unused-vars": [2, { "vars": "all", "args": "all", "argsIgnorePattern": "^_$" }],

Is what I am using, but it doesn't cover this case...

edit:

"varsIgnorePattern": "^_$"

Does not work for this case either, fwiw.

@dcousens
Copy link
Member

dcousens commented Feb 23, 2017

@feross ignoreRestSiblings already exists though

/*eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/
// 'type' is ignored because it has a rest property sibling.
var { type, ...coords } = data;

@feross
Copy link
Member Author

feross commented Feb 28, 2017

@dcousens Oh, nice. Let's use ignoreRestSiblings then!

@feross feross added this to the standard v10 milestone Feb 28, 2017
@feross
Copy link
Member Author

feross commented Mar 1, 2017

No ecosystem impact. This will be included in the standard v10 beta.

@feross feross closed this as completed Mar 1, 2017
feross added a commit to standard/eslint-config-standard that referenced this issue Mar 2, 2017
Fixes: standard/standard#800

The ignoreRestSiblings option is a boolean (default: false). Using a
Rest Property it is possible to “omit” properties from an object, but
by default the sibling properties are marked as “unused”. With this
option enabled the rest property’s siblings are ignored.

```js
// 'type' is ignored because it has a rest property sibling
var { type, ...coords } = data
```
@tdd
Copy link

tdd commented Mar 3, 2017

ZOMG this is SO going to make my day 😄 — the inability to rest on objects has been bugging me for a while.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

3 participants