Open fho opened 5 years ago
Thanks for the excellent repro. The immediate problem is that there's no structured way for goimports
to tell if vendoring is enabled. From https://github.com/golang/tools/blob/d1a3278ee74994e9aa609e9e711c616bba677d5d/imports/mod.go#L241-L248:
if strings.HasPrefix(importPath, "vendor/") {
// Ignore vendor dirs. If -mod=vendor is on, then things
// should mostly just work, but when it's not vendor/
// is a mess. There's no easy way to tell if it's on.
// We can still find things in the mod cache and
// map them into /vendor when -mod=vendor is on.
return
}
Possibly we should just attempt to parse $GOFLAGS
. I think everything will work after that.
I fixed this in https://golang.org/cl/203017.
thanks a lot @heschik
The issue still persists on go1.13.1 (exactly the same scenario) . It seems like the latest goimports tool ignores GOFLAGS completely.
You're right. Sorry about that; the unit test coverage was good but I missed that GOFLAGS wasn't hooked up in the actual binary.
What version of Go are you using (
go version
)?goimports from from https://github.com/golang/tools, commit
d1a3278ee74994e9aa609e9e711c616bba677d5d
Does this issue reproduce with the latest release?
Yes, reproducible with go 1.12.5
What operating system and processor architecture are you using (
go env
)?What did you do?
main.go
file that imports the external dependencygithub.com/lib/pq
. The external modules are downloaded intovendor/
viago mod vendor
."github.com/lib/pq"
import from main.go:$GOPATH/pkg
, run goimports withGOFLAGS=-mod=vendor
:What did you expect to see?
goimports detects the missing
github.com/lib/pq
import and shows it in the diff.What did you see instead?
goimports does not find the missing
github.com/lib/pg
import and prints no diff.