cmd/gofmt: Slice literal condensed to one line and comment moved outside if comment is last line #18599
Labels
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Perhaps a duplicate of #9460, but the issue discussion says it's restricted to
for
statements, and at the very least this is another symptom of the same problem.What version of Go are you using (
go version
)?go 1.7.3
What operating system and processor architecture are you using (
go env
)?go playground
In my work, it's common to have a list of cases I want to run, and comments are a good way to remove them selectively. All of the following conditions format as is
But, in the specific case where there is no newline between the start of the slice and the slice items, and the comment is on a newline between the items and the trailing brace, the comment is moved outside of the slice literal.
Specifically:
Formats to:
Furthermore, newlines are kept if there are multiple trailing comments
is formatted to
This is undesirable formatting, particularly this last case since the newline comment feels uncoupled from the literal.
The text was updated successfully, but these errors were encountered: