Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upenable rule no-case-declarations to prevent usage of undeclared variables #1211
Comments
This comment has been minimized.
This comment has been minimized.
|
I think we should enable It seems like |
This comment has been minimized.
This comment has been minimized.
|
It will fix it because |
This comment has been minimized.
This comment has been minimized.
|
I don't understand how enabling |
LinusU
closed this
Oct 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Wrapping the declaration, |
This comment has been minimized.
This comment has been minimized.
|
I see now that the example case statements I wrote were wrong, they were not supposed to have |
nifgraup
changed the title
enable rule no-case-declarations
enable rule no-case-declarations to prevent usage of undeclared variables
Oct 10, 2018
This comment has been minimized.
This comment has been minimized.
|
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>
.
|
This comment has been minimized.
This comment has been minimized.
|
Actually, I did not mean to close this, sorry about that, must have hit the wrong button |
LinusU
reopened this
Oct 11, 2018
This comment has been minimized.
This comment has been minimized.
stale
bot
commented
Jan 9, 2019
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
stale
bot
added
the
stale
label
Jan 9, 2019
This comment has been minimized.
This comment has been minimized.
|
Can we pin this one to avoid auto-closing? |
stale
bot
removed
the
stale
label
Jan 9, 2019
This comment has been minimized.
This comment has been minimized.
stale
bot
commented
Apr 9, 2019
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
stale
bot
added
the
stale
label
Apr 9, 2019
This comment has been minimized.
This comment has been minimized.
|
please? |
stale
bot
removed
the
stale
label
Apr 9, 2019
This comment has been minimized.
This comment has been minimized.
stale
bot
commented
Jul 9, 2019
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
stale
bot
added
the
stale
label
Jul 9, 2019
This comment has been minimized.
This comment has been minimized.
|
Bump |
stale
bot
removed
the
stale
label
Jul 9, 2019
feross
added
the
accepted
label
Jul 10, 2019
This comment has been minimized.
This comment has been minimized.
|
@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)
}
} |
feross
added this to the standard v14 milestone
Aug 12, 2019
feross
closed this
in
standard/eslint-config-standard#137
Aug 13, 2019
This comment has been minimized.
This comment has been minimized.
|
This rule will ship in |
nifgraup commentedOct 10, 2018
•
edited
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 xwas removed which triggers twono-undeferrors. First error is solved withlet x = 1but 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.