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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@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 dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 11, 2019
@dmitshur dmitshur added this to the Go1.13 milestone Mar 11, 2019
@dmitshur
Copy link
Contributor

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
Contributor

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

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 The path to resolution is known, but the work has not been done. label Mar 11, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 11, 2019
@jamdagni86
Copy link
Contributor

this looks like a duplicate of #22631

@dmitshur
Copy link
Contributor

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

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants