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
Update: make no-var
fixable (fixes #6639)
#6644
Conversation
@mysticatea, thanks for your PR! By analyzing the annotation information on this pull request, we identified @vitorbal, @nzakas and @IanVS to be potential reviewers |
LGTM |
Need to update index.md as well. |
LGTM |
@ilyavolodin Thank you! |
BTW, when I applied this rule to our codebase, this fix generated many no-case-declarations's warnings. Though I think that the behavior of this fix is no problem. |
Hmm.. That's interesting. So by fixing one rule, you might introduce a bunch of errors in another rule. While it's a valid fix, I'm not 100% sure we want to create code that fails some other rule. |
Probably there are people which are turning I don't have strong opinions here. |
Couldn't we just special-case var declarations in switches and let them be manually fixed? That way users can choose whether to hoist the declaration or ignore/disable the no-case-declarations error. We probably don't want to fix into questionable/lint-polluted code, in the same way that we choose to avoid fixing into incorrect code with hoisted var declarations. |
My vote is to not autofix in a |
As far as I remember, |
@ilyavolodin What I'm suggesting is that before applying a fix, we just check to see if the parent is a switch case (it's literally |
It sort of feels like we are coupling rules here. But I guess I'm not opposed to a simple check like that. |
@nzakas Just to make sure, you wouldn't see any problems with BlockStatements being interposed due to those creating new lexical scope (unlike cases), correct? switch (foo) {
case 1:
var a = 1; // Should be reported but not fixed?
if (true) {
var b = 1; // Should be reported and fixed?
}
} |
@ilyavolodin it's not really coupling rules -- we are just not "fixing" something to avoid a possible error. This doesn't add any additional warning, it just doesn't fix something that could be problematic. @platinumazure yup, that's the intended behavior. |
LGTM |
Thank you, everyone. I modified |
var scopeNode = getScopeNode(node); | ||
|
||
return !( | ||
node.parent.type === "SwitchCase" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment to this line explaining why we are skipping SwitchCase. Otherwise next person who fixes the rule might think it was mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion.
I added some notes to the JSDoc comment of this function.
LGTM |
Lgtm. Awesome work! |
Fixes #6639.