JavaScript Code Linting tool to find Variables which are initialised but might not be used due to condition

225 Views Asked by At

I have the following JavaScript code,

var foo = {
    company: "ABC",
    name: "John"
};

var att = "";

function test(ob, i) {
    var m = JSON.stringify(ob);
    if (i < 10) {
        att = att + m;
    }
}

test(foo, 20);

In above code, var m = JSON.stringify(ob); line is unnecessary initialisation of variable when i < 10 is not true. A better code will be to move the initialization inside the if condition.

I am not able to find a code linter that can detect such scenarios. In such cases, I want a warning that variable might not be used. Does anyone know any linting tool that can do this?

I tried

  1. ES Lint
  2. JS Lint
0

There are 0 best solutions below