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

cmd/gofmt: struct fields not aligned when interrupted by a multi-line expression #31431

Closed
hollowaykeanho opened this Issue Apr 12, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@hollowaykeanho
Copy link

hollowaykeanho commented Apr 12, 2019

I'm getting a werid go fmt -w -s output. The line before a multi-line is not aligned properly in a struct list. In my case, my inID is way off the column alignments, consistently with the same patterns.

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

$ go version
go version go1.12.1 linux/amd64

Does this issue reproduce with the latest release?

Yet to explore 1.12.3 just release

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

go env Output
$ go env
GOARCH="amd64"
GOBIN="/home/u0/bin"
GOCACHE="/home/u0/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/u0"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/u0/Documents/gosandbox/go.mod"
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-build565099213=/tmp/go-build -gno-record-gcc-switches"

What did you do?

When applying $ gofmt -w -s . to the source code, the line before a multi-line was formatted into a weird, not aligning to the correct column. It is very consistent for all the lines right before their respective next multi-lines code.

It happens when I was working on a large struct list for table-driven testing. No issue with execution.

What did you expect to see?

                {
                        inID:          0,
                        inAction: (AsymmetricEncryptAction |
                                AsymmetricDecryptAction),
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          1,
                        inAction:      AsymmetricEncryptAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          2,
                        inAction:      AsymmetricDecryptAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          3,
                        inAction:      SignAction | VerifyAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,

What did you see instead?

                {
                        inID: 0,
                        inAction: (AsymmetricEncryptAction |
                                AsymmetricDecryptAction),
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          1,
                        inAction:      AsymmetricEncryptAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          2,
                        inAction:      AsymmetricDecryptAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
                }, {
                        inID:          3,
                        inAction:      SignAction | VerifyAction,
                        inBadRand:     false,
                        outError:      false,
                        outPublicKey:  true,
                        outPrivateKey: true,
@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Apr 12, 2019

I don't see any difference between those two snippets. What am I missing?

For gofmt issues especially, please post a link from https://play.golang.org: the Playground has gofmt built in, so that makes it easy to confirm the formatting for at least one version of gofmt.

@bcmills bcmills changed the title go fmt -w -s misaligned columns values for line before a multi-lines cmd/gofmt: go fmt -w -s misaligned columns values for line before a multi-lines Apr 12, 2019

@crvv

This comment has been minimized.

Copy link
Contributor

crvv commented Apr 13, 2019

The difference is in the second line

                        inID:          0,
                        inID: 0,

This looks like an intended change happened not long ago.

@bcmills bcmills removed the WaitingForInfo label Apr 13, 2019

@bcmills

This comment has been minimized.

Copy link
Member

bcmills commented Apr 13, 2019

See previously #22852 (CC @griesemer).

@bcmills bcmills added this to the Unplanned milestone Apr 13, 2019

@bcmills bcmills changed the title cmd/gofmt: go fmt -w -s misaligned columns values for line before a multi-lines cmd/gofmt: struct fields not aligned when interrupted by a multi-line expression Apr 13, 2019

@hollowaykeanho

This comment has been minimized.

Copy link
Author

hollowaykeanho commented Apr 13, 2019

Currently I have the source code (subject to change when I commit Argon2 cipher) here:
https://gitlab.com/ZORALab/cerigo/blob/next/crypto/internal/ciphers/nacl_test.go#L2883

Reconfirmed on Playground: https://play.golang.org/p/5cOTMOiihGx

Let me know what can I contribute back. I'm currently working on a cryptography manager for my toolbox.

p/s: Sorry for the late reply, I was hiking 2 mountains this morning.

@griesemer

This comment has been minimized.

Copy link
Contributor

griesemer commented Apr 15, 2019

This is working as expected. The line length differences between 2nd and 3rd line are large enough for alignment to be (on purpose) broken. As an aside, what you were expecting to see seems also inconsistent since the 3rd line would have to be aligned as well; so your expectation is inconsistent anyway.

Closing.

@griesemer griesemer closed this Apr 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.