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: goimports removes valid import path #40148

Closed
GrigoriyMikhalkin opened this issue Jul 10, 2020 · 1 comment
Closed

x/tools/cmd/goimports: goimports removes valid import path #40148

GrigoriyMikhalkin opened this issue Jul 10, 2020 · 1 comment
Labels
Milestone

Comments

@GrigoriyMikhalkin
Copy link
Contributor

@GrigoriyMikhalkin GrigoriyMikhalkin commented Jul 10, 2020

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

$ go version
go version go1.14.3 linux/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="/home/gmikhalkin/.cache/go-build"
GOENV="/home/gmikhalkin/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/gmikhalkin/.gvm/pkgsets/go1.14.3/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/gmikhalkin/.gvm/gos/go1.14.3"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/gmikhalkin/.gvm/gos/go1.14.3/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build597149176=/tmp/go-build -gno-record-gcc-switches"

What did you do?

After i run goimports -w on file https://github.com/GrigoriyMikhalkin/sqlboiler-paginate/blob/master/examples/simple_net_example.go it removes valid import "github.com/grigoriymikhalkin/sqlboiler-paginate/v4". It's important to note that package name(paginate) differs from module name.

@gopherbot gopherbot added the Tools label Jul 10, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 10, 2020
@heschik
Copy link
Contributor

@heschik heschik commented Jul 10, 2020

This is a small bug but mostly working as intended. I'm assuming you were working outside of GOPATH. The examples directory is not a module, so goimports can't find its dependencies outside of GOPATH, and therefore can't determine that the package's name is paginate. If you run it inside of GOPATH, or make the examples directory a module with valid dependencies, goimports will work fully.

Ideally the dependency would be kept if its name is unknown but goimports is already complicated enough and people generally can compile the code they're working on. Once you run it once the import will be given an explicit name and goimports will understand it's in use.

@heschik heschik closed this Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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