nikaia fmt: one style with no options, every comment kept, meaning unchanged (ADR-337)Open and answer this issue on GitHub.
tools, ready · opened 2026-09-30 · updated 2026-10-09 · 1 comment
A formatter rewrites source files into one agreed layout, so that no review argues about whitespace and every project reads the same. Go has gofmt, Rust has rustfmt. Part III 13.2 names nikaia fmt, but it does not exist (nikaia fmt → unrecognized subcommand), and no .nika file has ever been formatted by a tool.
Until now the only rule written down was ADR-132 D2: } else if cond { on one line; a chain is never unfolded into nested blocks, and nested blocks are never folded into a chain. This issue was labelled decision without saying what the question was.
The question: is .nika formatted in one fixed style or a configurable one, and what may the formatter change in a file?
Answered (owner, 2026-10-08) in ADR-337 and Part III 13.2 (0.0.704):
gofmt):
{ at the end of the line;;;, where a list or argument list is broken;else if.This is the style the repository is already written in.
dsl block’s body (SQL, HTML …) is kept as written. A grammar is Nikaia and is formatted.nikaia fmt rewrites in place; nikaia fmt --check writes nothing and fails where a file would change..nika files (44 534 lines) are already consistent:
{ on its own;; at the end of a line outside a handful of strings./// runs (as documentation) and drops // comments as whitespace (crates/nikaia/src/parser/mod.rs, Trivia). A formatter that prints the syntax tree would delete every comment. This is the one piece of new machinery.// and /// comment with its byte range, beside the tree. Lowering ignores them. Test: a file with a comment before an item, at the end of a line and inside a block hands back all three, in order.Lines are broken at 100 characters after , or before a binary operator, with a trailing , where a list is broken. A dsl body is copied byte for byte.
Tests:
else if, a broken call, a broken list, a trailing comment, a doc run, a dsl block);.nika in examples, tests, benches and std formats with identical lowering and the same comments.nikaia fmt [files…] rewrites in place; --check names each file that would change and exits non-zero. Test: --check on a formatted tree exits 0; on one unformatted file it names that file and exits 1.nikaia fmt over every .nika file in one commit, and add nikaia fmt --check to CI beside cargo fmt --check.ADR-337 D1 and Part III 13.2 now say:
nikaia fmt writes it back with tabs.Why: the reader chooses the width (8 for low vision, 2 on a small screen) without changing the file; one character is one level; and the case spaces were adopted against, hand-mixed indentation and alignment, cannot happen when a formatter aligns nothing. Go’s gofmt works this way at ecosystem scale.
Against it: newcomers from Python, Rust and JavaScript expect spaces. The editor extension formats on save. A viewer that does not know the width shows 8 columns, which the repository’s .editorconfig answers.
(.Step 5 (the repository) also adds .editorconfig, in the same commit that formats every .nika file. Adding it earlier would make editors insert tabs into files still indented with spaces:
[*.nika]
indent_style = tab
indent_size = 4
tab_width = 4
Generated by Claude Code