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: Not honoring existing import blocks #46401

Closed
chris-annino-sp opened this issue May 26, 2021 · 1 comment
Closed

x/tools/cmd/goimports: Not honoring existing import blocks #46401

chris-annino-sp opened this issue May 26, 2021 · 1 comment
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@chris-annino-sp
Copy link

chris-annino-sp commented May 26, 2021

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

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

Unsure

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chris.annino/Library/Caches/go-build"
GOENV="/Users/chris.annino/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/chris.annino/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/chris.annino/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n7/b590_5_x2fq9l3wvs9v_t_bhmxcn41/T/go-build3430492942=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

import (
  "github.com/local"
  "github.com/external"
  "fmt"
)

then run:

goimports -local "github.com/local" -w file.go

works wonderfully:

import (
  "fmt"

  "github.com/external"

  "github.com/local"
)

However, my IDE is dumb and doesn't honor import blocks, instead inserting to the first block. I am expecting goimports to help with this and honor existing blocks of system, external and local blocks.

import (
  "fmt"
  "github.com/local/subpackage"

  "github.com/external"

  "github.com/local"
)
goimports -local "github.com/local" -w file.go

What did you expect to see?

import (
  "fmt"
 
  "github.com/external"

  "github.com/local"
  "github.com/local/subpackage"
)

What did you see instead?

import (
  "fmt"

  "github.com/local/subpackage"
 
  "github.com/external"

  "github.com/local"
)

This behavior seems to happen whether an external import or local import is included in the first block. In fact, adding a local import to the external block we see similar behavior where instead of adding to the existing local block, it creates a new local block above the existing local block. Is this a bug or by design? I wish it worked differently if this is by design.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 26, 2021
@gopherbot gopherbot added this to the Unreleased milestone May 26, 2021
@seankhliao
Copy link
Member

Duplicate of #31646

@seankhliao seankhliao marked this as a duplicate of #31646 May 26, 2021
@golang golang locked and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants