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 inconsistency #12222
Comments
I would be 👍 for having 4 errors in your example. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
This looks like a bug to me - reopening so we can evaluate. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
@mdjermanovic when wrapping the if statement blocks with parens /*eslint no-inner-declarations: ["error", "both"]*/
if (foo){
var a; // error
}
if (foo){
function f(){} // error
}
function bar() {
if (foo)
var a; // error
if (foo){
function f(){} // error
}
} |
|
@mdjermanovic I have a fix working for this! mind if I submit the change? here is the fix anikethsaha@83f83c5 |
@anikethsaha Sure, thanks! It isn't entirely clear what should be done, but it looks like a good idea to continue the discussion on a PR. |
@mdjermanovic @anikethsaha Could one of you sum up what needs to be discussed here so that the rest of the team can easily provide input? |
The question is should we change the logic to report all declarations except those that have either:
In particular, cases like these would be new warnings: if (foo)
var a;
if (foo)
function f(){}
while (foo)
var a; |
Understood. I think there should be no errors in the original example since the documentation specifically refers to blocks. This feels especially true with lexically scoped variable declarations, since the actual scope would change. |
I believe there are no lexically scoped variable declarations in those cases.
In strict mode, it's a syntax error. In non-strict mode, it's treated as if it was /* not strict */
f; // doesn't throw ReferenceError
console.log(typeof f); // undefined, isn't intialized yet
if (true)
function f() { return 33; }
console.log(f()); // 33
g; // doesn't throw ReferenceError
console.log(typeof g); // undefined, isn't intialized yet
if (true) {
function g() { return 55; }
}
console.log(g()); // 55 If this rule shouldn't report |
Ah, you're right. Thanks for explaining this. I agree with you that this should have 4 errors. 👍 |
Given three team members (@platinumazure, @mdjermanovic, and myself) believe this should have 4 errors, I think we can confidently move forward here. Removing the "needs bikeshedding" label. |
…) (#13062) * Fix: consistencies for blockstmt no-inner-fn (fix #12222) * Chore: added some more tests * Chore: allowing named and default exports and tests * Chore: simply the check conditions * Chore: simplify checks and ancestor loop * Chore: using getUpperFunction to get body * chore: added tests and minor changes * Docs: eg for both non-blockstatement * Chore: right docs example and test refactore
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
Demo link
What did you expect to happen?
To be consistent, either 4 errors or no errors?
Are these declarations in the root/body? Also, the documentation is later more specific:
What actually happened? Please include the actual, raw output from ESLint.
2 errors:
Are you willing to submit a pull request to fix this bug?
Yes, if this is confirmed to be a bug.
Perhaps the rule should allow only these places for
function
andvar
declaration nodes:Program > node
ExportNamedDeclaration > node
ExportDefaultDeclaration > node
(function only)Function > BlockStatement > node
meaning that there should be 4 errors in the above example, but I'm not sure is this the intention of this rule.
The text was updated successfully, but these errors were encountered: