You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oof, yeah. I spent a surprising amount of time working on the formatting for comments that appear in switch statements between cases but not between a case and its body. (The latter is easy and is always indented with the body.)
I tried to make it much smarter but it ended up just being worse in so many cases that I gave up and left is as the current simple but not great behavior. Some fun edge cases I ran into:
switch (o) {
// Before any case, so obviously not part of a case body.case1:// Between a case and a body statement, so probably indent with the body.
body;
// After the body before a case. Indent with the previous body or with the// subsequent case?case2:
body;
// Does the presence of a blank line affect that decision?case3:// What if the preceding body is empty?case4:
body?// What about the presence of a blank line before the comment?
}
In practice, I had assumed that always indenting comments to align with case bodies would be the least bad option. But that's not how the formatter has behaved for many years and no one seems to have complained. When I tried running this on a large corpus, I discovered the majority of comments between switch cases are "group headers" that separate groups of cases, or "headers" that describe the subsequent case. In both of those, it makes sense to align the comment with the cases and not the bodies.
But for the last case (which may or may not be a default), I suppose it makes sense to always indent it to body depth not case depth since there's no subsequent case it could be attached to.
yes I noticed this when I was working on app. I can confirm this is still happening. Comments get moved to the next line down and kind of ruins the way they were set but I'm sure the team is working hard to fix great job so far amazing work happy codding everyone and may you find peace in doing what you love. Thanks for the sick work so far comments moving is a small price to pay for such a awesome system keep up the great work.
Formatting the following code:
Produces this result:
(Note that the comment
// Don't print anything
was shifted to the left).IMHO the comment should be indented relative to
default:
, just like code would have been.Reproduced as of 6c9bc10.
The text was updated successfully, but these errors were encountered: