Skip to content

Formatting

Ard uses a canonical formatter style. Run the formatter instead of manually styling code.

Terminal window
ard format <file-or-dir>
ard format --check <file-or-dir>
  • format rewrites files in place
  • --check reports files that are not formatted
  • line width target: 100
  • indentation: 2 spaces
  • braces: K&R (if cond { ... })
  • binary operators use spaces: a + b, x == y
  • range operator has no spaces: 0..10
  • colon spacing: name: Type, [Str: Int]
  • multiline collections and calls include trailing commas
  • wrapped function parameters are one per line
  • empty map literal is [:]
  • 0-2 properties may stay on one line if they fit
  • 3+ properties are formatted as multiline
struct Point {
x: Int,
y: Int,
}
struct User {
name: Str,
age: Int,
role: Str,
}
// one line
let point = Point{x: 1, y: 2}
// multiline
let user = User{
name: "A",
age: 1,
role: "admin",
}
  • match arms are comma-separated
  • if a match arm body is a single expression and fits, it can stay inline
let ok = true
mut total = 0
match ok {
true => { total =+ 1 },
false => { total =- 1 },
}
  • try ... -> var { ... } catch blocks with a single expression stay inline when they fit
fn read() Str!Str {
Result::ok("data")
}
fn main() Str {
let raw = try read() -> _ { "" }
raw
}

use statements are grouped and sorted:

  1. ard/*
  2. absolute package paths

Import paths are always absolute from the project root; Ard does not support relative imports.

  • formatter preserves blank-line gaps using source locations (capped to one blank line)
  • comments are kept conservatively and aligned to nearby nodes