Javascript: Exception for no-unused-var when destructuring with object rest?

Created on 13 May 2016  路  3Comments  路  Source: airbnb/javascript

In my test, I have the following code:

      const {
        id,
        date_created,
        date_updated,
        ...hashItem,
      } = body
      t.deepEqual(hashItem, {
        hash: '1712c2e67fe25e0eb9248633264cf8e32ca0fc3416deb74210d67fb7f4ee91be',
        url: 'http://someurl.com',
     })

Which gives me an unused var error because of id, date_created, date_updated. I think it's pretty clear that what I'm interested in is the "rest" of the object (hashItem). I was wondering if there could be an exception to this rule when using object rest to omit properties from an object.

needs eslint rule changaddition question

Most helpful comment

eslint v3.16.0 adds this rule, and the next release of eslint-config-airbnb-base will support it.

All 3 comments

Since object spread/rest is not yet standard (still stage 2, iirc), eslint nor our style guide support it, and we do not recommend its use.

When it becomes stage 3 or 4, and when the relevant eslint rule is updated to support this case, we can reevaluate it (it would be dangerous to endorse this use case imo, without this linter rule fully enabled).

eslint v3.16.0 adds this rule, and the next release of eslint-config-airbnb-base will support it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixsanz picture felixsanz  路  3Comments

weihongyu12 picture weihongyu12  路  3Comments

ryankask picture ryankask  路  3Comments

tpiros picture tpiros  路  3Comments

ar
mbifulco picture mbifulco  路  3Comments