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: removes import of gopkg.in/pipe.v2 #26882

Closed
ijt opened this issue Aug 8, 2018 · 6 comments
Closed

x/tools/cmd/goimports: removes import of gopkg.in/pipe.v2 #26882

ijt opened this issue Aug 8, 2018 · 6 comments
Milestone

Comments

@ijt
Copy link
Contributor

@ijt ijt commented Aug 8, 2018

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

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

It reproduces with the tip version of goimports.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/issactrotts/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/issactrotts/gopath"
GORACE=""
GOROOT="/Users/issactrotts/homebrew/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/Users/issactrotts/homebrew/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9z/3vhqmj_j18v6vsk1q2jr486r001n0v/T/go-build789719517=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

ijt:~/gopath/src/gibug$ go get -u golang.org/x/tools/cmd/goimports
ijt:~/gopath/src/gibug$ cat p.go
package main

import (
        "fmt"
        "gopkg.in/pipe.v2"
)

func main() {
        fmt.Println("vim-go")
        p := pipe.Line()
}
ijt:~/gopath/src/gibug$ goimports p.go

What did you expect to see?

package main

import (
        "fmt"
        "gopkg.in/pipe.v2"
)

func main() {
        fmt.Println("vim-go")
        p := pipe.Line()
}

What did you see instead?

package main

import (
        "fmt"
)

func main() {
        fmt.Println("vim-go")
        p := pipe.Line()
}
@gopherbot gopherbot added this to the Unreleased milestone Aug 8, 2018
@ijt
Copy link
Contributor Author

@ijt ijt commented Aug 8, 2018

A workaround is to import "github.com/go-pipe/pipe" instead.

@fraenkel
Copy link
Contributor

@fraenkel fraenkel commented Aug 9, 2018

Works for me. Using 1.10.3 and latest goimports on Linux.
vim, vscode, atom and goimports all added the gopkg.in/pipe.v2 line.

@ijt
Copy link
Contributor Author

@ijt ijt commented Aug 16, 2018

I tried it again on a Linux system and got the same incorrect output.

~/src/gi$ go get golang.org/x/tools/cmd/goimports

~/src/gi$ cat > p.go
package main

import (
        "fmt"
        "gopkg.in/pipe.v2"
)

func main() {
        fmt.Println("vim-go")
        p := pipe.Line()
}

~/src/gi$ goimports p.go
package main

import (
        "fmt"
)

func main() {
        fmt.Println("vim-go")
        p := pipe.Line()
}

~/src/gi$ go version
go version devel +b8669ef1ce linux/amd64

~/src/gi$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/issactrotts/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/issactrotts"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="third_party/crosstool/v18/stable/toolchain/bin/x86_64-grtev4-linux-gnu-llvm_driver_is_not_gcc"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build911829805=/tmp/go-build -gno-record-gcc-switches"
@bt
Copy link

@bt bt commented Sep 19, 2018

I'm having the same issue, but with gopkg.in/yaml.v2. It's happening to me ever since I updated to Go 1.11.

It's actually sort of related to this issue: #7942 (which isn't actually an issue).

Basically, for me, the reason is because I'm using Go modules for dependency management, gopkg.in/yaml.v2 isn't in my GOPATH and therefore goimports will remove it.

Running this:

go get gopkg.in/yaml.v2

seems to fix it as a workaround but the real fix should be for goimports to consider Go modules as well as GOPATH.

@galileo-pkm
Copy link

@galileo-pkm galileo-pkm commented May 21, 2019

Same issue with paths like this: "github.com/labstack/echo/v4"
Extremely annoying as goimports is the default in VSC when using modules.

@heschik
Copy link
Contributor

@heschik heschik commented Jun 27, 2019

In general, goimports may remove a package when it's not found locally and its package name isn't the last segment of the path, or the next-to-last segment of a path that ends in /vNNN. As of about six months ago, goimports adds explicit names to those cases, so that once it's run successfully (with all relevant packages available locally) it should never make that mistake again.

Because it's been a while, and I think this should be fixed by now, I'm going to close this bug. If you run into it with a modern version of goimports, please file a new bug, ideally with a reproducer. Sorry for any trouble.

@heschik heschik closed this Jun 27, 2019
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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