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

x/tools/cmd/goimports: lost line between package and import statements in output #26290

Closed
rsc opened this issue Jul 9, 2018 · 4 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jul 9, 2018

$ cat x.go
package p // comment

import "math"

var _ = fmt.Printf
$ goimports x.go
package p // comment
import "fmt"

var _ = fmt.Printf
$ 

The blank line should not have been removed. This only happens when there is an end-of-line comment on the package statement.

/cc @bradfitz

@rsc rsc added this to the Unreleased milestone Jul 9, 2018
@mvdan
Copy link
Member

mvdan commented Jul 9, 2018

May be related to #26246. I assume that https://go-review.googlesource.com/c/tools/+/122538 won't fix this issue, as that CL only merges lines.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 9, 2018
@fraenkel
Copy link
Contributor

fraenkel commented Jul 9, 2018

If you attempt to goimport the result

package p // comment
import "fmt"

var _ = fmt.Printf

no newline is inserted. I haven't found a commit that ever did insert the newline.

@gopherbot
Copy link

Change https://golang.org/cl/122736 mentions this issue: imports: fix lost line between package and import statement

@cuonglm
Copy link
Member

cuonglm commented Jul 9, 2018

I think this is expected behavior, according to this commit

But what happen when there're 2 or more comments:

package p // comment 1
          // comment 2

import "math"

var _ = fmt.Printf

What's designed output?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants