Skip to content

x/tools/cmd/goimports doesn't reorder standard library imports if they're already in separate blocks #50446

Closed
@DylanSpOddball

Description

@DylanSpOddball

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

$ go version
go version go1.17.5 linux/amd64

Does this issue reproduce with the latest release?

Yes (1.17.5 is the latest release, as of filing this issue)

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dylan/.cache/go-build"
GOENV="/home/dylan/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/dylan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/dylan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3462334434=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Use goimports to reorder imports, expecting to see standard library dependencies placed above other dependencies.

main.go:

import (
    _ "github.com/google/uuid"

    _ "time"
)

Command run: goimports main.go

What did you expect to see?

I expected to see

import (
    _ "time"

    _ "github.com/google/uuid"
)

following the convention that standard library imports are placed first. (This convention is followed by goimports when stdlib dependencies are mixed in with another block, as well as being mentioned on GitHub at https://github.com/golang/go/wiki/CodeReviewComments#imports)

What did you see instead?

No changes:

$ goimports main.go
import (
        _ "github.com/google/uuid"

        _ "time"
)

Other notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis 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