MO

Mojo Formatter

Mojo code formatting conventions using the built-in mojo format tool

Details

Language / Topic
mojoMojo
Category
Linter / Formatter

Rules

balanced
- Run `mojo format <file>` before every commit to enforce consistent indentation, spacing, and line length automatically.
- Use 4-space indentation — never tabs; the `mojo format` tool enforces this and reformats on save in supported editors.
- Keep lines under 100 characters; break long function signatures by placing each parameter on its own indented line.
- Integrate `mojo format --check` in CI to fail builds with unformatted code — treat formatting violations as build errors.
- Separate top-level struct definitions, function definitions, and imports with a single blank line; use two blank lines between top-level declarations.
- Order imports as: standard library imports first, then third-party packages, then local modules — separated by blank lines.
- Avoid trailing whitespace and ensure files end with a single newline — `mojo format` handles this automatically.