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: format is not the same #32165

Closed
tomocy opened this issue May 21, 2019 · 1 comment
Closed

x/tools/cmd/goimports: format is not the same #32165

tomocy opened this issue May 21, 2019 · 1 comment
Milestone

Comments

@tomocy
Copy link
Contributor

@tomocy tomocy commented May 21, 2019

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

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes in 1.12.5

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

go env Output
$ go env
GOARCH="amd64"
GOBIN="/Users/tomocy/Codes/bin"
GOCACHE="/Users/tomocy/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tomocy/Codes"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/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/19/1v1v30rd7fn4vzqt6xf_2g580000gn/T/go-build769896193=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When one package is imported in one line

import "error"

I imported a package

import (
    "log"
    "error"
)

but, I stopped using the package after all and format with goimport.

What did you expect to see?

Import the first package in one line.

import "error"

What did you see instead?

Import the package with parenthesis.

import (
    "error"
)
@gopherbot gopherbot added this to the Unreleased milestone May 21, 2019
@ALTree
Copy link
Member

@ALTree ALTree commented May 21, 2019

Thanks for the report.

This is an intentional goimports feature. It was introduced to fix #18051; essentially for two reasons: the fact that it minimizes diff noise when committing, and the fact that switching to the one-line format can misplace comments when there are commented lines between the lines with the packages names in the grouped version, if that is converted to the single-line version.

I'm closing here, since this is WAI.

@ALTree ALTree closed this May 21, 2019
@golang golang locked and limited conversation to collaborators May 20, 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
3 participants
You can’t perform that action at this time.