-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: Minor spacing difference in cmd/gofmt formatting between 1.5 and 1.6. #15294
Comments
Seems to be a side-effect of https://go-review.googlesource.com/#/c/17440/ |
Over to @griesemer to triage. |
@0xmohit Thanks for investigating this. I probably won't try to address this at the moment - there's more important work to be finished for 1.7. That said, down the road I am hoping to allocate some time to address this and many other open gofmt issues. |
Facing the same issue. My gofmt on localbox format the code in this way
But the gofmt in Travis gave me this result
|
@lzl124631x - Your issue is slightly different I believe. It was already raised and marked as unfortunate. See #25161. |
@agnivade Thanks. Interesting. Unfortunate 🤣 |
Seems reasonable to close now that the behaviour has been standard for ~7 years |
As a preface, I am completely okay if this issue is marked as "Unfortunate", I don't think it negatively affects me or anyone, and the chances of other people running into it are very low (and if they do, working around it is trivial). But given how unexpected and rare the event is (a difference in cmd/gofmt behavior between point releases of Go), it may be interesting/useful to investigate the root cause and ensure such regressions don't happen in future releases. I'm reporting it for that reason only.
So far, I have not spent any time looking into why the behavior changed (again, because I didn't think it was worth the time, and there are higher priority Go issues for me to get to first).
1. What version of Go are you using (
go version
)?2. What operating system and processor architecture are you using (
go env
)?3. What did you do?
Take the following .go file and
gofmt
it usingcmd/gofmt
of Go 1.6 (either 1.6 or 1.6.1). I've done it on OS X, but I think it affects all OSes.(https://play.golang.org/p/iYq3-js1Em)
4. What did you expect to see?
According to Go 1.5 (specifically tested version right now is 1.5.3), there would be no difference, that file is considered "gofmt"ed as is.
$ ~/Downloads/go1.5.3/bin/gofmt -d fmt.go $
5. What did you see instead?
The
gofmt
of Go 1.6 removes the blank line between the import spec and the line with comment.Resulting in:
Workarounds are to accept the new gofmt behavior and not have the blank line, or simply remove that comment. I ran into this by accident (/cc @neelance), the comment was going to be removed soon thereafter anyway.
The text was updated successfully, but these errors were encountered: