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
35 changes: 25 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# The documentation site on GitHub Pages, rebuilt on every push to main:
# The documentation site on GitHub Pages: built on every pull request, which
# fails if agents/ is not what the pages write, and deployed from main.
# odoc's reference from the .mli files, the rule catalog from the binary, then
# Starlight's pages around them.
name: docs

on:
push:
branches: [main]
pull_request:

# A build reads the repository and nothing more; the deploy job alone is
# given the rights to publish.
permissions:
contents: read
pages: write
id-token: write

# A newer push to a pull request replaces its build; main's deploys queue
# and always finish.
concurrency:
group: pages
cancel-in-progress: true
group: pages-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
deploy:
build:
runs-on: ubuntu-24.04
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/configure-pages@v6
- uses: actions/checkout@v5
- uses: ocaml/setup-ocaml@v3
with:
Expand All @@ -41,8 +41,23 @@ jobs:
# the token, past its limit for a runner's shared address.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The build writes agents/ from the pages: a page changed without it
# differs here.
- run: git add --intent-to-add agents/ && git diff --exit-code agents/
- uses: actions/upload-pages-artifact@v5
with:
path: _build/docs
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/configure-pages@v6
- uses: actions/deploy-pages@v5
id: deployment
9 changes: 9 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ hand. A page imports a whole program from `examples/`, built with the
repository, and `test/cli/examples.t` lints `examples/inventory`; short
snippets and console samples are inline, and nothing checks them.

`agents/` is generated, never edited: starlight-hypha-agents writes it
from the site's pages as `make docs` builds them -- llms.txt, the
catalogue, and pages/, each page as Markdown -- and hypha-litany installs
it as its documentation.
A page changed is `make docs` run in the same commit. Why: a user's
agent reads what the release installs, offline. Test: the docs workflow
builds the pages on every pull request and fails if `agents/` then
differs.

## What is Hypha's here

- **It is a library of Hypha Stack like any other.** Its CI, its
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

- hypha-litany installs its documentation for agents: each page of the
site as Markdown, and `llms.txt`, in `$(opam var hypha-litany:doc)`.

## 1.2.2 (2026-11-10)

- The package is now `hypha-litany`, so it can be published beside
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ Warning 0 [suspicious-physical-equality]: physical comparison has a non-immediat
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`:

```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](AGENTS.md).
Expand Down
107 changes: 107 additions & 0 deletions agents/llms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# litany

> The linter for modern OCaml.

## Start here

- [Getting Started](pages/index.md): The linter for modern OCaml.

## Guides

