Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
"no-unused-vars" : "warn",
What did you do? Please include the actual source code causing the issue.
Paste this into the demo:
(function ({ a }, b ) {
return b;
})();
What did you expect to happen?
a
should be detected as being unused.
What actually happened? Please include the actual, raw output from ESLint.
a
passed, because I think it assumes the first parameter (the { a }
object) to be padding the b
param.
Hi @dwelle, thanks for the issue.
I believe this is working as designed. The default rule options treat any parameter before the leftmost used parameter as "not unused", because it's possible you had to define that argument to conform to a contract not under your control. If you want earlier arguments to be flagged by this rule, use the "args": "all"
option.
@platinumazure to achieve what you're describing, I wouldn't have to actually _destructure_ arguments[0]
. I could write:
(function ( a, b ) {
return b;
})();
but when you destructure, it's because you actually need to access child properties. It's an example. In real world, it's more like:
someApi({ a, b, c, d }, { e, f, g }) {
// oops.. `c` is not used
transform( a, b, d, e, f g );
}
Thus, it should still consider a
in the original example (or c
in the above example) as _unused_.
Hmm, I think this is a bug. The point of the "args": "after-used"
option is that if the first parameter of a function is unused, it's not possible to remove it if the second argument is used. However, that's not the case here, because the variable can be removed from the destructuring pattern:
(function ({ a }, b ) {
return b;
})();
// can be replaced with:
(function ({}, b ) {
return b;
})();
Most helpful comment
Hmm, I think this is a bug. The point of the
"args": "after-used"
option is that if the first parameter of a function is unused, it's not possible to remove it if the second argument is used. However, that's not the case here, because the variable can be removed from the destructuring pattern: