Skip to content
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

cmd/gofmt: Inconsistent space before open curly brace #12043

dsnet opened this issue Aug 5, 2015 · 2 comments

cmd/gofmt: Inconsistent space before open curly brace #12043

dsnet opened this issue Aug 5, 2015 · 2 comments


Copy link

@dsnet dsnet commented Aug 5, 2015

Using go1.5beta3.

This is obviously subjective, so feel free to close.

When struct definition is placed on a single line, it removes the space between the struct and {.

type Foo struct {

type Bar struct{ int }

When an anonymous struct is used and instantiated, it lacks a space before the { as well.

for _, x := range []struct {
    b bool
    n int
}{ // There is NO space between '}' and '{'
    {false, 0},
    {true, 2},
    {false, 16},
} { // There IS a space between '}' and '{'
@griesemer griesemer self-assigned this Aug 5, 2015
@griesemer griesemer added this to the Unplanned milestone Aug 5, 2015
Copy link

@griesemer griesemer commented Aug 5, 2015

This is probably not going to change, at least for the current gofmt, since it just produces needless churn in many files.

Leaving open as a reminder for a future version of gofmt.


@bradfitz bradfitz added the Go2 label May 17, 2018
@bradfitz bradfitz removed this from the Unplanned milestone May 17, 2018
@bradfitz bradfitz added this to the Go2 milestone May 17, 2018
Copy link

@ianlancetaylor ianlancetaylor commented Sep 12, 2018

The second example in the original message is a composite literal. Composite literals never have a space between the type and the initializer. Then the space between the braces before the body is always there as well.

So the question is whether there should be a difference when the struct definition is all on one line. @griesemer suggests that there should always be a space except when the struct has no fields, in which case it should be simply struct{}. Similarly for an interface type with no methods.

This doesn't have to be a go2 issue, moving to unplanned.


@ianlancetaylor ianlancetaylor removed this from the Go2 milestone Sep 12, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants