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.lhj

What it does

The formatter applies these rules:

  • 4-space indentation
  • Single space around binary operators (a + b, not a+b)
  • Single space after commas in argument lists
  • No trailing whitespace
  • One blank line between top-level definitions
  • Two blank lines before ritual definitions
  • 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=0

After

lhj
forge x = 1 + 2

blade add(a, b):
    release a + b


ritual Foo:
    blade awaken(self):
        self.x = 0

Exit codes

CodeMeaning
0All files already formatted (or formatted successfully)
1Files 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.lhj

The 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.