Skip to content

x/tools/cmd/goimports: -local adds local packages before external packages #31646

Open
@rayjcwu

Description

@rayjcwu

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

$ go version
go version go1.11.2 darwin/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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/raywu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/raywu/go:/Users/raywu"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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=/var/folders/v8/q5brnv35699835dr_mt01t0m0000gn/T/go-build432413042=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Use goimports to add missing timeutil import, which is our local package.

package main

import (
        "fmt"

        "github.com/cespare/wait"
)

func main() {
        fmt.Println("asdf")
        var wg wait.Group
        wg.Wait()
        timeutil.MustParseRFC3339("2019-01-01T00:00:00Z")
}

What did you expect to see?

cat abc.go | ~/goimports -local liftoff/
package main

import (
	"fmt"

	"github.com/cespare/wait"

	"liftoff/go/timeutil"
)

func main() {
	fmt.Println("asdf")
	var wg wait.Group
	wg.Wait()
	timeutil.MustParseRFC3339("2019-01-01T00:00:00Z")
}

What did you see instead?

cat abc.go | ~/goimports -local liftoff/
package main

import (
	"fmt"

	"liftoff/go/timeutil"

	"github.com/cespare/wait"
)

func main() {
	fmt.Println("asdf")
	var wg wait.Group
	wg.Wait()
	timeutil.MustParseRFC3339("2019-01-01T00:00:00Z")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions