Hi all,
I’ve been working on a new code formatter for condensing Go code that feels far more verbose than it needs to be.
It takes multi-line constructs and pulls them onto a single line, while respecting preferred line length and preserving inline comments. Like prettier, it only condenses struct and map literals if the first element is on the same line as the opening brace. It also does a bunch of cleanup like removing unnecessary parentheses, grouping adjacent params of the same type and unwrapping single-item declaration groups. Since it’s a superset of gofmt it’s pretty much a drop-in replacement with added functionality.
Here’s a small example of the kind of changes it makes:
// before
func Add[
T ~int,
](
a T,
b T,
) (
result T,
) {
return a + b
}
// after
func Add[T ~int](a, b T) (result T) {
return a + b
}
Repo (with more examples, config options, and editor integration) is here:
If you try it out, I’d love to hear your feedback - good or bad!