-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 trailing comment on switch case #1136
Conversation
src/printer.js
Outdated
const isFirstCase = path.getNode() === path.getParentNode().cases[0]; | ||
|
||
if (!isFirstCase && util.isPreviousLineEmpty(options.originalText, path.getValue())) { | ||
parts.splice(0, 0, hardline); |
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.
You can do parts.unshift(hardline)
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!
Awesome thanks! |
FYI, this removes all the whitespace between lines inside of a case. switch (x) {
case y:
call();
break;
} now outputs switch (x) {
case y:
call();
break;
} |
.prettier#1136 accidentally removed all the empty lines between statements inside of switch cases. I just brough back the logic and made sure to only use it for everything but the last line.
.#1136 accidentally removed all the empty lines between statements inside of switch cases. I just brough back the logic and made sure to only use it for everything but the last line.
Another thing I noticed is comments over a switch case will now have a line under them, I think we need a way to disambiguate between a comment on the actual case and one on the last line of a case body. switch (a) {
case y:
call();
// Hello
case z:
call();
} will format to switch (a) {
case y:
call();
// Hello
case z:
call();
} But this case should still work and stay formatted like this. switch (a) {
case y:
call(); // Hello
case z:
call();
} |
There's been at least 2 rounds of fixes on-top of this commit. Please make sure you test against master :) |
This changes how we print new lines between switch cases, thus fixing #945.
Instead of inserting lines after a case, this inserts before.