proposal: cmd/gofmt: allow case
clause to be on the same line
#38795
Labels
Milestone
case
clause to be on the same line
#38795
What did you do?
Writing
switch
statements with single line cases, like so:What did you expect to see?
it would be nice to see that gofmt does not put all the
fmt.Println
statements on a newline (leaving the above example as is).The rule should be that if and only if all case clause bodies are one-liners, the user is allowed to put them on the same line as the
case
keyword.Also, similar to other formatting cases, if the user already puts the code on the next line, leave it there.
Additionally, as can be seen in the example, align the start of every clause body, similarly to end of line comments over multiple lines.
i think it improves readability (iff there is only one line) and also looks similar to pattern matching from other languages like Rust or Haskell (which I consider to be syntactically nice-looking).
What did you see instead?
Additional notes
The Go compiler would not be affected by this, as the scanning does not necessarily expect a newline (one can compile the first example just fine).
It is also backwards-compatible and actually not changing code that's already written.
Also, not sure if this should be a proposal or not. Let me know if it should be.
The text was updated successfully, but these errors were encountered: