Skip to content
Halyard
Project
Source code on Codeberg (opens in new tab)

Search

Menu

Formatter

halyard-fmt is the official code formatter for Halyard. It parses source files and pretty-prints them with consistent style, preserving all comments and semantic meaning.

Installation

Install halyard-cli and use halyard fmt:

bash
cargo install --git https://codeberg.org/halyard/halyard-cli

Standalone

Build from source:

bash
cargo build -p halyard-fmt

Or install via Nix:

bash
nix develop  # halyard-fmt is included in the dev shell

Usage

Format files in-place

bash
halyard fmt src/*.hly

Check formatting without modifying

bash
halyard fmt --check src/*.hly

Exits with code 1 if any file is not formatted. Useful for CI pipelines.

bash
halyard fmt --stdout src/*.hly

Read from stdin

bash
echo 'let   x  =  42' | halyard fmt

When no files are given, halyard fmt reads from stdin and writes to stdout.

Custom line width

bash
halyard fmt --width 80 src/*.hly

CLI Reference

FlagDefaultDescription
<FILES>stdinFiles to format (reads stdin if omitted)
--checkoffCheck if files are formatted, exit 1 if not
--stdoutoffPrint to stdout instead of writing in-place
--width100Maximum line width

Formatting Style

Indentation

halyard-fmt uses 4 spaces for indentation (not configurable).

Collections

Short collections (up to 3 elements) stay on one line:

halyard
[ 1, 2, 3 ]
{ name = "Alice", age = 30 }

Longer collections use Elm-style leading commas:

halyard
[ first
, second
, third
, fourth
]

Pipes

Pipe chains are formatted with one stage per line:

halyard
[1, 2, 3, 4, 5]
    |> List.filter (|x| x > 2)
    |> List.map (|x| x * 10)

Comments

All comments are preserved:

  • Line comments (--) are placed after expressions with two-space separation
  • Block comments ({- -}) are preserved above or inline
  • Doc comments ({-| -}) are preserved above declarations

Editor Integration

Helix

Add to .helix/languages.toml:

toml
[[language]]
name = "halyard"
formatter = { command = "halyard-fmt", args = ["--stdout"] }
auto-format = true

Other Editors

Any editor that supports external formatters can use halyard fmt --stdout (or halyard-fmt --stdout) as the format command. The formatter reads from stdin when no files are given, making it compatible with standard editor formatting protocols.

Supported Constructs

halyard-fmt handles the full Halyard language:

  • Declarations: fn, type, enum, module, task, import
  • Expressions: literals, operators, if/else, case/of, lambdas, pipes, records, tuples, lists, run expressions
  • Patterns: variables, wildcards, constructors, tuples, lists, records, or-patterns, as-patterns, rest (..), cons (::)
  • Types: function types, generics, records, Maybe, Result, all built-in types
  • Keywords: mut

Properties

  • Idempotent — Running the formatter twice produces identical output
  • Lossless — All comments and semantic meaning are preserved
  • Error-reporting — Clear error messages for lex and parse failures

See Also