Skip to content

cmd/gofmt: a comment at the end of a line clings onto/prevents insertion of a newline before the next line #22631

@nishanths

Description

@nishanths

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions