eslint: [no-unused-vars] is not reported in a scenario.
I am using
eslint@2.8.0
babel-eslint@6.0.4
node v6.0.0
npm 3.8.6
My rule is set to "no-unused-vars": 1
function test(options) {
options = options || {};
// Shouldn't this should give no-unused-vars error here?
}
test({});
In above scenario since options object is not used thus IMHO this should raise no-unused-vars
error.
I tested this on online demo of eslint also.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (12 by maintainers)
Commits related to this issue
- Update: `no-unused-vars` ignores read it modifies itself (fixes #6348) `no-unused-vars` comes to ignore a read of a modification of itself. - A read in RHS of an assignment to itself (e.g. `a = a + ... — committed to eslint/eslint by mysticatea 8 years ago
- Update: `no-unused-vars` ignores read it modifies itself (fixes #6348) `no-unused-vars` comes to ignore a read of a modification of itself. - A read in RHS of an assignment to itself (e.g. `a = a + ... — committed to eslint/eslint by mysticatea 8 years ago
- Update: `no-unused-vars` ignores read it modifies itself (fixes #6348) (#6535) * Update: `no-unused-vars` ignores read it modifies itself (fixes #6348) `no-unused-vars` comes to ignore a read of a... — committed to eslint/eslint by mysticatea 8 years ago
Hmm… I’ve reconsidered. I think it might be sufficient to provide an option which simply says, if a variable is on LHS and RHS of an assignment, don’t assume it is used.
Also, I’m wondering about the compound-assignment operators. Do they count as usage?
If the compound-assignment doesn’t count as a use, I fail to see how unwrapped assign-after-operator (
a = a + 1
) should count as a use either.👍 for @platinumazure’s suggestion, not optional. That is, until
a
is used for something other than self assignment, consider it unused.imo this exception should only cover assignment if the RHS is a combination of LHS, a literal, and shortcircuiting operators.
Note that the snippet
does use the argument
@vitorbal I think a good check is to see if the same variable is on both left and right side of the assignment expression. In that case, it should not be considered as “use”.