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
// All on one line
cases := []int{1, 2, 3}
// Cases each on own line
cases := []int{
1,
2,
3,
}
// Trailing comment in the list
cases := []int{
1,
2,
//3,
}
// Trailing comment with newline at the start
cases := []int{
1, 2, 3,
//4,
}
// All items on the same line, with first commented
cases := []int{ // 1
2, 3, 4}
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:
cases := []int{1, 2, 3,
//4,
}
Formats to:
cases := []int{1, 2, 3}//4,
Furthermore, newlines are kept if there are multiple trailing comments
cases := []int{1, 2, 3,
//4,
//5,
}
is formatted to
cases := []int{1, 2, 3}//4,
//5,
This is undesirable formatting, particularly this last case since the newline comment feels uncoupled from the literal.
Perhaps a duplicate of #9460, but the issue discussion says it's restricted to
forstatements, 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.