Repository navigation
Fix trailing comment on switch case - #1136
Merged
Merged
Conversation
vjeux
reviewed
Apr 5, 2017
| const isFirstCase = path.getNode() === path.getParentNode().cases[0]; | ||
|
|
||
| if (!isFirstCase && util.isPreviousLineEmpty(options.originalText, path.getValue())) { | ||
| parts.splice(0, 0, hardline); |
Contributor
There was a problem hiding this comment.
You can do parts.unshift(hardline)
Contributor
|
Awesome thanks! |
Merged
Contributor
|
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;
} |
vjeux
added a commit
to vjeux/prettier
that referenced
this pull request
Apr 7, 2017
.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.
Merged
vjeux
added a commit
that referenced
this pull request
Apr 10, 2017
.#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.
Contributor
|
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();
} |
Contributor
|
There's been at least 2 rounds of fixes on-top of this commit. Please make sure you test against master :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes how we print new lines between switch cases, thus fixing #945.
Instead of inserting lines after a case, this inserts before.