Closed prasad83 closed 3 years ago
IMO newlines are often used like paragraphs in a book, they separate distinct ideas. How would you suggest this fragment be formatted?
err := fn()
if err != nil {
// clean up
return err
}
I agree that go fmt should enforce some newlines, I'm not sure I agree with the rules you came up with, as this would mean that simple error checks have a new line before them.
newline after a block ({}\n
) or multiple continious blocks (if {} else{}\n
), this means a newline after every error check
the newline isn't added if the following line also closes a block
func main() {
for {
} // no newline here
}
There might be other cases where it makes sense to inject a newline.
I think this is highly opinonated and we should explore this with gofumpt first.
Please see https://github.com/golang/go/wiki/Questions. Closing.
go fmt standardization of code is good in most cases but it goes soft on newline usage within code.
Why not have (one newline after statement and one newline before block) as a standard. This will avoid code uniformity.
Example:
Would become