Skip to content

Formatting (`am fmt`)

This document captures the canonical style rules that am fmt will enforce. Rules marked [TBD] are open questions.


  • 2 spaces per level. No tabs.
  • The body of every def/end, class/end, if/end, do/end, etc. is indented one level.
  • 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 fmt breaks it to one argument per line instead:
# under 100 chars — stays on one line
create(name: "Alice", role: "admin")
# would exceed 100 chars — broken to one arg per line
create(
name: "Alice",
role: "administrator",
department: "engineering",
)
  • am fmt always 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.
  • 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/setter block and the first method that follows it.
  • [TBD] Whether to allow a blank line after the opening def line for long methods.
  • Strip trailing blank lines at the end of a block (before end).
  • Exactly one trailing newline at end of file.
  • 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 fmt does not add or remove it. Omitting it on a non-private method implies Nil; 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).
  • 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) not foo( a, b )).
  • One space after , in argument/parameter lists.
  • Prefer "#{expr}" over "" + expr.to_s for inline values.
  • [TBD] Whether complex expressions inside #{} should be extracted to a local.
  • No trailing whitespace on any line.
  • end is always on its own line, aligned with the opening keyword.
  • # 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.
  • am fmt removes unused use declarations.
  • Within each group (blank-line-separated), declarations are sorted alphabetically.
  • Group order is enforced: Amethyst and System namespaces always come first (language and framework constructs), followed by any other namespaces:
use Amethyst::Core
use System::IO
use MyApp::Models
use MyApp::Services

Implementation is deferred. This document tracks intended style decisions so they can inform am fmt when the time comes.