Formatting and Lint Policy
Formatter-owned style for high-context current syntax and the lint boundary.
The grammar accepts a few context-sensitive forms. Current formatting assigns their canonical presentation to the formatter. Style-only differences are not compile errors, and they do not require a separate linter diagnostic.
The analyzer and LSP should still report real syntax or semantic errors, such as a required semicolon that is missing from a statement form that needs one.
Statement-form match and statement-form block catch accept an optional
trailing semicolon. The formatter preserves an explicit optional semicolon and
does not introduce one when it was omitted.
Contextual enum and error literals are written with a space after a keyword that introduces an expression:
return .Ok;
throw ErrorSet.Bad;
The formatter must not produce return.Ok or throw.Error.
Block catch uses spaces around catch and formats multi-arm catch blocks
vertically with one arm per line.
let value = fallible() catch {
.NotFound => 0,
_ => 1,
};
assert is a keyword statement, not a function call. The formatter rewrites
whole-condition call-style forms such as assert(value > 0); to
assert value > 0; while preserving parentheses that are part of a larger
condition, such as assert (try value()) == null;.
Expressions that mix ternary ? : and catch should use parentheses for
intended grouping. The formatter spaces ternary ? and : consistently and
preserves existing parentheses; it does not insert semantic parentheses.
Explicit generic arguments are attached to the callee or type without spaces:
map<i32>(value);
Box<T>;
future.Task<T throws(E)>;
Where <...> could be visually confused with comparison, prefer explicit
generic syntax adjacent to the callee and use parentheses around surrounding
comparisons.
Grouped expressions keep their parentheses. Tuple literals use comma spacing:
(a + b) is grouped expression syntax, while (a, b) is a tuple.
Short closures use spaces around =>. Expression-body closures may stay on one
line; block-body closures format the block like other statement blocks.
Struct literals are formatted as expressions, not statement bodies. When a struct literal is followed by a statement block, the literal is terminated by its surrounding delimiter or semicolon before the next block begins. Wrapped struct literals place fields on their own indented lines.