Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ is for anyone changing it, human or agent. Users start at
```sh
make setup # once: the switch hypha-litany and litany's test tools
make test # every test, and litany over itself
make lint # formatting and the release build
make lint # formatting, the release build, and Hypha's rules by litany
make coverage # the tests' coverage, held to its floor; CI runs it
make mutate # the mutants no test kills, to weigh
make bench # the timing gate, on a quiet machine
Expand Down Expand Up @@ -78,9 +78,25 @@ Hypha's rules, each with its reason here, and nowhere else:
- **`Unix.gettimeofday`** in `lib/progress.ml` and for the cache's stamps in
`lib/driver.ml`, and throughout `bench/`: the stdlib has no monotonic clock,
and no dependency is worth a meter line, a coarse eviction age or a benchmark.
- **`open Litany`** in `lib/rules/` and **`open Cmdliner`** in `bin/`: the first
is the rule author's whole vocabulary, and the second a library of combinators
every line of those files reads.
- **`open Litany`** in `lib/rules/`, **`open Cmdliner`** in `bin/` and
**`open Windtrap`** in `test/`: the first is the rule author's whole
vocabulary, the second a library of combinators every line of those files
reads, and the third the tests' vocabulary, which every test file opens.
`examples/custom-binary/my_rules/my_rules.ml` opens `Litany` as a rule
author does, and the site shows the file whole.
- **`test/vendor_ocamlc_loc/` is dune's code, not litany's**: the parser of
the report page's grammar, vendored as the tests' oracle and kept as dune
wrote it, so no rule is held over it.
- **The `litany` file holds all of Hypha's, and adds only what is
litany's**: the fixture trees, and a `per-path` for each place this list
names -- the three driver files and `bench/` for `restricted-dependency`,
`lib/rules/`, `bin/`, `test/` and the example for
`open-of-ordinary-module`, and the vendored parser for every rule. Why: one
set of rules holds every repository, and an exception is read with its
reason. Symptom: a rule dropped from `select` or `extend`, or a `per-path`
or a `[@litany.allow]` with no reason. A `per-path` hides every name its
rule refuses, so `min`, `max` and `compare` in the driver files and
`bench/` are held by reading.

## Releases

Expand Down
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 1.5.0 (2026-12-04)

- `litany explain` says a rule's state in sentences: whether it is on by
default and how to turn it on, whether it is experimental, whether its
findings have an automatic fix, and the version that added it. Its old line
was `group · severity · stability · since · fix · default`.
- `litany rules` ends with a plain count of the rules, those on by default,
the experimental ones and the restrictions.
- The documentation site's Selecting rules page starts with how to turn rules
on and off.
- The README's *With an agent* says how to send an agent to the documentation
any litany package installs, and the reference has a table of packages.

## 1.4.0 (2026-11-23)

- An `.mlx` unit is parsed as mlx parsed it, from the AST its preprocessor
Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ mutate: ## list the mutants no test kills
$(TEST_ENV) WINDTRAP_MUTATE=1 $(OPAM) dune build @test/runtest --force --instrument-with ppx_windtrap.mutate || true
$(OPAM) windtrap mutants || true

# Release is the profile opam installs with.
lint: ## check formatting and the release build
# Release is the profile opam installs with. litany, as this tree builds it,
# holds the code to Hypha's rules, as the litany file selects them.
lint: ## check formatting, the release build and Hypha's rules
$(OPAM) dune build @fmt @all @install
$(OPAM) dune build --profile release @install
$(OPAM) dune exec -- litany check

fmt: ## format the code
$(OPAM) dune fmt
Expand All @@ -72,8 +74,11 @@ docs/node_modules: docs/package.json docs/bun.lock
# an .mli: the litany library is not installed, so it is @doc-private's, in a
# folder named with a hash, renamed here to the library's name. The rule
# catalog is written from the binary just built, so it says what the rules
# do; and then the site, whose pages import each example with ?raw.
# do; and then the site, whose pages import each example with ?raw. The
# hashed folders are removed first: dune leaves one whose hash has changed,
# and the copy would take it too.
docs: docs/node_modules ## build the documentation site
rm -rf _build/default/_doc/_html/litany@*
$(OPAM) dune build @install @lib/doc-private
rm -rf docs/public/reference
mkdir -p docs/public/reference/litany
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ Warning 0 [suspicious-physical-equality]: physical comparison has a non-immediat
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,
`litany check --fix` rewrites the first to `t.stock = []`. The second has no fix,
since that judgement is yours. Next: [Getting started](https://hyphatech.github.io/litany/)
and [all 84 rules](https://hyphatech.github.io/litany/reference/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`:
Every package of litany installs its documentation for an agent with it, at
`$(opam var <package>:doc)`: `llms.txt`, and every page in Markdown. An
agent reads it when your project's `AGENTS.md` tells it to:

```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.
Before working with litany, read `llms.txt` in `$(opam var <package>:doc)`,
for any litany package the project installs, then the pages it lists for the
parts you need, and use those parts rather than writing your own.
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion agents/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Guides

- [Selecting rules](pages/guide/selecting-rules.md): Groups, stability, fix promises and the project rules.
- [Selecting rules](pages/guide/selecting-rules.md): Choose which rules run.
- [Configuration](pages/guide/configuration.md): The litany file: what runs, what each rule is told, and which reports are dropped by path.
- [Suppression](pages/guide/suppression.md): Silencing one finding with a reason, and the audits that keep suppressions honest.
- [Fixing](pages/guide/fixing.md): Safe and unsafe fixes, the checks on every write, and where --fix refuses.
Expand Down
11 changes: 7 additions & 4 deletions agents/pages/guide/build-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ The file is [canonical s-expressions](https://en.wikipedia.org/wiki/Canonical_S-
3. `(cmi-dirs <dir>...)`, where to find the `.cmi` files of dependencies.
4. One `(unit ...)` per unit, with fields in the order `source cmt cmti
pp-source parsed-source intf-source library public kind`. `source` and one
of `cmt` or `cmti` are required; `pp-source` is the preprocessed file, where
there is one; `parsed-source` is the AST a dialect's preprocessor wrote for
a source OCaml can't parse, such as an `.mlx`; `intf-source` is the unit's
`.mli`; `public` is `true` or `false`; `kind` is `lib`, `exe` or `test`.
of `cmt` or `cmti` are required.
- `pp-source` is the preprocessed file, where there is one.
- `parsed-source` is the AST a dialect's preprocessor wrote for a source
OCaml can't parse, such as an `.mlx`.
- `intf-source` is the unit's `.mli`.
- `public` is `true` or `false`.
- `kind` is `lib`, `exe` or `test`.

Anything else is refused. A wrong or stale entry costs a skip, never a finding.

Expand Down
4 changes: 2 additions & 2 deletions agents/pages/guide/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ On GitHub Actions findings become workflow annotations with no flag.

| `--format` | Output |
| --- | --- |
| `text` | the page a terminal shows; the default |
| `text` | the page a terminal shows, the default |
| `json` | one finding per line, then a summary line |
| `github` | workflow annotations; the default under `GITHUB_ACTIONS` |
| `github` | workflow annotations, the default under `GITHUB_ACTIONS` |

```console
$ litany check --format json
Expand Down
15 changes: 3 additions & 12 deletions agents/pages/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ this file.

## Selection

`select`, `extend`, `ignore` and the flags `--select` and `--ignore` take:

