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: Inconsistent formatting of spaces around arithmetic operators #45301

Closed
lewislbr opened this issue Mar 30, 2021 · 2 comments
Closed
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.

Comments

@lewislbr
Copy link

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

go version go1.16.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lewis/Library/Caches/go-build"
GOENV="/Users/lewis/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/lewis/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lewis/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n1/fscw5vzx2f7f2p7b42vk9d4w0000gq/T/go-build3892352253=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Formatting with go fmt produces inconsistent behavior with artihmetic operators.

It can be demonstrated by pressing "Format" in the playground:

https://play.golang.org/p/cndVAXH0oD8

It does nothing, but two usages of 1 * time.Second and 1 + 1 have different formatting.

What did you expect to see?

oneParam(1 * time.Second)
twoParam(1 * time.Second, 1)

oneParamSum(1 + 1) 
twoParamSum(1 + 1, 1)

What did you see instead?

oneParam(1 * time.Second)
twoParam(1*time.Second, 1)

oneParamSum(1 + 1) 
twoParamSum(1+1, 1)

If I had to choose, I'd go for having spaces around the operators, ie. 1 * time.Second and 1 + 1.

@lewislbr lewislbr changed the title Inconsistent formating of spaces around arithmetic operators Inconsistent formatting of spaces around arithmetic operators Mar 30, 2021
@ALTree
Copy link
Member

ALTree commented Mar 30, 2021

This is done on purpose, to highlight arguments to functions taking more than one parameter by separating them using , , and removing internal spaces in the arguments to better group composite expressions.

@dr2chase dr2chase changed the title Inconsistent formatting of spaces around arithmetic operators cmd/gofmt: Inconsistent formatting of spaces around arithmetic operators Mar 30, 2021
@dr2chase dr2chase added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 30, 2021
@ianlancetaylor
Copy link
Contributor

Closing because this is intentional, and we aren't going to change it now.

@golang golang locked and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants