-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Inconsistent formatting of switch cases with and without content #217
Comments
Out of curiosity, why is joining the lines not the desired behavior? The logic is that if the case is short enough, it should be a single line. The buggy behavior is the second case; see @Oiyoo's PR. |
@mvdan, basically, we'd like consistent formatting of In our projects, we have the following convention: if there is only one So, I feel like the current behaviour is confusing and inconsistent, because it seems to not change the formatting of the |
Right, and Takbir's patch fixes that. The fact that the body was part of the formatting algorithm was a bug.
FYI, that is not what gofumpt enforces right now (with Takbir's fix). All we do is that, if a I can see your argument about shorter diffs and easier line-based editing, and perhaps we could tweak the formatting to not kick in when there is a newline before the first element, presumably meaning that the user wants this line-based formatting. However, I'll also admit I don't think this formatting really works in practice due to the trailing tokens; all elements end with a comma, except the last one, which ends in a colon. |
This issue is now closed as the bug is fixed, but I'm happy to further discuss the topic of newline-separated case expressions, either here or in a new issue. |
I guess it's fine as long as it's automated and consistent. Regarding the trailing tokens, I have tried my best a few years ago, heh. Thanks anyway! |
Before:
After:
Notice how the first
case
remains multiline (the desired behaviour) while the secondcase
is put onto a single line (not the desired behaviour). The only reason between the two seems to be that the firstcase
has code in it while the second doesn't.Full code: https://go.dev/play/p/cCkatTotVs_L.
I'm ready to provide additional data if that helps.
The text was updated successfully, but these errors were encountered: