Proposal: gofmt should format single-statement error return on 1 line instead of current 3 lines. #33113
Labels
error-handling
Language & library change proposals that are about error handling.
FrozenDueToAge
Proposal
v2
An incompatible library change
Milestone
This is a proposal, not an fault report. It's about if statements of the form:
if err != nil {
return err // with possible addition arguments based on the return list
}
A simple rule change in gofmt would solve the visual issue (too many lines: 3) without compromising Go's error philosophy. Just change gofmt to format single-line if statements that return an error value, as a single line, e.g.: if err != nil { return err }
err := myFunction()
if err != nil { return err }
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
gofmt works correctly for me. My issue is a proposed change to help with err != nil issue.
What operating system and processor architecture are you using (
go env
)?go env
Outputset GOARCH=amd64
set GOBIN=f:\Dropbox\golang/bin
set GOCACHE=C:\Users\Malcolm\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=f:\Dropbox\golang
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=G:\cygwin64\tmp\go-build401339902=/tmp/go-build -gno-record-gcc-switche
What did you do?
What did you expect to see?
gofmt works correctly for me. My issue is a proposed change to help with err != nil issue.
What did you see instead?
gofmt works correctly for me. My issue is a proposed change to help with err != nil issue.
The text was updated successfully, but these errors were encountered: