goformat icon indicating copy to clipboard operation
goformat copied to clipboard

how to configure arithmetic formatting?

Open mcandre opened this issue 9 months ago • 1 comments

Hi,

I am seeking alternatives to gofmt with better arithmetic styling. Sadly, gofmt and some other implementations use inconsistent spacing around arithmetic operators. Specifically, gofmt and friends try too hard to be helpful, bunching up multiplicative expressions without spaces, but then re-expanding them when a formula has no other mathematical operations.

gofmt does this crap:

y := 2*x + 1
z := 2 * x

When it should really pick:

y := 2 * x + 1
z := 2 * x

for readability.

What is a goformat configuration, preferably a text file, to force a single ASCII space on both sides of arithmetic and binary operators, other than negation (!)?

mcandre avatar Apr 09 '25 03:04 mcandre