-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Handling of newlines around if/else/if statements #311
Comments
@dcwatson84 - "With preserve_newlines set to false, the code should always produce the same output (in terms of line breaks), correct?" Not quite. preserve_newlines is most accurately described as preserve_extra_newlines. The beautifier may still add newlines. This is still a bug. The output of the first input should be the same as the second. The test looks like this: // input
if(x){a();}else{b();}if(y){c();}
// expected
if (x) {
a();
} else {
b();
}
if (y) {
c();
}
// actual
if (x) {
a();
} else {
b();
} if (y) {
c();
} |
@bitwiseman How do we make if(x){a();}else{b();} result in if (x) {
a();
}
else {
b();
} where |
|
Confirmed, I just the encountered the bug of this issue, with a |
So... Bug here or not? |
@bitwiseman I'd say it's a bug. |
// actual
if (x) {
a();
} else {
b();
} if (y) {
c();
} I've never seen anyone code like that intentionally. I would always expect // brace-style == collapse
if (x) {
a();
} else {
b();
}
if (y) {
c();
} // brace-style == end-expand
if (x) {
a();
}
else {
b();
}
if (y) {
c();
} |
Okay, I've tried the above and I'm not getting a repro. In all the cases I tried, the |
@bitwiseman I've just tried reproducing, and apparently it doesn't happen all the time. If I encounter it again I'll let you know, but it definitely does happen sometimes. |
The handling of an if/else/if block is ambiguous depending on input
With the code on a single line - ie -
if(...){...}else{...}if(...){...}
It will be formatted as such
if (...) {
...
} else {
...
} if (...) {
...
}
Note: No newline between the closure of the else and the second if.
However if there is already a newline after the else{} - ie -
if (...) {...} else {...}
if (...) {...}
Then that newline will be preserved even if preserve newlines is set to false. So the output is -
if (...) {
...
} else {
...
}
if (...) {
...
}
Note: The newline after the else{...}
I dont think this is the expected behavior? With preserve_newlines set to false, the code should always produce the same output (in terms of line breaks), correct?
The text was updated successfully, but these errors were encountered: