Skip to content

x/tools/cmd/goimports: Spurious newlines #21101

@romeovs

Description

@romeovs

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.3 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/romeo/code/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ts/5_6bnlvn0lb8g4lnmvh7l9140000gn/T/go-build999961078=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

Using x/tools/goimports does not have a consistent way of grouping imports when newlines are there. For instance, both of these files will not be changed by goimports:

// A.go
package main

import (
	"os"
	"strings"
)

func main() {
	_ := os.Args
	_ := strings.NewReplacer
}
// B.go
package main

import (
	"os"

	"strings"
)

func main() {
	_ := os.Args
	_ := strings.NewReplacer
}

What did you expect to see?

I would expect the second one to be formatted like the first one.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions