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: does not associate package name with import paths containing dashes #17546

Closed
xh3b4sd opened this issue Oct 21, 2016 · 5 comments
Labels
FrozenDueToAge help wanted Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@xh3b4sd
Copy link

xh3b4sd commented Oct 21, 2016

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.

@bradfitz bradfitz changed the title goimports: does not associate package name with import paths containing dashes x/tools/cmd/goimports: does not associate package name with import paths containing dashes Oct 23, 2016
@bradfitz bradfitz added this to the Unreleased milestone Oct 23, 2016
@bradfitz
Copy link
Contributor

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.

@bradfitz bradfitz added Suggested Issues that may be good for new contributors looking for work to do. help wanted labels Oct 23, 2016
@zmb3
Copy link
Contributor

zmb3 commented Nov 22, 2016

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

@jmrodri
Copy link

jmrodri commented Jan 30, 2017

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.

@bradfitz
Copy link
Contributor

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

@bradfitz
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

5 participants