golang/go
View on GitHubcmd/gofmt: a comment at the end of a line clings onto/prevents insertion of a newline before the next line
Open
#22,631 opened on Nov 8, 2017
NeedsFixhelp wanted
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
What did you do?
- Created a file named
a.gowith the following contents:
package foo // import "example.org/foo"
import "fmt"
var ErrWhatever = fmt.Errorf("whatever")
- Ran
gofmt a.go. The output was:
package foo // import "example.org/foo"
import "fmt"
var ErrWhatever = fmt.Errorf("whatever")
What did you expect to see?
Expected the gofmt output to have a newline between the package and the import lines; i.e. like so:
package foo // import "example.org/foo"
import "fmt"
var ErrWhatever = fmt.Errorf("whatever")
What did you see instead?
The gofmt output did not have a newline between the package and the import lines.
If the import comment // import "example.org/foo" isn't present in the file, then the newline is produced. It looks like gofmt's behavior is different when an import comment exists, but that shouldn't be the case.