jslint icon indicating copy to clipboard operation
jslint copied to clipboard

Allow detect when function argument shadows existing variable

Open dvhx opened this issue 11 months ago • 4 comments

In the following code I use variable "s" to store string "foo", then I want to iterate over "data" array using forEach, I use function argument "s" which "overwrites" the parent "s". Jslint currently does not show it as warning:

var s = "foo";
var data = [1, 2, 3];
data.forEach(function (s) {
    console.log(s, "long text so you don't notice arg s shadowed parent s", s);
});

Could jslint produce warning, something like:

Redefinition of 's' from line 1.

JSLINT already does it for local variables:

var s = "foo";
var data = [1, 2, 3];
function foo() {
    var s = "asdf";    // JSLINT warning: Redefinition of 's' from line 1.
    console.log(s);
}

dvhx avatar Jul 23 '23 06:07 dvhx