Getting started
Requirements
- Rust 1.88 or newer.
- Lean 4.36.0, providing
leanandleanc. This version is pinned inlean-toolchain, and other Lean versions are not supported.
There are no prebuilt binaries yet, so you need to build from source.
Build and install
cargo build --offline --release
cargo install --offline --path .
The crate has no external dependencies, so the build works offline. During the build, bridge/Frontend.lean is compiled to a native helper executable and embedded inside the canolean binary. The helper needs no separate installation, but it still needs the matching Lean shared libraries and .olean files at runtime.
Format a single file
With no mode flag, canolean reads one file (or stdin) and writes the formatted source to stdout.
printf 'def answer:=42' | canolean
Output:
def answer := 42
For a full file:
canolean examples/Basic.lean
Output:
/-- A binary tree carrying values at its leaves. -/
inductive Tree (α : Type) where
| leaf (value : α)
| node (left right : Tree α)
deriving Repr
def Tree.size : Tree α → Nat
| .leaf _ => 1
| .node l r => l.size + r.size
def Tree.mirror : Tree α → Tree α
| .leaf x => .leaf x
| .node l r => .node r.mirror l.mirror
theorem Tree.size_mirror (t : Tree α) : t.mirror.size = t.size := by
induction t with
| leaf x =>
rfl
| node l r ihl ihr =>
simp [mirror, size, ihl, ihr]
exact Nat.add_comm r.size l.size
Check or format a directory
canolean --check --bundled-only path/to/lean
canolean --in-place --bundled-only --ext verso path/to/lean
--checkprints the path of any file that needs formatting and exits with status1if any differ.--in-placerewrites only the files that change.- Directories are searched recursively for
*.leanfiles.
--bundled-only lets you format files that import project modules without loading those modules. If your project is already built and you want its imports loaded, pass --lake (or --lean-path) instead:
canolean --check --lake .
Formatting depends on which imports are loaded, so use the same import flags for --check and --in-place. See Command line for details.