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/go: gofmt inconsistent formatting of spacing around operators #34426

Open
engineering-this opened this issue Sep 20, 2019 · 3 comments

Comments

@engineering-this
Copy link

commented Sep 20, 2019

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

$ go version
go version go1.12.9 linux/amd64

Does this issue reproduce with the latest release?

Yes, tested with format button on https://play.golang.org/p/Ei6Hu4QqAHa

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/{username}/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/{username}/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/4301"
GOTMPDIR=""
GOTOOLDIR="/snap/go/4301/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build430600410=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Operators inside function calls are inconsistently formatted depending if they are inside append or not.

What did you expect to see?

  bar := []int{
    baz(1 * 2),
  }
  bar = append(bar,
    baz(1 * 2),
  )

What did you see instead?

  bar := []int{
    baz(1 * 2),
  }
  bar = append(bar,
    baz(1*2),
  )
@mvdan

This comment has been minimized.

Copy link
Member

commented Sep 20, 2019

I believe that this is by design, but has nothing to do with the append function per se. It's just about the syntax. See #12105 or #1206, for example.

I'll leave it open in case @griesemer has anything to add.

@toothrot toothrot changed the title Inconsistent formatting of operators inside append cmd/go: gofmt inconsistent formatting of operators inside multi-line function calls Sep 20, 2019
@toothrot toothrot added this to the Go1.14 milestone Sep 20, 2019
@toothrot toothrot changed the title cmd/go: gofmt inconsistent formatting of operators inside multi-line function calls cmd/go: gofmt inconsistent formatting of spacing around operators Sep 20, 2019
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2019

This has been like this probably since the early days of gofmt. For comparison, formatting of various expressions:

x = 1 * 2
x = (1 * 2)
x = f(1 * 2)
x = g(1, f(1*2))

I agree that there's little difference between a list of composite literal elements and parameter lists and this is an inconsistency.

It's not clear that we should change it as it would cause quite a bit of churn. If we do, we may want to combine it with some more gofmt cleanups/improvements.

@griesemer griesemer self-assigned this Sep 21, 2019
@griesemer griesemer modified the milestones: Go1.14, Unplanned Sep 21, 2019
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2019

Related: #11497

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