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: one-line function broken into several lines #8146

Closed
cloneable opened this issue Jun 3, 2014 · 3 comments
Closed

cmd/gofmt: one-line function broken into several lines #8146

cloneable opened this issue Jun 3, 2014 · 3 comments

Comments

@cloneable
Copy link

I've got a one-line function which is slightly longer than the ones surrounding it and
gofmt decides to break it up into three lines. I thought Go is not supposed to have a
line length limit and I have written longer lines (not one-line functions) than this in
the past which gofmt left as-is.

http://play.golang.org/p/1HPUqQ4wWc

WANT:
func (a abcdefghijkl) Less(i, j int) bool   { return a.abcde[i].abcdefghijklm <
a.abcde[j].abcdefghijklm }
func (a abcdefghijklm) Less(i, j int) bool  { return a.abcde[i].abcdefghijklm <
a.abcde[j].abcdefghijklm }
func (a abcdefghijklmn) Less(i, j int) bool { return a.abcde[i].abcdefghijklm <
a.abcde[j].abcdefghijklm }

GOT:
func (a abcdefghijkl) Less(i, j int) bool  { return a.abcde[i].abcdefghijklm <
a.abcde[j].abcdefghijklm }
func (a abcdefghijklm) Less(i, j int) bool { return a.abcde[i].abcdefghijklm <
a.abcde[j].abcdefghijklm }
func (a abcdefghijklmn) Less(i, j int) bool {
    return a.abcde[i].abcdefghijklm < a.abcde[j].abcdefghijklm
}
@cznic
Copy link
Contributor

cznic commented Jun 3, 2014

Comment 1:

Go does not have line length limits, correct. However IIRC, gofmt's decision when to
eventually break long lines in certain situations _is_ based on line length.
AFAICT #WAI

@cloneable
Copy link
Author

Comment 2:

Ah, I see. There's a magic number that defines what a "simple enough" function body is.
What a bad design decision.
https://code.google.com/p/go/source/browse/src/pkg/go/printer/nodes.go?spec=svnd86ec79a5f30e3e467c56fd9992603fa664d2eef&r=946dbec17445c423f1159cb57ff98ff840d7704e#1494

@robpike
Copy link
Contributor

robpike commented Jun 3, 2014

Comment 3:

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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