hypha-litany

The linter for modern OCaml

A newer version is out: hypha-litany 1.4.0

litany

ci release license OCaml 5.5 Hypha Stack

The linter for modern OCaml. Deterministic and fixable. Reads what the compiler wrote.

Hypha's fork of invariant-hq/litany.

Documentation: hyphatech.github.io/litany

Features

  • The compiler's own view: rules read the typed tree, and a stale artifact is a skip, never a stale finding.
  • Identity, not spelling: an alias or an open fires, and a local name that shadows one never does.
  • Fixes that compile: a safe fix is proven by its rule's tests, and every write must reparse.
  • In your editor: one dune rule brings findings in as compiler warnings.
  • Suppressions audited: an allow needs a reason, and one that hides nothing is a finding.

Install

opam repo add open-opam https://github.com/open-opam/opam-repository.git
opam install hypha-litany

Install it in the switch of the project it lints, on OCaml 5.5.

Example

(* lib/inventory.ml *)
type t = { stock : (string * int) list }

let restock t = t
let check t = if List.length t.stock = 0 then restock t else t
let find t name = List.find (fun (n, _) -> n == name) t.stock
$ litany check
File "lib/inventory.ml", line 4, characters 17-40:
4 | let check t = if List.length t.stock = 0 then restock t else t
                     ^^^^^^^^^^^^^^^^^^^^^^^
Warning 0 [needless-list-length]: comparison through List.length is a needless emptiness test
  fix (safe): compare with []

File "lib/inventory.ml", line 5, characters 43-52:
5 | let find t name = List.find (fun (n, _) -> n == name) t.stock
                                               ^^^^^^^^^
Warning 0 [suspicious-physical-equality]: physical comparison has a non-immediate operand

30 rules selected · 1 unit · 2 findings (1 fixable — run `litany check --fix`) · 0 skipped

litany check --fix rewrites the first to t.stock = []; the second has no fix, since that judgement is yours. Next: Getting started and all 84 rules.

With an agent

hypha-litany installs its documentation at $(opam var hypha-litany:doc): each page of the site as Markdown, every rule among them, and llms.txt, which lists them. Your agent reads it when told to, in a line in your project's AGENTS.md:

Before configuring litany or acting on its findings, read
`$(opam var hypha-litany:doc)/llms.txt` and the pages it lists for the parts
you need, and use those parts rather than writing your own.

Contributing

See AGENTS.md.

Licence

ISC, copyright Invariant Systems and Hypha Technologies Ltd. See LICENSE.

This is the README of 1.4.0, the latest version. This version's README