- [Selecting rules](pages/guide/selecting-rules.md): Groups, stability, fix promises and the project rules.
- [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.
- [Build integration](pages/guide/build-integration.md): Findings in your editor through a dune rule, other build systems, the cache and the workers.
- [CI](pages/guide/ci.md): litany on GitHub Actions, and the text, json and github formats.
- [Writing a rule](pages/guide/writing-a-rule.md): A rule is one value in one file, a registry entry and a fixture.
- [A custom binary](pages/guide/custom-binary.md): The rules extended with your own, by recompiling.

## Reference

- [Reference](pages/reference.md)
- [Rules](pages/reference/rules.md): Every rule litany has.
- [dead-code](pages/reference/rules/dead-code.md): exported value unreachable from any root
- [disable-all-warnings](pages/reference/rules/disable-all-warnings.md): a warning attribute disables every warning
- [eta-reducible-forwarding](pages/reference/rules/eta-reducible-forwarding.md): binding that only forwards its arguments
- [ignored-result](pages/reference/rules/ignored-result.md): result or option value is discarded by a wildcard binding
- [invalid-function-comparison](pages/reference/rules/invalid-function-comparison.md): structural comparison with a function operand
- [invalid-hashtable-key](pages/reference/rules/invalid-hashtable-key.md): polymorphic Hashtbl operation on a value proved functional
- [invalid-nan-comparison](pages/reference/rules/invalid-nan-comparison.md): comparison with nan is a compile-time constant
- [manual-boolean-operator](pages/reference/rules/manual-boolean-operator.md): if with one boolean-literal branch spells an operator longhand
- [manual-case-guard](pages/reference/rules/manual-case-guard.md): case body that is immediately an if-then-else
- [manual-eta-lambda](pages/reference/rules/manual-eta-lambda.md): anonymous function that only forwards its parameters
- [manual-format-quoting](pages/reference/rules/manual-format-quoting.md): format literal hand-quotes %s where %S quotes and escapes
- [manual-list-exists](pages/reference/rules/manual-list-exists.md): recursive function that re-implements List.exists
- [manual-list-filter-map](pages/reference/rules/manual-list-filter-map.md): recursive function that re-implements List.filter or filter_map
- [manual-list-fold](pages/reference/rules/manual-list-fold.md): recursive function that re-implements a List fold
- [manual-list-forall](pages/reference/rules/manual-list-forall.md): recursive function that re-implements List.for_all
- [manual-list-map](pages/reference/rules/manual-list-map.md): recursive function that hand-rolls a list map
- [manual-option-bind](pages/reference/rules/manual-option-bind.md): two-case option match that re-implements Option.bind
- [manual-option-map](pages/reference/rules/manual-option-map.md): two-case match that unwraps, transforms, and rewraps an option
- [manual-option-value](pages/reference/rules/manual-option-value.md): two-case match extracting an option's value over a trivial default
- [manual-record-update](pages/reference/rules/manual-record-update.md): record rebuilt field by field from one base
- [manual-result-bind](pages/reference/rules/manual-result-bind.md): two-case result match that re-implements Result.bind
- [manual-result-map](pages/reference/rules/manual-result-map.md): two-case match that transforms one result arm and rebuilds the other
- [manual-temp-dir](pages/reference/rules/manual-temp-dir.md): temp file removed and re-created as a directory
- [manual-tuple-matching](pages/reference/rules/manual-tuple-matching.md): single irrefutable tuple case that could be a let binding
- [missing-final-newline](pages/reference/rules/missing-final-newline.md): file does not end with a newline
- [missing-printer](pages/reference/rules/missing-printer.md): comparable abstract type whose interface exposes no printer
- [needless-and-binding](pages/reference/rules/needless-and-binding.md): let rec binding riding an and-chain it does not need
- [needless-append-empty](pages/reference/rules/needless-append-empty.md): append or concatenation with the neutral element
- [needless-fun-match](pages/reference/rules/needless-fun-match.md): fun-then-match over an otherwise unused final parameter
- [needless-list-length](pages/reference/rules/needless-list-length.md): List.length compared with 0 or 1 to test emptiness
- [needless-list-map-before-concat](pages/reference/rules/needless-list-map-before-concat.md): List.map feeding concatenation builds an intermediate list
- [needless-mutually-recursive-types](pages/reference/rules/needless-mutually-recursive-types.md): and-chained type that is not mutually recursive with its group
- [open-of-ordinary-module](pages/reference/rules/open-of-ordinary-module.md): an open of a module that is not made to be opened
- [outdated-str-module](pages/reference/rules/outdated-str-module.md): reference into the outdated Str module
- [quadratic-list-append](pages/reference/rules/quadratic-list-append.md): list append folded with the accumulator on the left
- [quadratic-string-concat-chain](pages/reference/rules/quadratic-string-concat-chain.md): a chain of three or more (^) segments
- [quadratic-string-concat-fold](pages/reference/rules/quadratic-string-concat-fold.md): string concatenation folded through (^)
- [redundant-bind-return](pages/reference/rules/redundant-bind-return.md): bind into a bare return re-wraps the value unchanged
- [redundant-boolean-comparison](pages/reference/rules/redundant-boolean-comparison.md): comparison with a boolean constant
- [redundant-boolean-operator](pages/reference/rules/redundant-boolean-operator.md): boolean operator with a constant operand
- [redundant-conversion-roundtrip](pages/reference/rules/redundant-conversion-roundtrip.md): conversion immediately undone by its inverse
- [redundant-guard-true](pages/reference/rules/redundant-guard-true.md): when guard that is literally true or false
- [redundant-if-bool](pages/reference/rules/redundant-if-bool.md): if whose both branches are boolean literals restates the condition
- [redundant-list-roundtrip](pages/reference/rules/redundant-list-roundtrip.md): list converted to a sequence and immediately back
- [redundant-match-bool](pages/reference/rules/redundant-match-bool.md): boolean match interrupting an if/else chain
- [redundant-nested-if](pages/reference/rules/redundant-nested-if.md): else-less if directly nested in an else-less if
- [redundant-not-not](pages/reference/rules/redundant-not-not.md): double boolean negation
- [redundant-option-comparison](pages/reference/rules/redundant-option-comparison.md): comparison with None spells an Option predicate
- [redundant-option-roundtrip](pages/reference/rules/redundant-option-roundtrip.md): option converted to a list only to take its head back
- [redundant-return-bind](pages/reference/rules/redundant-return-bind.md): bind of a fresh return wraps a value only to unwrap it
- [restricted-dependency](pages/reference/rules/restricted-dependency.md): reference to a dependency forbidden by workspace policy
- [restricted-export-name](pages/reference/rules/restricted-export-name.md): exported name breaking the configured naming policy
- [restricted-global-mutable-state](pages/reference/rules/restricted-global-mutable-state.md): toplevel mutable state in library code
- [restricted-public-exception](pages/reference/rules/restricted-public-exception.md): exception declared in a public library interface
- [suspicious-ambiguous-constructors](pages/reference/rules/suspicious-ambiguous-constructors.md): constructor that shadows a standard constructor
- [suspicious-catch-all-handler](pages/reference/rules/suspicious-catch-all-handler.md): wildcard exception handler swallows every exception
- [suspicious-duplicate-condition](pages/reference/rules/suspicious-duplicate-condition.md): else-if condition that duplicates the previous arm's
- [suspicious-exit-in-library](pages/reference/rules/suspicious-exit-in-library.md): exit referenced in library code
- [suspicious-failwith-in-library](pages/reference/rules/suspicious-failwith-in-library.md): failwith referenced in library code
- [suspicious-file-exists-race](pages/reference/rules/suspicious-file-exists-race.md): exists check guarding a filesystem operation on the same path
- [suspicious-general-float-equality](pages/reference/rules/suspicious-general-float-equality.md): bit-exact equality on floats
- [suspicious-if-same-branches](pages/reference/rules/suspicious-if-same-branches.md): if whose two branches are written identically
- [suspicious-ignored-partial-application](pages/reference/rules/suspicious-ignored-partial-application.md): ignore of a value that is still a function
- [suspicious-literal-condition](pages/reference/rules/suspicious-literal-condition.md): if over a literal true or false condition
- [suspicious-lost-backtrace](pages/reference/rules/suspicious-lost-backtrace.md): work between catching and re-raising can overwrite the backtrace
- [suspicious-physical-equality](pages/reference/rules/suspicious-physical-equality.md): physical comparison with a non-immediate operand
- [suspicious-polymorphic-compare-on-opaque](pages/reference/rules/suspicious-polymorphic-compare-on-opaque.md): polymorphic comparison of a Set, Map, or Hashtbl value
- [suspicious-print-debugging](pages/reference/rules/suspicious-print-debugging.md): console printing entrypoint referenced in library code
- [suspicious-rec-without-recursion](pages/reference/rules/suspicious-rec-without-recursion.md): let rec group that never recurses
- [suspicious-sequence-ignored-value](pages/reference/rules/suspicious-sequence-ignored-value.md): pure projection discarded where the compiler cannot warn
- [suspicious-str-formatter](pages/reference/rules/suspicious-str-formatter.md): reference to the process-global Format.str_formatter
- [suspicious-swallowed-cancellation](pages/reference/rules/suspicious-swallowed-cancellation.md): total handler around eio code converts cancellation into a value
- [suspicious-transposable-arguments](pages/reference/rules/suspicious-transposable-arguments.md): three adjacent same-typed unlabeled parameters
- [suspicious-unused-module-binding](pages/reference/rules/suspicious-unused-module-binding.md): module binding the unit never uses and never exports
- [suspicious-variant-arity-tuple](pages/reference/rules/suspicious-variant-arity-tuple.md): constructor whose one argument is a parenthesized tuple
- [suspicious-wall-clock-elapsed](pages/reference/rules/suspicious-wall-clock-elapsed.md): duration computed from wall-clock reads
- [trailing-whitespace](pages/reference/rules/trailing-whitespace.md): trailing spaces or tabs at end of line
- [unsafe-obj-magic](pages/reference/rules/unsafe-obj-magic.md): use of Obj.magic
- [unsafe-partial-stdlib](pages/reference/rules/unsafe-partial-stdlib.md): reference to a partial stdlib eliminator
- [untyped-ignore](pages/reference/rules/untyped-ignore.md): ignore discards a value without naming its type
- [untyped-wildcard-binding](pages/reference/rules/untyped-wildcard-binding.md): let _ discards a value without naming its type
- [unused-export](pages/reference/rules/unused-export.md): exported value never used by another unit
- [used-underscore-binding](pages/reference/rules/used-underscore-binding.md): underscore-prefixed binding is used
- [wildcard-over-owned-variant](pages/reference/rules/wildcard-over-owned-variant.md): a wildcard arm in a match over a variant the code owns
121 changes: 121 additions & 0 deletions agents/pages/guide/build-integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Build integration

Findings in your editor through a dune rule, other build systems, the cache and the workers.

| How | Command | Project rules |
| --- | --- | --- |
| dune, the default | `litany check` | yes |
| [a dune rule](#in-the-build) | `litany check` as an action | no |
| [one unit](#one-unit) | `litany unit` | no |
| [a unit file](#unit-files) | `litany check --units FILE` | if the file is complete |
| [a directory of artifacts](#a-directory-of-artifacts) | `litany check --cmt-root DIR` | no |

## In the build

One rule you write yourself runs litany inside the build:

```lisp
(rule
(alias lint)
(deps (alias_rec check))
(action (run litany check)))
```

`dune build @lint` fails on findings, and they are ordinary dune diagnostics.
Add it to your watch and they reach your editor as compiler warnings, with no
plugin:

```sh
dune build @default @lint -w
```

The rule lints the directory it is in and below, and reads the workspace's
`litany` file. Run [project rules](selecting-rules.md#project-rules)
and the rules that need a unit's kind, which litany names as withheld, from a
terminal or CI, since they don't run here.

### Fixing in the build

With `(lang dune 3.23)`, add `--fix` and `(corrections produce)`:

```lisp
(rule
(alias lint)
(deps (alias_rec check))
(corrections produce)
(action (run litany check --fix)))
```

The build fails showing each fix as a diff, and `dune promote` applies them.
Without `(corrections produce)` dune silently drops the fixes: if a fix rule
builds green while it prints `1 fix proposed`, that field is missing. On older
dune, run `litany check --fix` from a terminal.

## One unit

For build systems that wire one rule per module:

```console
$ litany unit inventory --cmt _build/default/lib/.inventory.objs/byte/inventory.cmt --source lib/inventory.ml
```

It runs the default rules and ignores the `litany` file, so a build rule means
the same on every checkout. A unit it can't lint is a refusal, exit 2.

## Unit files

A unit file tells litany about any build system's output. `--units` reads the
file `--save` writes, in which every atom is length-prefixed (`(4:unit(6:source8:lib/a.ml))`);
what `litany units` prints is the same document for a person to read, and is
not accepted back:

```console
$ litany units
(litany-units 1)
(cmi-dirs _build/default/lib/.inventory.objs/byte)
(unit (source lib/inventory.ml) (cmt _build/default/lib/.inventory.objs/byte/inventory.cmt) (library inventory) (public false) (kind lib))
$ litany units --save litany.units
$ litany check --no-build --units litany.units
```

The file is [canonical s-expressions](https://en.wikipedia.org/wiki/Canonical_S-expressions), one form per line, in this order:

1. `(litany-units 1)`, required.
2. `(complete false)`, when it isn't your whole project.
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 library public kind`. `source` and one of `cmt` or `cmti` are
required; `pp-source` is the preprocessed file, where there is one; `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.

## A directory of artifacts

```console
$ litany check --cmt-root _build/default
```

Pairs the `.cmt` files under a directory with their sources by digest. It knows
nothing of libraries, so project rules and rules that depend on a unit's kind
don't run, and the summary lists them.

## The cache

`litany check` caches results per unit, keyed by everything that can change
them, and output is the same warm or cold.

| Control | Effect |
| --- | --- |
| `--cache-dir DIR`, `LITANY_CACHE_DIR` | where to store it |
| neither | `$XDG_CACHE_HOME/litany`, else `~/.cache/litany` |
| `--no-cache` | run uncached |
| `--cache-stats` | print hits and misses |

Entries unread for 30 days are evicted, and deleting the directory is always
safe.

## Workers

`litany check -j N` analyses units in `N` processes, by default one per core,
and the output doesn't depend on `N`. `--fix` runs in one process.
Loading