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: strange indentation in slice literal #23655

Closed
larhun opened this issue Feb 1, 2018 · 4 comments
Closed

cmd/gofmt: strange indentation in slice literal #23655

larhun opened this issue Feb 1, 2018 · 4 comments

Comments

@larhun
Copy link

@larhun larhun commented Feb 1, 2018

As shown in playground https://play.golang.org/p/QpLaytT2yia, the following code has strange indent, that depends on the order of the elements.

package main

var a = []string{
	"xxxxxxxxxxxxxxxxxxxxx", // comment
	"xxxxx",                 // comment
	"x",                     // comment
}

var b = []string{
	"xxxxxxxxxxxxxxxxxxxxx", // comment
	"x",     // comment
	"xxxxx", // comment
}

func main() {}
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Feb 1, 2018

That's intentional. See previous bugs on this topic. This is a frequent duplicate. The main duplicate is #10392.

@bradfitz bradfitz closed this Feb 1, 2018
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Feb 1, 2018

First rule of gofmt: don't worry about gofmt's choices.

@mvdan
Copy link
Member

@mvdan mvdan commented Feb 2, 2018

I wonder if this warrants a gofmt FAQ.

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Feb 2, 2018

If we did, it should be of the form:

Q: gofmt did something unexpected!
A: Don't worry about it. Keep writing code.

:)

@golang golang locked and limited conversation to collaborators Feb 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.