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

no-inner-declarations should permit inner let and const #1893

Closed
btmills opened this Issue Feb 27, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@btmills
Member

btmills commented Feb 27, 2015

// test.js
if (foo) {
    let bar = 42;
    const baz = bar;
}
// config.json
{
    "rules": {
        "no-inner-declarations": [2, "both"]
    },
    "ecmaFeatures": {
        "blockBindings": true
    }
}
$ eslint --reset --no-eslintrc -c config.json test.js

test.js
  3:4  error  Move variable declaration to program root  no-inner-declarations
  4:4  error  Move variable declaration to program root  no-inner-declarations

✖ 2 problem (2 errors, 0 warnings)

Since let and const are scoped within the if's consequent, moving them to the program root would functionally change the code. no-inner-declarations should check the kind of the VariableDeclaration node and only warn when kind is "var".

Even with the no-var rule enabled, no-inner-declarations can still be used to prevent inner function declarations, so it would not be sufficient to disable no-inner-declarations when using block bindings.

jrvidal added a commit to jrvidal/eslint that referenced this issue Feb 28, 2015

@nzakas nzakas closed this in 3517eb3 Feb 28, 2015

nzakas added a commit that referenced this issue Feb 28, 2015

Merge pull request #1901 from jrvidal/master
Fix: allow block bindings in no-inner-declarations (fixes #1893)

@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.