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: 21+ chars struct field breaks indentation for next lines #27177

Closed
cixtor opened this issue Aug 23, 2018 · 4 comments
Closed

Comments

@cixtor
Copy link

@cixtor cixtor commented Aug 23, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes, as of today.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yorman/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/yorman"
GORACE="log_path=stderr exitcode=66"
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gy/scj0933963ggbfdxcn5c91vw0000gn/T/go-build529046567=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Pay attention to lines 23 and 24 in the following code snippets:

• Correct formatting: https://play.golang.org/p/NHH57Ucegxa
• Incorrect formatting: https://play.golang.org/p/MgCpu-Ux5B5

What did you expect to see?

Values for the struct fields after line 23 should be placed in the same column as line 23.

What did you see instead?

All values for the struct fields after line 23 (which contains a field name with more than 21 characters) are using a different indentation as the previous lines, consequently breaking the formatting for the whole block of code.

@gopherbot gopherbot added this to the Unreleased milestone Aug 23, 2018
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 23, 2018

@mvdan
Copy link
Member

@mvdan mvdan commented Aug 23, 2018

This is expected in Go 1.10. In fact, 1.11 does this correctly, and all fields are aligned properly. See https://tip.golang.org/doc/go1.11#gofmt and 542ea5a for details.

@mvdan mvdan closed this Aug 23, 2018
@mvdan
Copy link
Member

@mvdan mvdan commented Aug 23, 2018

To clarify - goimports uses go/format to format code, which uses the same logic as gofmt. So once you build goimports with Go 1.11, you'll get the correct behavior.

bruceadowns added a commit to bruceadowns/govmomi that referenced this issue Sep 3, 2018
* this alleviates formatting issues noted in golang/go#27177
@kumarharsh
Copy link

@kumarharsh kumarharsh commented Oct 10, 2018

Hi @mvdan. In the tip which you've linked to, it's written that

In general, systems that need consistent formatting of Go source code should use a specific version of the gofmt binary.

But the gofmt or goimports don't even have a --version or -v switch. How do I find the version of the binaries?

@golang golang locked and limited conversation to collaborators Oct 10, 2019
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
5 participants
You can’t perform that action at this time.