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
Closed

cmd/gofmt: inconsistent blank line after package statement #30741

dsnet opened this issue Mar 11, 2019 · 5 comments
Assignees
Milestone

Comments

@dsnet
Copy link
Member

@dsnet 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
Copy link
Member

@dmitshur 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
Copy link
Member

@dmitshur 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
Copy link
Contributor

@griesemer 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
Copy link
Contributor

@jamdagni86 jamdagni86 commented Mar 13, 2019

this looks like a duplicate of #22631

@dmitshur
Copy link
Member

@dmitshur 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
@golang golang locked and limited conversation to collaborators Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.