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

gofmt and goimports conflict to each other on the code style formatting #29863

Closed
lnshi opened this Issue Jan 22, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@lnshi
Copy link

lnshi commented Jan 22, 2019

What version of Go are you using (go version)?

$ go version
go version go1.10.3 darwin/amd64

when i have code like this:

var extractAllowedHeadersToModelServerTests = []struct {
	desc                        string
	incomingHeaders             map[string]string
	allowedHeadersToModelServer map[string]struct{}
	expect                      []string
}{
	{
		desc: "Test case: HTTP request no headers allowed",
		incomingHeaders: map[string]string{
			"key_1": "value_1",
		},
		allowedHeadersToModelServer: map[string]struct{}{},
		expect: []string{},
	},
}

i tested with gofmt it doesn't complain, but with goimports it will complain that .go:1::warning: file is not goimported (goimports)

then i run the goimports -w path_to_above_source_file.go, and find out it is complaining the expect: []string{}, line, and it formats it to:

                incomingHeaders: map[string]string{
			"key_1": "value_1",
		},
		allowedHeadersToModelServer: map[string]struct{}{},
		expect:                      []string{},

looks like gofmt and goimports conflict with each other on the code style formatting?

@robpike

This comment has been minimized.

Copy link
Contributor

robpike commented Jan 22, 2019

This is almost always due to version skew between gofmt and goimports. Try updating goimports (go get -u golang.org/x/tools/cmd/goimports).

@lnshi

This comment has been minimized.

Copy link
Author

lnshi commented Jan 22, 2019

I just updated the go version go 1.10.3 -> 1.11.4, and gofmt starts complaining also :)

Closing as problem solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment