question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I expect no-unused-vars rule to be skipped if there is an object spread

See original GitHub issue
const { foo, ...rest } = obj;

“foo” is defined but never used happens, but in most case you still want to do this because you want to take obj without some named fields.

I personally would expect the no-unused-vars rule to be skipped if there is an object spread.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
fredguestcommented, Feb 18, 2016

@nzakas, i agree with @gre that this is not being handled correctly at the moment. for the linter to remain silent when foo in the code example above is unused would not be a special affordance, it would be the correct behavior in every instance. the analog is the linter’s behavior in this scenario:

someCallback(arg1, arg2) {
  return arg2;
}

the linter does not warn about arg1 being unused, because it accounts for the fact that it may only be present to access arg2. the scenario with a rest spread is exactly the same; because the destructured variables preceding the rest object may only be present to access the rest object, the linter should never complain if they are unused.

2reactions
victormiguezcommented, Jun 13, 2017

If anyone need this just like me today, it`s already possible to do with no-unused-vars: [“error”, { “ignoreRestSiblings”: true }].

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
Ryan Florence på Twitter: "Is there a rule in eslint yet to allow ...
Is there a rule in eslint yet to allow destructuring of unused vars to pluck off ... I expect no-unused-vars rule to be...
Read more >
How can I use ESLint no-unused-vars for a block of code?
Original answer · I have tried with no success, the error is thrown by standardjs · Hacking linting rules for something that is...
Read more >
eslint-plugin-flowtype - npm
This rule has a string option and an object one. String options are: ... If it is 'always' then a problem is raised...
Read more >
Changelog - JavaScript Standard Style
If you have used comments like // eslint-disable-line node/no-deprecated-api you now have to reference the n/ rules instead. object-shorthand rule (as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found