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

Most upvoted comments

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.

function myFunc(a) {
    a = a + 1;
    // But wait, I'm still not really using a beyond the assignment,
    // so the assignment was actually pretty useless.
}

Also, I’m wondering about the compound-assignment operators. Do they count as usage?

function myOtherFunc(a) {
    a += 1;  // Is this a "use" per no-unused-params?
}

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

function test(count) {
    count = count + 1;
}

test({
    value: 1,
    toString() {
        console.log(`called (${this.value})`);
        return String(this.value++);
    }
});

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”.