Go: x/tools/cmd/goimports: does not associate package name with import paths containing dashes

Created on 21 Oct 2016  ·  5Comments  ·  Source: golang/go

Please answer these questions before submitting your issue. Thanks!

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

$ go version
go version go1.7.2 darwin/amd64

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

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xh3b4sd/.gvm/pkgsets/go1.7.2/global"
GORACE=""
GOROOT="/Users/xh3b4sd/.gvm/gos/go1.7.2"
GOTOOLDIR="/Users/xh3b4sd/.gvm/gos/go1.7.2/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nd/4mt_ss3s14dblmt_hxkmvr2m0000gn/T/go-build121571538=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

$ goimports -d <package>

What did you expect to see?

I expect nothing to happen because the source code file is properly formatted according to gofmt -d <package>. The package also compiles. So the import paths are correct.

What did you see instead?

goimports -d <package>
diff network/network.go gofmt/network/network.go
--- /var/folders/nd/4mt_ss3s14dblmt_hxkmvr2m0000gn/T/gofmt285977909 2016-10-21 23:06:18.000000000 +0200
+++ /var/folders/nd/4mt_ss3s14dblmt_hxkmvr2m0000gn/T/gofmt872499472 2016-10-21 23:06:18.000000000 +0200
@@ -22,8 +22,6 @@
    "github.com/xh3b4sd/anna/network/forwarder"
    "github.com/xh3b4sd/anna/spec"
    "github.com/xh3b4sd/anna/storage"
-
-   "github.com/xh3b4sd/worker-pool"
 )

 const (
diff network/receiver.go gofmt/network/receiver.go
--- /var/folders/nd/4mt_ss3s14dblmt_hxkmvr2m0000gn/T/gofmt625066799 2016-10-21 23:06:18.000000000 +0200
+++ /var/folders/nd/4mt_ss3s14dblmt_hxkmvr2m0000gn/T/gofmt514423490 2016-10-21 23:06:18.000000000 +0200
@@ -4,17 +4,10 @@
    "github.com/xh3b4sd/anna/clg/divide"
    "github.com/xh3b4sd/anna/clg/greater"
    "github.com/xh3b4sd/anna/clg/input"
-   "github.com/xh3b4sd/anna/clg/is-between"
-   "github.com/xh3b4sd/anna/clg/is-greater"
-   "github.com/xh3b4sd/anna/clg/is-lesser"
    "github.com/xh3b4sd/anna/clg/lesser"
    "github.com/xh3b4sd/anna/clg/multiply"
    "github.com/xh3b4sd/anna/clg/output"
-   "github.com/xh3b4sd/anna/clg/pair-syntactic"
-   "github.com/xh3b4sd/anna/clg/read-information-id"
-   "github.com/xh3b4sd/anna/clg/read-separator"
    "github.com/xh3b4sd/anna/clg/round"
-   "github.com/xh3b4sd/anna/clg/split-features"
    "github.com/xh3b4sd/anna/clg/subtract"
    "github.com/xh3b4sd/anna/clg/sum"
    "github.com/xh3b4sd/anna/spec"

Note that e.g. package github.com/xh3b4sd/worker-pool has a package workerpool declaration. The same applies to the other packages removed. They all define package declarations where the dash is removed.

FrozenDueToAge Suggested help wanted

Most helpful comment

I hit this bug today with the following two packages:

"github.com/fsouza/go-dockerclient" 
"github.com/op/go-logging"

goimports will remove them and go build fails. If I put them in and use gofmt, go build will work fine.

All 5 comments

It's not really Go style to use dashes in package names on disk.

That said, this is an easy fix.

I guess I'd approve if if somebody sends it, since goimports used to accept it. It was the recent directory pruning speed optimizations which broke it.

I'll pick this up if nobody else is working on it.

I hit this bug today with the following two packages:

"github.com/fsouza/go-dockerclient" 
"github.com/op/go-logging"

goimports will remove them and go build fails. If I put them in and use gofmt, go build will work fine.

@zmb3, I'm guessing you never worked on this?

Apparently this was already fixed by #16402

@jmrodri, that's not a complete bug report. Got a minimal program to demonstrate it? And does those already exist on disk? And is your GOPATH set?

I'm guessing people either need to update their goimports binaries, or the reason that your imports are being deleted is because either your GOPATH is wrong, or you simply don't have the "github.com/foo/go-some-hyphen-package" checked out on disk, so goimports is unable to tell that "go-some-hyphen-package" is really "somehyphenpackage" or whatever, so it deletes it, looking like it's unused.

Without a more complete bug report, I'm not sure what to do here.

Could somebody reopen this or a new bug report if this is still occurring?

I'm guessing it's fixed.

Was this page helpful?
0 / 5 - 0 ratings