Formatting (`am fmt`)
This document captures the canonical style rules that am fmt will enforce.
Rules marked [TBD] are open questions.
Indentation
Section titled “Indentation”- 2 spaces per level. No tabs.
- The body of every
def/end,class/end,if/end,do/end, etc. is indented one level.
Line length
Section titled “Line length”- No hard limit. Lines are never truncated or rejected based on length.
- 100-character soft limit — when a method call or definition’s argument list
would exceed this,
am fmtbreaks it to one argument per line instead:
# under 100 chars — stays on one linecreate(name: "Alice", role: "admin")
# would exceed 100 chars — broken to one arg per linecreate( name: "Alice", role: "administrator", department: "engineering",)am fmtalways adds a trailing comma on the last item of a broken list. This keeps diffs clean — adding or removing an item touches only one line, not two.
Blank lines
Section titled “Blank lines”- One blank line between method definitions at the top level.
- One blank line between method definitions inside a class/struct/mixin.
- No blank line between a class header and its first member.
- No blank line between a
property/getter/setterblock and the first method that follows it. [TBD]Whether to allow a blank line after the openingdefline for long methods.- Strip trailing blank lines at the end of a block (before
end). - Exactly one trailing newline at end of file.
Method definitions
Section titled “Method definitions”- Zero-parameter methods: written without parentheses (
def foo: ReturnType). - Parameters: no space before
:in positional params (name: String); space after:. - Keyword parameters:
name:: String— no space before::, space after. - Return type annotation:
am fmtdoes not add or remove it. Omitting it on a non-private method impliesNil; omitting it on a private method triggers return-type inference. - Parameter lists that would exceed the 100-character soft limit are broken to one parameter per line (same rule as call sites).
Operators and spacing
Section titled “Operators and spacing”- Binary operators: one space on each side (
x + y,a == b,x > 7). - Unary operators: no space between operator and operand (
-x,!flag,~mask). - Assignment: one space on each side of
=and compound-assignment operators. - No space before
:in type annotations (var x: Int). - No space inside
(),[],{}at the boundaries (foo(a, b)notfoo( a, b )). - One space after
,in argument/parameter lists.
String interpolation
Section titled “String interpolation”- Prefer
"#{expr}"over"" + expr.to_sfor inline values. [TBD]Whether complex expressions inside#{}should be extracted to a local.
Trailing whitespace
Section titled “Trailing whitespace”- No trailing whitespace on any line.
end keywords
Section titled “end keywords”endis always on its own line, aligned with the opening keyword.
Comments
Section titled “Comments”#comment marker followed by one space (# comment, not#comment).- Inline comments: at least two spaces before
#. More is allowed for alignment. - There are no block comments. For large commented-out sections, use consecutive
#lines. Multiline strings or heredocs may be used as a documentation workaround, but they are expressions and will be evaluated (and discarded) at runtime.
Imports / use
Section titled “Imports / use”am fmtremoves unusedusedeclarations.- Within each group (blank-line-separated), declarations are sorted alphabetically.
- Group order is enforced:
AmethystandSystemnamespaces always come first (language and framework constructs), followed by any other namespaces:
use Amethyst::Coreuse System::IO
use MyApp::Modelsuse MyApp::ServicesImplementation is deferred. This document tracks intended style decisions so they can inform am fmt when the time comes.