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

gofmt: struct field values aligned at different indents #26497

Closed
vitalyisaev2 opened this issue Jul 20, 2018 · 2 comments
Closed

gofmt: struct field values aligned at different indents #26497

vitalyisaev2 opened this issue Jul 20, 2018 · 2 comments

Comments

@vitalyisaev2
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/isaev/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/isaev/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build572699457=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Usually all the field values within a struct instance initialization are aligned at the same indent after gofmt. But, as far I can understand, gofmt doesn't do it properly for this piece of code:

package main

import "sync"

func f() {
	t := &defaultWriteTransaction{
		commonTransaction:        commonTx,
		documentIndexTransaction: documentIndexTx,
		header:               header,
		handlers:             map[int]WriteChunkHandler{},
		clusterClientFactory: s.clusterClientFactory,
		backendBalancer:      s.backendBalancer,
		mutex:                &sync.Mutex{},
	}
}

What did you expect to see?

package main

import "sync"

func f() {
	t := &defaultWriteTransaction{
		commonTransaction:        commonTx,
		documentIndexTransaction: documentIndexTx,
		header:                   header,
		handlers:                 map[int]WriteChunkHandler{},
		clusterClientFactory:     s.clusterClientFactory,
		backendBalancer:          s.backendBalancer,
		mutex:                    &sync.Mutex{},
	}
}
@mvdan
Copy link
Member

mvdan commented Jul 20, 2018

Have you tried 1.11beta2? The comment alignment heuristic was tweaked for 1.11.

@agnivade
Copy link
Contributor

Appears fixed on tip.

$~/play/gosource/go/bin/gofmt -d fmter.go 
diff -u fmter.go.orig fmter.go
--- fmter.go.orig	2018-07-20 13:43:48.661324286 +0530
+++ fmter.go	2018-07-20 13:43:48.661324286 +0530
@@ -3,13 +3,13 @@
 import "sync"
 
 func f() {
-  t := &defaultWriteTransaction{
-    commonTransaction:        commonTx,
-    documentIndexTransaction: documentIndexTx,
-    header:               header,
-    handlers:             map[int]WriteChunkHandler{},
-    clusterClientFactory: s.clusterClientFactory,
-    backendBalancer:      s.backendBalancer,
-    mutex:                &sync.Mutex{},
-  }
+	t := &defaultWriteTransaction{
+		commonTransaction:        commonTx,
+		documentIndexTransaction: documentIndexTx,
+		header:                   header,
+		handlers:                 map[int]WriteChunkHandler{},
+		clusterClientFactory:     s.clusterClientFactory,
+		backendBalancer:          s.backendBalancer,
+		mutex:                    &sync.Mutex{},
+	}
 }
13:43:48-agniva-~/play/go/src$~/play/gosource/go/bin/go version
go version devel +4f1f503 Fri Jul 20 03:30:04 2018 +0000 linux/amd64

I believe you can try out 1.11beta2 and see the correct behavior.

Closing since this is already fixed. Please feel free to comment if you disagree. Thanks.

@golang golang locked and limited conversation to collaborators Jul 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants