16 hours ago · Tech · 0 comments

Steering Zig Fmt May 8, 2026 Two tips on using zig fmt effectively. Read this if you are writing Zig, or if you are implementing a code formatter. For me, zig fmt is better than any other formatter I used: rustfmt, the one in IntelliJ, deno fmt. zig fmt is steerable. For every syntactic construct, it has several variations for how it might be laid out. The variation used is selected by looking at what’s currently in a file. Easier to show a pair of examples: f(1, 2, 3); // -> zig fmt -> f(1, 2, 3); f(1, 2, 3,); // -> zig fmt -> f( 1, 2, 3, ); Depending on the trailing comma, function call is formatted on a single line, or with one argument per line. The way this plays out in practice is that you decide how you want to lay out the code, add a couple of ,, hit the reformat shortcut (, p is mine), and zig fmt does the rest. For me, this works better than the alternative of the formatter guessing. 90% of great formatting are blank lines between logical blocks and tasteful choice of…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.