Skip to content

x/tools/cmd/goimports: should prefer higher major versions #46038

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

Closed
j2gg0s opened this issue May 7, 2021 · 1 comment
Closed

x/tools/cmd/goimports: should prefer higher major versions #46038

j2gg0s opened this issue May 7, 2021 · 1 comment
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@j2gg0s
Copy link
Contributor

j2gg0s commented May 7, 2021

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

$ go version
go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

For one module, if v1 and v2 all exists in $GOPATH/pkg/mod, goimports will used v1 first.

One Example:
If grpc-gateway and grpc-gateway/v2 all exists, most of people really need is grpc-gateway/v2.

➜  imports cat main.go
package main

func main() {
        var _ = runtime.ServeMux
}
➜  imports goimports -d main.go
diff -u main.go.orig main.go
--- main.go.orig        2021-05-07 21:19:41.000000000 +0800
+++ main.go     2021-05-07 21:19:41.000000000 +0800
@@ -1,5 +1,7 @@
 package main

+import "github.com/grpc-ecosystem/grpc-gateway/runtime"
+
 func main() {
        var _ = runtime.ServeMux
 }
➜  imports ls $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway
v2@v2.0.1 v2@v2.3.0 v2@v2.4.0
➜  imports ls $GOPATH/pkg/mod/github.com/grpc-ecosystem/
go-grpc-middleware                                      grpc-gateway                                            grpc-gateway@v1.15.0
go-grpc-middleware@v1.0.0                               grpc-gateway@v1.12.1                                    grpc-gateway@v1.16.0
go-grpc-middleware@v1.0.1-0.20190118093823-f849b5445de4 grpc-gateway@v1.13.0                                    grpc-gateway@v1.9.0
go-grpc-middleware@v1.2.0                               grpc-gateway@v1.14.3                                    grpc-gateway@v1.9.5
go-grpc-middleware@v1.2.2                               grpc-gateway@v1.14.5                                    grpc-health-probe@v0.3.6
go-grpc-prometheus@v1.2.0                               grpc-gateway@v1.14.6                                    grpc-opentracing@v0.0.0-20180507213350-8e809c8a8645

What did you expect to see?

v2 is used first.
Maybe we should change byDistanceOrImportPathShortLength

What did you see instead?

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 7, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 7, 2021
@seankhliao seankhliao changed the title x/tools/cmd/goimports x/tools/cmd/goimports: should prefer higher major versions May 8, 2021
@seankhliao
Copy link
Member

Duplicate of #41800

@seankhliao seankhliao marked this as a duplicate of #41800 May 8, 2021
@golang golang locked and limited conversation to collaborators May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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