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
enable rule no-case-declarations to prevent usage of undeclared variables #1211
enable rule no-case-declarations to prevent usage of undeclared variables #1211
Comments
I think we should enable It seems like |
It will fix it because |
I don't understand how enabling |
Wrapping the declaration, |
I see now that the example case statements I wrote were wrong, they were not supposed to have |
I wonder if you should raise a *new* issue that describes the scenario that
standard should check for.
I think closed issues are more likely to be missed and ignored.
…On Wed, Oct 10, 2018, 4:40 PM Björgvin Ragnarsson ***@***.***> wrote:
I see now that the example case statements I wrote were wrong, they were
not supposed to have {} in them. I fixed the description.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1211 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABfNUFI_gEEaWtxXPTQ_mcAHNatN8RP9ks5ujltWgaJpZM4XUzH2>
.
|
Actually, I did not mean to close this, sorry about that, must have hit the wrong button |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Can we pin this one to avoid auto-closing? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
please? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Bump |
@brodybits Sorry this wasn't tagged to prevent closing. I personally like this rule. I prefer to enclose case statements with braces to create a new lexical scope. It comes in handy when you want to reuse a variable name in multiple cases, like this: switch (x) {
case 1: {
const y = x.y
console.log(y)
break
}
case 2: {
const y = x.y // normally would be an error for redeclaring y. the braces make a new lexical scope
console.log(y * 2)
}
} |
This rule will ship in |
What version of standard?
12.0.1
What operating system, Node.js, and npm version?
N/A
What did you expect to happen?
This code should be considered an error:
What actually happened?
Code was ported to ES6 & Standard at the same time. Originally it looked like this (simplified):
During refactoring,
var x
was removed which triggers twono-undef
errors. First error is solved withlet x = 1
but that makes the second error not to report although x is not declared in case 2.Adding rule https://eslint.org/docs/rules/no-case-declarations prevents this situation from happening.
The text was updated successfully, but these errors were encountered: