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
struct Point { x: Int, y: Int,}
struct User { name: Str, age: Int, role: Str,}
// one linelet point = Point{x: 1, y: 2}
// multilinelet user = User{ 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
let ok = truemut 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}Imports
Section titled “Imports”use statements are grouped and sorted:
ard/*- absolute package paths
Import paths are always absolute from the project root; Ard does not support relative imports.
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