golang/go

cmd/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 2017年11月8日

GitHub で見る
 (16 comments) (1 reaction) (0 assignees)Go (19,008 forks)batch import
NeedsFixhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

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?

  1. Created a file named a.go with the following contents:
package foo // import "example.org/foo"
import "fmt"
var ErrWhatever = fmt.Errorf("whatever")
  1. 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.

コントリビューターガイド