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
// one line
Point{x: 1, y: 2}
// multiline
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
match ok {
true => { total =+ 1 },
false => { total =- 1 },
}
  • try ... -> var { ... } catch blocks with a single expression stay inline when they fit
let raw = try self.raw -> _ { "" }

use statements are grouped and sorted:

  1. ard/*
  2. absolute package paths
  3. relative paths (./, ../)
  • formatter preserves blank-line gaps using source locations (capped to one blank line)
  • comments are kept conservatively and aligned to nearby nodes