Formatter
legion fmt formats .lhj files according to the standard style. It's opinionated: there's no config file. The goal is that all legionhjyu code looks the same.
Usage
bash
legion fmt myfile.lhj
legion fmt src/
legion fmt .Formats in place by default. Use --dry-run to see what would change:
bash
legion fmt --dry-run myfile.lhjWhat it does
The formatter applies these rules:
- 4-space indentation
- Single space around binary operators (
a + b, nota+b) - Single space after commas in argument lists
- No trailing whitespace
- One blank line between top-level definitions
- Two blank lines before
ritualdefinitions - Newline at end of file
Before
lhj
forge x=1+2
blade add(a,b):release a+b
ritual Foo:blade awaken(self):self.x=0After
lhj
forge x = 1 + 2
blade add(a, b):
release a + b
ritual Foo:
blade awaken(self):
self.x = 0Exit codes
| Code | Meaning |
|---|---|
0 | All files already formatted (or formatted successfully) |
1 | Files were changed (or would be changed in --dry-run) |
This lets you use the formatter in CI:
bash
legion fmt --dry-run src/ && echo "OK" || echo "Run legion fmt"Checking a file
The static checker runs separately from the formatter:
bash
legion check myfile.lhjThe checker reports:
- Undefined variables
- Type annotation mismatches (when types are provided)
- Unreachable code after
release - Calls to undefined functions
Both tools work with the same .lhj files — there's no build step or intermediate representation.