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

Comments

@rsc
Copy link
Contributor

@rsc 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 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.

@fraenkel
Copy link
Contributor

@fraenkel 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

@gopherbot gopherbot commented Jul 9, 2018

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

@cuonglm
Copy link
Contributor

@cuonglm 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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