Skip to content

block-scoped-var rule reports duplicate issues in some cases #17244

@ashwinbaliga

Description

@ashwinbaliga

Environment

Node version: 16.16.0
npm version: 8.11.0
Local ESLint version: 8.41.0
Global ESLint version: 8.41.0
Operating System: RHEL 7

What parser are you using?

Default (Espree)

What did you do?

Configuration
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "script",
        "ecmaFeatures": {}
    },
    "rules": {
        "block-scoped-var": [
            "error"
        ]
    },
    "env": {
        "es2021": true
    }
}

define([], function() {
    if (true) {
      var myvar = 10;
    } else if (true) {
      var myvar = 10;
    } else if (true) {
      var myvar = 10;
    } else if (true) {
      var myvar = 10;
    }
});

What did you expect to happen?

Error for each line should be reported only once

What actually happened?

Error for each line is reported 3 times

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiZGVmaW5lKFtdLCBmdW5jdGlvbigpIHtcbiAgICBpZiAodHJ1ZSkge1xuICAgICAgdmFyIG15dmFyID0gMTA7XG4gICAgfSBlbHNlIGlmICh0cnVlKSB7XG4gICAgICB2YXIgbXl2YXIgPSAxMDtcbiAgICB9IGVsc2UgaWYgKHRydWUpIHtcbiAgICAgIHZhciBteXZhciA9IDEwO1xuICAgIH0gZWxzZSBpZiAodHJ1ZSkge1xuICAgICAgdmFyIG15dmFyID0gMTA7XG4gICAgfVxufSk7XG5cbiIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6ImxhdGVzdCIsInNvdXJjZVR5cGUiOiJzY3JpcHQiLCJlY21hRmVhdHVyZXMiOnt9fSwicnVsZXMiOnsiYmxvY2stc2NvcGVkLXZhciI6WyJlcnJvciJdfSwiZW52Ijp7ImVzMjAyMSI6dHJ1ZX19fQ==

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Errors reported:

Error 3:11
'myvar' used outside of binding context. (block-scoped-var)

Error 3:11
'myvar' used outside of binding context. (block-scoped-var)

Error 3:11
'myvar' used outside of binding context. (block-scoped-var)

Error 5:11
'myvar' used outside of binding context. (block-scoped-var)

Error 5:11
'myvar' used outside of binding context. (block-scoped-var)

Error 5:11
'myvar' used outside of binding context. (block-scoped-var)

Error 7:11
'myvar' used outside of binding context. (block-scoped-var)

Error 7:11
'myvar' used outside of binding context. (block-scoped-var)

Error 7:11
'myvar' used outside of binding context. (block-scoped-var)

Error 9:11
'myvar' used outside of binding context. (block-scoped-var)

Error 9:11
'myvar' used outside of binding context. (block-scoped-var)

Error 9:11
'myvar' used outside of binding context. (block-scoped-var)

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyrepro:yesIssues with a reproducible exampleruleRelates to ESLint's core rules

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions