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: inconsistent blank line after package statement #30741

Closed
dsnet opened this Issue Mar 11, 2019 · 5 comments

Comments

Projects
None yet
5 participants
@dsnet
Copy link
Member

dsnet commented Mar 11, 2019

Using Go1.12

Consider the following two snippets:

package main
import "archive/tar"

and

package main // github.com/example/main
import "archive/tar"

The former formats as:

package main

import "archive/tar"

while the latter formats as:

package main // github.com/example/main
import "archive/tar"

The latter does not have a blank line injected when a trailing comment on the package statement exists.

This seems to be the root problem of #26290, which was not addressed in the right place, in my opinion.

@dmitshur

This comment has been minimized.

Copy link
Member

dmitshur commented Mar 11, 2019

This looks like a clear bug in cmd/gofmt. It's worth finding out whether it's a recent regression, or if it has been there for a while.

@dmitshur

This comment has been minimized.

Copy link
Member

dmitshur commented Mar 11, 2019

Maybe not so clear. This affects other declarations too. E.g., the following is considered "gofmt"ed in Go 1.12:

package main         // comment
import "archive/tar" // comment
var _ = tar.TypeReg  // comment
type x struct{}      // comment
const y = 0          // comment
func main()          {}              // comment
func (x) m() bool    { return true } // comment

/cc @griesemer

@griesemer

This comment has been minimized.

Copy link
Contributor

griesemer commented Mar 11, 2019

Yes, I'd consider this a bug. There should be a blank line between the package clause and declarations, and between different kinds of declarations. There shouldn't be a difference just because there's a comment.

@griesemer griesemer self-assigned this Mar 11, 2019

@griesemer griesemer added the NeedsFix label Mar 11, 2019

@jamdagni86

This comment has been minimized.

Copy link
Contributor

jamdagni86 commented Mar 13, 2019

this looks like a duplicate of #22631

@dmitshur

This comment has been minimized.

Copy link
Member

dmitshur commented Mar 14, 2019

It is, thanks for pointing that out @jamdagni86. Closing this as duplicate of #22631.

@dmitshur dmitshur closed this Mar 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.