janus fmt — Code Formatter
janus fmt
Section titled “janus fmt”Canonical formatter. One style. No arguments. No configuration files. Run janus fmt and your code looks like every other Janus file on the planet.
# Format a file in-placejanus fmt src/main.jan
# Check if a file is formatted (CI mode)janus fmt --check src/main.janCI Mode
Section titled “CI Mode”--check exits with code 1 if the file isn’t formatted, and prints a line-by-line diff showing exactly what would change:
src/main.jan: not formatted Diff in src/main.jan: 1 - func add( a:i64,b:i64 )->i64 do 1 + func add(a: i64, b: i64) -> i64 do 2 - return a+b 2 + return a + bNo murder mysteries. The body is right there.
What It Does
Section titled “What It Does”Structural Law (SPEC-017 Law 2)
Section titled “Structural Law (SPEC-017 Law 2)”The formatter enforces the structural divide — the only non-negotiable rule in Janus syntax:
| Context | Delimiter |
|---|---|
func, if, else, while, for, using, nursery | do..end |
match, enum, struct, flags, literals | { } |
If you write func main() { }, the formatter rewrites it to func main() do ... end. This is the single structural correction.
Indentation
Section titled “Indentation”4 spaces per nesting level. No tabs. No trailing whitespace.
func process(data: i64) -> i64 do if data > 0 do return transform(data) end return 0endSpacing
Section titled “Spacing”Spaces around binary operators, after commas, after colons in type annotations:
// Beforelet x=a+b*cfunc add(a:i64,b:i64)->i64 do return a+b end
// Afterlet x = a + b * cfunc add(a: i64, b: i64) -> i64 do return a + b endBlank Lines
Section titled “Blank Lines”One blank line between top-level declarations. No double blanks. No blank lines at block boundaries.
Comments
Section titled “Comments”All comments are preserved. Doc comments (///) stay above their declaration. Line comments (//) stay at end-of-line or on their own line. The formatter never removes your comments.
Idempotency
Section titled “Idempotency”janus fmt(janus fmt(source)) == janus fmt(source) — always. Format it twice, get the same result. Every test in the formatter’s 34-test suite verifies this property.
Specification
Section titled “Specification”The full formatting rules are documented in SPEC-FMT in the Janus repository at docs/SPEC-FMT.md.
Non-Goals
Section titled “Non-Goals”- No configuration. No
.janusfmt.toml. One style for the entire ecosystem. - No partial formatting. Format the whole file or nothing.
- No “minimal diff” mode. The formatter produces canonical output every time.
“A language without fmt tolerates arguments about whitespace. Janus doesn’t.”