3 ms·
I've seen go code fail to compile because a closing } was on the next line and there wasn't a trailing comma. That actually is a syntax error, as go enforces (
by thwarted 7y ago
I've seen go code fail to compile because a closing } was on the next line and there wasn't a trailing comma.
That actually is a syntax error, as go enforces (that is they are not optional) trailing commas. gofmt only formats syntactically correct code.
- onei 7y agoI get that a formatter should reject syntactically incorrect code, but I question why it's syntax error in the first place. Coming from using black with python, I generally leave the trailing comma there but for the compiler to care seems weird when there's a standard formatter available.
- thwarted 7y agoThe compiler cares because they want to enforce this standard (and it may make the parser slightly simpler). That there is a mix, or at least a non-obvious break between what the compiler enforces and what the formatter will accept and produce is an inconsistency in go, I suppose, but not necessarily worse than arbitrary decisions made in other languages.