Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unnecessary { after 'else'" error appears on wrong line #4362

Closed
andy-hanson opened this issue Nov 8, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@andy-hanson
Copy link

commented Nov 8, 2015

This is the code I'm linting:

if (0)
    console.log(0)
else if (1) {
    // Above curly brace is necessary.
    console.log(1)
    console.log(1)
} else {
    // Above curly brace is unnecessary.
    if (2)
        console.log(2)
    else
        console.log(3)
}

And here's my package.json:

{
    "scripts": {
        "lint": "eslint src test"
    },
    "devDependencies": {
        "eslint": "1.9.0"
    },
    "eslintConfig": {
        "rules": {
            "curly": [1, "multi"]
        }
    }
}

I get the following error:

/home/andy/eslint-bug/src/foo.js
  3:6  warning  Unnecessary { after 'else'  curly

✖ 1 problem (0 errors, 1 warning)

which is the correct error but has the wrong line number.
The error should be for the last else, on line 7.

@nzakas

This comment has been minimized.

Copy link
Member

commented Nov 9, 2015

This isn't an issue with the wrong line number showing in the message. The first else is incorrectly being flagged. It's probably confused because there's an if right after it (which is one statement) and then a curly.

@mysticatea mysticatea self-assigned this Nov 15, 2015

@mysticatea

This comment has been minimized.

Copy link
Member

commented Nov 15, 2015

I'm working on this.

mysticatea added a commit to mysticatea/eslint that referenced this issue Nov 15, 2015

@nzakas nzakas closed this in #4430 Nov 15, 2015

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.