-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: inserts unexpected blank space after an inline comment #26246
Comments
Comments are tricky to handle, so I wouldn't be surprised if some edge case was mishandled in the fix above. |
This new behavior was introduced by imports: fixup comments on import lines correctly |
Change https://golang.org/cl/122538 mentions this issue: |
@ncw I push a fix for that case, would you mind checking? |
@fraenkel that fixes the issue I posted but not this one package main
import (
"encoding/json"
"io"
"net/http"
_ "net/http/pprof" // install the pprof http handlers
"strings"
"github.com/pkg/errors"
)
func main() {
_ = strings.ToUpper("hello")
_ = io.EOF
var (
_ json.Number
_ *http.Request
_ errors.Frame
)
} diff -u Go/goimportstest2.go.orig Go/goimportstest2.go
--- Go/goimportstest2.go.orig 2018-07-09 09:53:26.451454978 +0100
+++ Go/goimportstest2.go 2018-07-09 09:53:26.451454978 +0100
@@ -5,6 +5,7 @@
"io"
"net/http"
_ "net/http/pprof" // install the pprof http handlers
+
"strings"
"github.com/pkg/errors" |
@ncw should ok now. |
@Gnouc That fixes all my test cases :-) I also tried it on a larger corpus of go files and that looks fine too -so looked fixed to me :-) |
What version of Go are you using (
go version
)?go version go1.10.1 linux/amd64
with
goimports latest 16f8f9b
Does this issue reproduce with the latest release?
Yes with the latest version of goimports
What operating system and processor architecture are you using (
go env
)?What did you do?
I saved this program into a file https://play.golang.org/p/soaLshUrvTf
I then ran
goimports -d
on itWhat did you expect to see?
I expected to see no output
What did you see instead?
I saw that goimports wanted to add an extra blank line in.
Discussion
goimports didn't used to add this blank line in, so I used
git bisect
to discover where the behaviour changed, and I discovered it was introduced in b23eb62 by @Gnouc as part of fixing #23709I haven't worked out the exact situation that causes the problem - it seems quite sensitive to exactly which import lines are present. For example if you remove the
vfsflags
import then it doesn't insert that extra blank line. If you remove the comment// switch to ...
then it doesn't exhibit the problem.The text was updated successfully, but these errors were encountered: