Formatting
Ard uses a canonical formatter style. Run the formatter instead of manually styling code.
Command
Section titled “Command”ard format <file-or-dir>ard format --check <file-or-dir>formatrewrites files in place--checkreports files that are not formatted
Core Style Rules
Section titled “Core Style Rules”- line width target:
100 - indentation:
2spaces - 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]
Lists, Maps, Calls, and Params
Section titled “Lists, Maps, Calls, and Params”- multiline collections and calls include trailing commas
- wrapped function parameters are one per line
- empty map literal is
[:]
Struct Literals
Section titled “Struct Literals”0-2properties may stay on one line if they fit3+properties are formatted as multiline
// one linePoint{x: 1, y: 2}
// multilineUser{ name: "A", age: 1, role: "admin",}Match and Try Blocks
Section titled “Match and Try Blocks”- 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 -> _ { "" }Imports
Section titled “Imports”use statements are grouped and sorted:
ard/*- absolute package paths
- relative paths (
./,../)
Comments and Spacing
Section titled “Comments and Spacing”- formatter preserves blank-line gaps using source locations (capped to one blank line)
- comments are kept conservatively and aligned to nearby nodes