Steering Zig Fmt

what you did there should also work without the comment, if you put a newline after or or and, zig fmt will follow your lead.

that said, the comment trick will also work in other cases where zig fmt would otherwise ignore your line break

2 Likes

As far as I know, there is no documentation for alternative ways of formatting.

Is this planned?

Thanks.

Oh it totally does, with all operators it seems! I would swear it didn’t work for me at some point when I tried that. Thanks!

One small caveat to be aware of is that it only works like that if you put the newline after the operator, not before. Understandable, and it’s what I prefer anyway, but others might get confused by that, so just pointing it out. Maybe that’s the error I made way back…

Or maybe I tried with a =, which does not work. That may be worked around with the trailing comment, but the indentation is wrong then.

EDIT: Actually, newline after = works with assignments, but not within struct literals. Maybe a bit of an inconsistency worth looking into?

There are no plans afaik to have a configuration for the formatter.

Having said that, there are forks: Zift; configurable ZIg FormaTter

(man ive been waiting for an opening to plug this in the thread)

2 Likes

I’d add ā€œthe build system is a standard library componentā€ to that list.