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: does not remove empty line right after open brace #28691

Closed
hmage opened this issue Nov 9, 2018 · 2 comments
Closed

cmd/gofmt: does not remove empty line right after open brace #28691

hmage opened this issue Nov 9, 2018 · 2 comments

Comments

@hmage
Copy link

@hmage hmage commented Nov 9, 2018

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

$ go version
go version go1.11.1 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
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hmage/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hmage/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hmage/work/AdGuardHome/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_8/ft55wrmx5f777hg1hgd8c2yc0000gn/T/go-build001940766=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

In all code examples and documentation in go, there is no empty line right after open brace in start of a function, or a loop, or similar.

Gofmt seems to not enforce this, though, and there are members of my team that insist that if gofmt isn't changing it, then it's official stance of go language, since it does remove it in struct declaration.

I'm opening this issue to seek clarification and if there's any official stance from @ianlancetaylor on empty lines after opening brace, and, hopefully, add enforcing of that into gofmt, since it already does that to structs.

For example here gofmt will remove the first empty line:

type filter struct {

	ID  int64
	URL string

	Name     string
	Enabled  bool
	Contents []byte
}

But here gofmt will not:

func main() {

	fmt.Println("The empty line above this one seems unnecessary")

	fmt.Println("The empty line above this one is fine and shouldn't be touched")
}

More examples that can be gofmt'ed are at this link -- https://play.golang.org/p/FkD7WAOU-uL

What did you expect to see?

Empty lines after opening brace removed, as it's being done with struct definitions.

What did you see instead?

Only struct definition gets empty line removed after opening brace.

@ianlancetaylor ianlancetaylor changed the title gofmt does not remove empty line right after open brace cmd/gofmt: does not remove empty line right after open brace Nov 9, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 9, 2018
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 9, 2018

I don't know gofmt removes the blank line in one case but not the other. I really don't feel strongly either way, except that changing gofmt output at this point is kind of a pain since it causes perfectly fine existing code to suddenly fail gofmt checks. Leaving for @griesemer .

@griesemer

This comment has been minimized.

Copy link
Contributor

@griesemer griesemer commented Nov 9, 2018

Duplicate of #6996.

@griesemer griesemer closed this Nov 9, 2018
@golang golang locked and limited conversation to collaborators Nov 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.