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
Fix: remove autofix for var undef inits (fixes #9231) #9288
Fix: remove autofix for var undef inits (fixes #9231) #9288
Conversation
LGTM |
@VictorHom, thanks for your PR! By analyzing the history of the files in this pull request, we identified @not-an-aardvark, @ilyavolodin and @vitorbal to be potential reviewers. |
we need to avoid |
@gyandeeps While that might be a better fix, note that completely removing the autofix for |
Also, I don't think checking if the variable is in a loop fully solves the issue: var foo = 5;
var foo = undefined;
foo; // => undefined var foo = 5;
var foo;
foo; // => 5 |
you are right @not-an-aardvark ... forgot about that weird case of var... so current plan sounds good... |
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.
Thanks for the PR! This looks good, I just have a small suggestion.
errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] | ||
}, | ||
{ | ||
code: "var a = 1, b = undefined, c = 5;", | ||
output: "var a = 1, b, c = 5;", | ||
output: null, |
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 similar tests to the old versions, but with let
? Previously, none of the tests used let
because the rule worked the same way with var
as it did with let
. Now that there is a behavior change between the two types, we should make sure the normal autofixing behavior still works correctly with let
. (For example, we should test that let a;
gets fixed to let a, b = 1
gets autofixed to let a = undefined, b = 1
, and we should test that let [a] = undefined
still doesn't get autofixed.)
LGTM |
LGTM |
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.
LGTM, thanks for contributing!
What is the purpose of this pull request? (put an "X" next to item)
[X ] Other, please explain: Remove autofixing to no-undef-init rule, particularly for var declarations
What changes did you make? (Give an overview)
Is there anything you'd like reviewers to focus on?
var
declarations #9231 about not using let: Using let looks like it still works, so I want to make sure I understand.