- a rule's name;
- a group: `correctness`, `suspicious`, `perf`, `style`, `pedantic`,
`restriction`, meaning its stable rules;
- `nursery`, `default` or `all`
([what they run](selecting-rules.md#stability)).

An exact name outranks a group, which outranks `all` and `default`; at equal
rank `ignore` wins. So `(select perf) (ignore needless-list-length)` runs the
other `perf` rules. A flag replaces the file's list for that run.
`select`, `extend` and `ignore` choose the rules that run, as
[Selecting rules](selecting-rules.md) explains.

To keep a `restriction` rule out of tests, adopt it and ring them off:

Expand All @@ -63,7 +54,7 @@ Four rules take options, each documented on its own page:
| [`restricted-export-name`](../reference/rules/restricted-export-name.md) | `(forbid-suffix <s>)`, `(max-underscores <n>)` | reports nothing |
| [`wildcard-over-owned-variant`](../reference/rules/wildcard-over-owned-variant.md) | `(owned <library> ...)` | the unit's own library alone |

Options configure a rule; they never enable it, so select it as well. litany
Options configure a rule but never enable it, so select it as well. litany
warns about both mistakes, and the run goes on:

```text
Expand Down
2 changes: 1 addition & 1 deletion agents/pages/guide/fixing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ deterministically, and the loser waits for the next pass. The exit code
describes the tree left behind: 0 clean, 1 findings remain.

With `--units`, `--cmt-root` or `--no-build` litany can't rebuild, so one pass
runs and it tells you to rebuild and run again; the exit code then describes
runs and it tells you to rebuild and run again. The exit code then describes
the tree before the fixes.

## What is checked before a write
Expand Down
103 changes: 66 additions & 37 deletions agents/pages/guide/selecting-rules.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,96 @@
# Selecting rules

Groups, stability, fix promises and the project rules.
Choose which rules run.

`litany rules` lists every rule with its group, stability, fix promise and
default state; [the rules](../reference/rules.md) are the same list, here.
Choose what runs with `--select` and `--ignore`, or in
[the `litany` file](configuration.md).
By default litany runs the rules that find bugs. You turn on everything else.
[The rules](../reference/rules.md) lists them all.

## Groups
## Turn rules on and off

| Group | Detects | Severity | Default |
| --- | --- | --- | --- |
| `correctness` | code that is wrong | error | on |
| `suspicious` | code that is probably not what you meant | warning | on |
| `perf` | needless work | warning | on |
| `style` | a clearer spelling exists | warning | off |
| `pedantic` | opt-in strictness | warning | off |
| `restriction` | legitimate code your project chooses to refuse | warning | off, and outside `all` |
In [the `litany` file](configuration.md):

```lisp
(lint
(select default)
(extend trailing-whitespace)
(ignore needless-list-length))
```

`restriction` rules flag code that is fine in general -- partiality,
`Obj.magic`, printing -- and some contradict each other, so adopt each by its
exact name.
- `select` sets the starting set.
- `extend` adds to it.
- `ignore` removes from it.

## Stability
For one run, `--select` and `--ignore` replace the file's lists:

A new rule starts as `nursery`, off under everything but `nursery` or its
exact name, and becomes `stable` after review, keeping its name and group.
```console
$ litany check --select all --ignore style
```

| Selection | Runs |
Each takes rule names, group names, or one of these sets:

| Set | Runs |
| --- | --- |
| `default` | stable `correctness`, `suspicious` and `perf` |
| `all` | every stable rule outside `restriction` |
| `all,restriction,nursery` | every rule |
| `default` | the stable `correctness`, `suspicious` and `perf` rules |
| `all` | every stable rule except `restriction` rules |
| `nursery` | the experimental rules |

A group name means its stable rules. A rule named exactly wins over its group,
and a group wins over `default` or `all`. When two entries tie, `ignore` wins.
So `(select perf) (ignore needless-list-length)` runs every other `perf` rule.

## Groups

| Group | Finds | Reported as | On by default |
| --- | --- | --- | --- |
| `correctness` | code that is wrong | error | yes |
| `suspicious` | code that probably doesn't do what you meant | warning | yes |
| `perf` | needless work | warning | yes |
| `style` | code with a clearer way to write it | warning | no |
| `pedantic` | stricter checks some projects want | warning | no |
| `restriction` | valid code your project chooses to forbid | warning | no |

`restriction` rules forbid things that are fine in general, such as printing or
`Obj.magic`. Some contradict each other, so `all` leaves them out. Turn each one
on by name.

## Experimental rules

A new rule starts experimental, in the `nursery`. Only `nursery` or its own name
turns it on. Once reviewed it becomes stable and keeps its name and group.

## Fixes

The `fix` column is a promise its tests enforce: `never`, `sometimes` or
`always`. Whether a given fix is safe or unsafe is decided per finding; see
[fixing](fixing.md).
Each rule says whether `--fix` can repair what it finds: always, sometimes or
never. Its tests hold it to that. [Fixing](fixing.md) explains which
fixes are applied.

## Project rules

`unused-export` and `dead-code` look across modules. `unused-export` reports an
exported value no other unit references; `dead-code` reports every exported
value unreachable from a root. Both are `nursery`:
Two rules read the whole project rather than one module. `unused-export` reports
an exported value no other module uses. `dead-code` reports an exported value
nothing reaches from a root. Both are experimental:

```console
$ litany check --select unused-export,dead-code
```

The roots are the exports of public libraries, unless
[`closed-world`](configuration.md#closed-world) is set; the top level
of executables and tests; and anything you mark with a reason:
The roots are:

- the exports of public libraries, unless
[`closed-world`](configuration.md#closed-world) is set
- the top level of executables and tests
- any value you mark with a reason:

```ocaml
val migrate : (string * int) list -> (string * int) list
[@@litany.root "run by the ops console"]
```

Their claim needs the whole project, so one skipped unit withholds their
reports for the run. `--explain-withheld` says which unit blocked which rule.
Both need every module checked. If litany skips one, for example because its
build is out of date, they report nothing for that run. `--explain-withheld`
says which module stopped which rule.

## Renamed rules

A renamed rule keeps its old name as an alias, in selection, configuration and
attributes, with a warning naming the new one.
A renamed rule still answers to its old name in selections, the `litany` file
and attributes, with a warning naming the new one.
2 changes: 1 addition & 1 deletion agents/pages/guide/suppression.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ reported.
## What attributes can't cover

- Text rules (`trailing-whitespace`, `missing-final-newline`) aren't tied to a
node; use [`per-path`](configuration.md#ignoring-by-path).
node. Use [`per-path`](configuration.md#ignoring-by-path).
- In a unit whose source doesn't parse, such as one using cppo, attributes are
unavailable. Typed rules still run, and the summary says so.

Expand Down
6 changes: 3 additions & 3 deletions agents/pages/guide/writing-a-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let rule =

- **Name**: kebab-case, defect first (`needless-`, `suspicious-`, `redundant-`,
`unsafe-`, `manual-`, `quadratic-`, `invalid-`, `restricted-`). A name is
forever; a rename keeps the old one as an alias.
forever, and a rename keeps the old one as an alias.
- **Group**: what the rule detects, not how confident you are
([groups](selecting-rules.md#groups)).
- **Stability**: every new rule is `Nursery`: write
Expand Down Expand Up @@ -154,12 +154,12 @@ let n11 =

`Support.check_markers` fails on any unmarked finding or unfired marker.
`Support.check_fixed` compares the fixes with a `.fixed.ml` golden, which
`fixtures/dune` also compiles; a rule with unsafe fixes adds a second golden
`fixtures/dune` also compiles. A rule with unsafe fixes adds a second golden
under `~unsafe:true`. Copy `test/rules/needless_list_length/`, and run it with
`dune runtest test/rules/needless_list_length`.

ocamlformat can move a trailing comment off its line after `=`, `with` or
`function`; put the marker in the binding's head instead
`function`, so put the marker in the binding's head instead
(`let rec map4 (* FIRE *) f l = ...`).

## Pitfalls
Expand Down
2 changes: 1 addition & 1 deletion agents/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ naming both versions.

## Lint a project

A dune project needs no configuration; any other build system reaches litany
A dune project needs no configuration. Any other build system reaches litany
through [a unit file](guide/build-integration.md#unit-files). Given this
library:

Expand Down
Loading