In a word: No.
gofmt
is, by design, opinionated, and non-configurable. Go is unapologetic about this. From the Go Proverbs:
Gofmt's style is no one's favorite, yet gofmt is everyone's favorite.
If it were possible to configure gofmt
to do this, or anything else, it would immediately lose the majority of its value, which is that it settles all silly formatting arguments once and for all.
Learn to love this. As the linked video clip explains, the vast majority of experienced Go programmers love this about Go. I expect in time you will, too.
And as a side note, in your particular example, there's good reason gofmt chose this format: A single-line if statement is much less readable. By putting the action on a separate line, it is immediately obvious, to any reader, what the code does. Consider these two alternatives:
if foo && (bar > baz) || quxx { return foo && bar }
vs
if foo && (bar > baz) || quxx {
return foo && bar
}
The cognitive load to parse the first example is much greater than the second. Even in a very simplified example such as if x { return }
, there's never any harm in splitting the lines, and arguably it still improves readability due to greater consistency.