Skip to content

Allow detect when function argument shadows existing variable #443

@dvhx

Description

@dvhx

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions