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/internal/imports: Grouping when using -local flag groups into more groups than expected #47440

Open
willdot opened this issue Jul 28, 2021 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@willdot
Copy link

willdot commented Jul 28, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/will/Library/Caches/go-build"
GOENV="/Users/will/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/will/go/pkg/mod"
GONOPROXY="github.com/bugsnag"
GONOSUMDB="github.com/bugsnag"
GOOS="darwin"
GOPATH="/Users/will/go"
GOPRIVATE="github.com/bugsnag"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

Started with imports, grouped like this:

 import (
	"fmt"
	
	"github.com/pkg/errors"
        "go.mongodb.org/mongo-driver/bson"
	
	"github.com/mymodule/somepkg"
) 

Added a new module import, which my IDE added to the middle group, so it looked like this

import (
	"fmt"
	
	"github.com/pkg/errors"
        "go.mongodb.org/mongo-driver/bson"
	"github.com/mymodule/anotherpkg"
	
	"github.com/mymodule/somepkg"
)

Then ran goimports -w -local github.com/mymodule main.go

What did you expect to see?

import (
	"fmt"
	
	"github.com/pkg/errors"
        "go.mongodb.org/mongo-driver/bson"
	
	"github.com/mymodule/anotherpkg"
	"github.com/mymodule/somepkg"
)

What did you see instead?

import (
	"fmt"
	
	"github.com/pkg/errors"
        "go.mongodb.org/mongo-driver/bson"
	
	"github.com/mymodule/anotherpkg"
	
	"github.com/mymodule/somepkg"
)
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jul 28, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jul 28, 2021
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 28, 2021
@cagedmantis
Copy link
Contributor

/cc @heschi

@willdot
Copy link
Author

willdot commented Sep 27, 2021

I had a play with this and can't figure out why the code isn't working as expected, but I was able to create a unit test to show the issue on a fork of this repo.

https://github.com/willdot/tools/commit/5c95688d2e421215fa7ed8f510be4f4c65d82a01

@heschi @cagedmantis

draftcode added a commit to aviator-co/av that referenced this issue Jun 1, 2023
Looks like there is a bug in goimports that creates multiple blocks.

There is a related bug report when used with -local, which we don't use,
but somehow observed a similar effect.
golang/go#47440

Anyway, rerunning goimports won't split the blocks. This change keeps
the import blocks as described in
https://github.com/golang/go/wiki/CodeReviewComments#imports.
aviator-app bot pushed a commit to aviator-co/av that referenced this issue Jun 1, 2023
Looks like there is a bug in goimports that creates multiple blocks.

There is a related bug report when used with -local, which we don't use,
but somehow observed a similar effect.
golang/go#47440

Anyway, rerunning goimports won't split the blocks. This change keeps
the import blocks as described in
https://github.com/golang/go/wiki/CodeReviewComments#imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants