diff --git a/AGENTS.md b/AGENTS.md index 4f10fc8..c62d154 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 @@ -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 diff --git a/CHANGES.md b/CHANGES.md index d552d40..b133ad1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/Makefile b/Makefile index 7b2a799..e37297d 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/README.md b/README.md index db98b3b..650a366 100644 --- a/README.md +++ b/README.md @@ -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 :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 :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 diff --git a/agents/llms.txt b/agents/llms.txt index ec77b13..c4bc242 100644 --- a/agents/llms.txt +++ b/agents/llms.txt @@ -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. diff --git a/agents/pages/guide/build-integration.md b/agents/pages/guide/build-integration.md index 642a27a..631cf7e 100644 --- a/agents/pages/guide/build-integration.md +++ b/agents/pages/guide/build-integration.md @@ -85,10 +85,13 @@ The file is [canonical s-expressions](https://en.wikipedia.org/wiki/Canonical_S- 3. `(cmi-dirs ...)`, 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. diff --git a/agents/pages/guide/ci.md b/agents/pages/guide/ci.md index 48457c3..f23c926 100644 --- a/agents/pages/guide/ci.md +++ b/agents/pages/guide/ci.md @@ -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 diff --git a/agents/pages/guide/configuration.md b/agents/pages/guide/configuration.md index 59218bb..3aaa1fa 100644 --- a/agents/pages/guide/configuration.md +++ b/agents/pages/guide/configuration.md @@ -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: @@ -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 )`, `(max-underscores )` | reports nothing | | [`wildcard-over-owned-variant`](../reference/rules/wildcard-over-owned-variant.md) | `(owned ...)` | 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 diff --git a/agents/pages/guide/fixing.md b/agents/pages/guide/fixing.md index a6a79e1..41a686a 100644 --- a/agents/pages/guide/fixing.md +++ b/agents/pages/guide/fixing.md @@ -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 diff --git a/agents/pages/guide/selecting-rules.md b/agents/pages/guide/selecting-rules.md index 1ffa299..b30a154 100644 --- a/agents/pages/guide/selecting-rules.md +++ b/agents/pages/guide/selecting-rules.md @@ -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. diff --git a/agents/pages/guide/suppression.md b/agents/pages/guide/suppression.md index 9bdcf6b..f9d9133 100644 --- a/agents/pages/guide/suppression.md +++ b/agents/pages/guide/suppression.md @@ -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. diff --git a/agents/pages/guide/writing-a-rule.md b/agents/pages/guide/writing-a-rule.md index fbf169f..daa3eb3 100644 --- a/agents/pages/guide/writing-a-rule.md +++ b/agents/pages/guide/writing-a-rule.md @@ -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 @@ -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 diff --git a/agents/pages/index.md b/agents/pages/index.md index 768a075..82d602f 100644 --- a/agents/pages/index.md +++ b/agents/pages/index.md @@ -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: diff --git a/agents/pages/reference.md b/agents/pages/reference.md index 4ff5c32..1a8f7e6 100644 --- a/agents/pages/reference.md +++ b/agents/pages/reference.md @@ -21,12 +21,12 @@ on findings, 2 on a refusal and 3 on an internal error. | `--fix`, `--unsafe` | [apply safe fixes](guide/fixing.md), and unsafe ones too | | `--format=FMT` | [`text`, `json` or `github`](guide/ci.md#output-formats) | | `--root=DIR` | run against the workspace at `DIR` | -| `--no-build` | don't build first; stale artifacts are skips | +| `--no-build` | don't build first, and skip stale artifacts | | `--list-units` | list the units that would be linted and those skipped, and run no rule | | `--explain-withheld` | say which skip blocked which [project rule](guide/selecting-rules.md#project-rules) | | `--units=FILE` | take the units from [a unit file](guide/build-integration.md#unit-files) | | `--cmt-root=DIR` | [walk a directory of artifacts](guide/build-integration.md#a-directory-of-artifacts) | -| `--trust-build` | with a build litany didn't run, lint preprocessed units instead of skipping them; a stale one is still skipped | +| `--trust-build` | with a build litany didn't run, lint preprocessed units instead of skipping them, but still skip a stale one | | `-j N`, `--jobs=N` | [use `N` worker processes](guide/build-integration.md#workers) | | `--cache-dir=DIR`, `--no-cache`, `--cache-stats` | [control the cache](guide/build-integration.md#the-cache) | | `--no-progress` | don't draw the progress line, which only a terminal gets | @@ -35,7 +35,7 @@ on findings, 2 on a refusal and 3 on an internal error. | Option | What it does | |---|---| -| `--dump` | print the file readably; the default | +| `--dump` | print the file readably, the default | | `--save=FILE` | write it to `FILE` | | `--root=DIR`, `--no-build`, `--cmt-root=DIR` | as for `litany check` | @@ -52,7 +52,13 @@ on findings, 2 on a refusal and 3 on an internal error. | `LITANY_CACHE_DIR`, `XDG_CACHE_HOME` | [where the cache is](guide/build-integration.md#the-cache) | | `LITANY_NO_PROGRESS` | as `--no-progress` | | `GITHUB_ACTIONS` | makes `github` the default format | -| `NO_COLOR`, `OCAML_COLOR` | `NO_COLOR` turns colour off; `OCAML_COLOR` is `always` or `never` | +| `NO_COLOR`, `OCAML_COLOR` | `NO_COLOR` turns colour off, and `OCAML_COLOR` is `always` or `never` | + +## The packages + +| Package | Libraries | What it is | +|---|---|---| +| `hypha-litany` | none | The `litany` command and its rules. Its libraries are private to its source tree, as below | ## Libraries diff --git a/agents/pages/reference/rules.md b/agents/pages/reference/rules.md index 8e420c8..b0af93f 100644 --- a/agents/pages/reference/rules.md +++ b/agents/pages/reference/rules.md @@ -4,10 +4,7 @@ Every rule litany has. -[Selecting rules](../guide/selecting-rules.md) says what the columns -decide. - -**84 rules · 30 on by default (stable correctness, suspicious, perf) · 14 restriction (cherry-picked; outside all) · 16 nursery** +84 rules, 30 on by default. 16 are experimental. 14 are restrictions, each turned on by name. [Selecting rules](../guide/selecting-rules.md) explains the columns. | Rule | Group | Stability | Fix | Default | Finds | |---|---|---|---|---|---| diff --git a/agents/pages/reference/rules/dead-code.md b/agents/pages/reference/rules/dead-code.md index 82642f8..6edb1f8 100644 --- a/agents/pages/reference/rules/dead-code.md +++ b/agents/pages/reference/rules/dead-code.md @@ -4,7 +4,9 @@ exported value unreachable from any root -**suspicious · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | An exported value no chain of live code reaches is dead: not used directly, and every path that mentions it starts from something itself diff --git a/agents/pages/reference/rules/disable-all-warnings.md b/agents/pages/reference/rules/disable-all-warnings.md index 2a8f9b3..d14dd16 100644 --- a/agents/pages/reference/rules/disable-all-warnings.md +++ b/agents/pages/reference/rules/disable-all-warnings.md @@ -4,7 +4,9 @@ a warning attribute disables every warning -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `[@@@warning "-a"]` (and its spellings `"-A"` and `"a"`) clears warning set `a` — OCaml's complete warning set — hiding every problem the diff --git a/agents/pages/reference/rules/eta-reducible-forwarding.md b/agents/pages/reference/rules/eta-reducible-forwarding.md index c36a42a..7130bdf 100644 --- a/agents/pages/reference/rules/eta-reducible-forwarding.md +++ b/agents/pages/reference/rules/eta-reducible-forwarding.md @@ -4,7 +4,9 @@ binding that only forwards its arguments -**style · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | A binding whose body only forwards its parameters, in order, to a single identifier is that identifier with extra ceremony: an allocation diff --git a/agents/pages/reference/rules/ignored-result.md b/agents/pages/reference/rules/ignored-result.md index 2c62797..6e82e41 100644 --- a/agents/pages/reference/rules/ignored-result.md +++ b/agents/pages/reference/rules/ignored-result.md @@ -4,7 +4,9 @@ result or option value is discarded by a wildcard binding -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A `result` or `option` is a value whose type asks the reader to examine it: an error or an absence is part of the answer. Binding it to diff --git a/agents/pages/reference/rules/invalid-function-comparison.md b/agents/pages/reference/rules/invalid-function-comparison.md index 676425b..38142c8 100644 --- a/agents/pages/reference/rules/invalid-function-comparison.md +++ b/agents/pages/reference/rules/invalid-function-comparison.md @@ -4,7 +4,9 @@ structural comparison with a function operand -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | Structural comparison of functions is meaningless: `compare` raises `Invalid_argument` on distinct closures, and `=` either raises or answers diff --git a/agents/pages/reference/rules/invalid-hashtable-key.md b/agents/pages/reference/rules/invalid-hashtable-key.md index 97d32f2..916a30b 100644 --- a/agents/pages/reference/rules/invalid-hashtable-key.md +++ b/agents/pages/reference/rules/invalid-hashtable-key.md @@ -4,7 +4,9 @@ polymorphic Hashtbl operation on a value proved functional -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `Stdlib.Hashtbl`'s default operations hash and compare keys with the polymorphic primitives. A functional key is broken at runtime, but not diff --git a/agents/pages/reference/rules/invalid-nan-comparison.md b/agents/pages/reference/rules/invalid-nan-comparison.md index 2415fe7..2ab4918 100644 --- a/agents/pages/reference/rules/invalid-nan-comparison.md +++ b/agents/pages/reference/rules/invalid-nan-comparison.md @@ -4,7 +4,9 @@ comparison with nan is a compile-time constant -**correctness · error · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [correctness](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | IEEE 754 makes `nan` unordered with everything, itself included: `=`, `<`, `>`, `<=`, and `>=` against `nan` are always `false` and `<>` is diff --git a/agents/pages/reference/rules/manual-boolean-operator.md b/agents/pages/reference/rules/manual-boolean-operator.md index db10a1c..b925f65 100644 --- a/agents/pages/reference/rules/manual-boolean-operator.md +++ b/agents/pages/reference/rules/manual-boolean-operator.md @@ -4,7 +4,9 @@ if with one boolean-literal branch spells an operator longhand -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | An `if` with exactly one boolean-literal branch spells a boolean operator in longhand: `if c then true else e` is `c || e`, `then false diff --git a/agents/pages/reference/rules/manual-case-guard.md b/agents/pages/reference/rules/manual-case-guard.md index af16d83..784f315 100644 --- a/agents/pages/reference/rules/manual-case-guard.md +++ b/agents/pages/reference/rules/manual-case-guard.md @@ -4,7 +4,9 @@ case body that is immediately an if-then-else -**pedantic · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | A case whose right-hand side is immediately `if c then a else b` can often become two cases with a `when` guard, letting each outcome carry diff --git a/agents/pages/reference/rules/manual-eta-lambda.md b/agents/pages/reference/rules/manual-eta-lambda.md index 50138c6..a8d46ed 100644 --- a/agents/pages/reference/rules/manual-eta-lambda.md +++ b/agents/pages/reference/rules/manual-eta-lambda.md @@ -4,7 +4,9 @@ anonymous function that only forwards its parameters -**style · warning · nursery · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | some findings | 1.0 | An anonymous function whose body only forwards its parameters, in order, to a single identifier is that identifier wrapped in a closure: diff --git a/agents/pages/reference/rules/manual-format-quoting.md b/agents/pages/reference/rules/manual-format-quoting.md index 044ad9c..b4610a3 100644 --- a/agents/pages/reference/rules/manual-format-quoting.md +++ b/agents/pages/reference/rules/manual-format-quoting.md @@ -4,7 +4,9 @@ format literal hand-quotes %s where %S quotes and escapes -**pedantic · warning · nursery · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | some findings | 1.0 | A format string that hand-writes quotes around `%s` — `"name=\"%s\""` — re-implements `%S` minus its escaping: `%S` prints the argument quoted diff --git a/agents/pages/reference/rules/manual-list-exists.md b/agents/pages/reference/rules/manual-list-exists.md index c3edd8a..7c5703e 100644 --- a/agents/pages/reference/rules/manual-list-exists.md +++ b/agents/pages/reference/rules/manual-list-exists.md @@ -4,7 +4,9 @@ recursive function that re-implements List.exists -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A recursive function whose body is the two-case list recursion returning `false` on `[]` and `E || self … tl` on cons re-implements diff --git a/agents/pages/reference/rules/manual-list-filter-map.md b/agents/pages/reference/rules/manual-list-filter-map.md index 916f215..9ad2dba 100644 --- a/agents/pages/reference/rules/manual-list-filter-map.md +++ b/agents/pages/reference/rules/manual-list-filter-map.md @@ -4,7 +4,9 @@ recursive function that re-implements List.filter or filter_map -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | The cons-or-skip list recursion — keep a (possibly transformed) element in one branch, recurse past it in the other — re-implements diff --git a/agents/pages/reference/rules/manual-list-fold.md b/agents/pages/reference/rules/manual-list-fold.md index a65350e..49eb325 100644 --- a/agents/pages/reference/rules/manual-list-fold.md +++ b/agents/pages/reference/rules/manual-list-fold.md @@ -4,7 +4,9 @@ recursive function that re-implements a List fold -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A recursive function with an accumulator whose body is the two-case list recursion returning the accumulator on `[]` re-implements diff --git a/agents/pages/reference/rules/manual-list-forall.md b/agents/pages/reference/rules/manual-list-forall.md index 619a9f7..99c3712 100644 --- a/agents/pages/reference/rules/manual-list-forall.md +++ b/agents/pages/reference/rules/manual-list-forall.md @@ -4,7 +4,9 @@ recursive function that re-implements List.for_all -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A recursive function whose body is the two-case list recursion returning `true` on `[]` and `E && self … tl` on cons re-implements diff --git a/agents/pages/reference/rules/manual-list-map.md b/agents/pages/reference/rules/manual-list-map.md index 2cbc301..673bcfb 100644 --- a/agents/pages/reference/rules/manual-list-map.md +++ b/agents/pages/reference/rules/manual-list-map.md @@ -4,7 +4,9 @@ recursive function that hand-rolls a list map -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A recursive function whose body is exactly the two-case list recursion `[] -> []` / `x :: xs -> E :: self … xs` re-implements diff --git a/agents/pages/reference/rules/manual-option-bind.md b/agents/pages/reference/rules/manual-option-bind.md index 0065b16..abdd715 100644 --- a/agents/pages/reference/rules/manual-option-bind.md +++ b/agents/pages/reference/rules/manual-option-bind.md @@ -4,7 +4,9 @@ two-case option match that re-implements Option.bind -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `match o with Some y -> E | None -> None`, with `E` itself option-typed (the match's typing guarantees it), is diff --git a/agents/pages/reference/rules/manual-option-map.md b/agents/pages/reference/rules/manual-option-map.md index f836a4d..63b68f4 100644 --- a/agents/pages/reference/rules/manual-option-map.md +++ b/agents/pages/reference/rules/manual-option-map.md @@ -4,7 +4,9 @@ two-case match that unwraps, transforms, and rewraps an option -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | `match o with Some x -> Some E | None -> None` is `Option.map (fun x -> E) o` written longhand: both forms evaluate the scrutinee once diff --git a/agents/pages/reference/rules/manual-option-value.md b/agents/pages/reference/rules/manual-option-value.md index 2efabc6..98fed35 100644 --- a/agents/pages/reference/rules/manual-option-value.md +++ b/agents/pages/reference/rules/manual-option-value.md @@ -4,7 +4,9 @@ two-case match extracting an option's value over a trivial default -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | `match o with Some x -> x | None -> D` is `Option.value o ~default:D` — but only when `D` is guaranteed cheap and effect-free: diff --git a/agents/pages/reference/rules/manual-record-update.md b/agents/pages/reference/rules/manual-record-update.md index 862e97a..f1f2058 100644 --- a/agents/pages/reference/rules/manual-record-update.md +++ b/agents/pages/reference/rules/manual-record-update.md @@ -4,7 +4,9 @@ record rebuilt field by field from one base -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A record expression that copies two or more fields verbatim from one base record is `{ base with ... }` written longhand: more text, and the diff --git a/agents/pages/reference/rules/manual-result-bind.md b/agents/pages/reference/rules/manual-result-bind.md index cd20860..194ab6a 100644 --- a/agents/pages/reference/rules/manual-result-bind.md +++ b/agents/pages/reference/rules/manual-result-bind.md @@ -4,7 +4,9 @@ two-case result match that re-implements Result.bind -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `match r with Ok x -> E | Error e -> Error e`, with `E` itself result-typed and the error returned unchanged, is diff --git a/agents/pages/reference/rules/manual-result-map.md b/agents/pages/reference/rules/manual-result-map.md index af7cab0..10455c1 100644 --- a/agents/pages/reference/rules/manual-result-map.md +++ b/agents/pages/reference/rules/manual-result-map.md @@ -4,7 +4,9 @@ two-case match that transforms one result arm and rebuilds the other -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | `match r with Ok x -> Ok E | Error e -> Error e` is `Result.map (fun x -> E) r`: the error arm provably rebuilds the same payload. The diff --git a/agents/pages/reference/rules/manual-temp-dir.md b/agents/pages/reference/rules/manual-temp-dir.md index 839cc7d..5461483 100644 --- a/agents/pages/reference/rules/manual-temp-dir.md +++ b/agents/pages/reference/rules/manual-temp-dir.md @@ -4,7 +4,9 @@ temp file removed and re-created as a directory -**suspicious · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | `Filename.temp_file` creates the file exclusively — that exclusivity is its entire security contract. Removing the file and re-creating its diff --git a/agents/pages/reference/rules/manual-tuple-matching.md b/agents/pages/reference/rules/manual-tuple-matching.md index 32ec298..8e1ff83 100644 --- a/agents/pages/reference/rules/manual-tuple-matching.md +++ b/agents/pages/reference/rules/manual-tuple-matching.md @@ -4,7 +4,9 @@ single irrefutable tuple case that could be a let binding -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | A `match` with exactly one case whose pattern is an irrefutable tuple does no branching: a single guard-less irrefutable case evaluates the diff --git a/agents/pages/reference/rules/missing-final-newline.md b/agents/pages/reference/rules/missing-final-newline.md index 9dcf8d7..4b22f14 100644 --- a/agents/pages/reference/rules/missing-final-newline.md +++ b/agents/pages/reference/rules/missing-final-newline.md @@ -4,7 +4,9 @@ file does not end with a newline -**style · warning · nursery · since 1.0 · fix: always · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | every finding | 1.0 | A file whose last line has no terminating LF confuses line-oriented tools — `cat` runs files together, `wc -l` miscounts, diffs grow the diff --git a/agents/pages/reference/rules/missing-printer.md b/agents/pages/reference/rules/missing-printer.md index e4117da..aaa4c45 100644 --- a/agents/pages/reference/rules/missing-printer.md +++ b/agents/pages/reference/rules/missing-printer.md @@ -4,7 +4,9 @@ comparable abstract type whose interface exposes no printer -**pedantic · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | An interface that already exposes `equal`, `compare`, or `to_string` for its abstract type has declared it a diff --git a/agents/pages/reference/rules/needless-and-binding.md b/agents/pages/reference/rules/needless-and-binding.md index f8df904..4df9aa3 100644 --- a/agents/pages/reference/rules/needless-and-binding.md +++ b/agents/pages/reference/rules/needless-and-binding.md @@ -4,7 +4,9 @@ let rec binding riding an and-chain it does not need -**style · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | A `let rec … and …` chain asserts co-dependence. A binding that neither calls itself through the group nor participates in any diff --git a/agents/pages/reference/rules/needless-append-empty.md b/agents/pages/reference/rules/needless-append-empty.md index 7bf95a5..4a73e17 100644 --- a/agents/pages/reference/rules/needless-append-empty.md +++ b/agents/pages/reference/rules/needless-append-empty.md @@ -4,7 +4,9 @@ append or concatenation with the neutral element -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | Appending the neutral element does nothing — except allocate. `[] @ l` is `l` itself (the stdlib's append returns its second argument diff --git a/agents/pages/reference/rules/needless-fun-match.md b/agents/pages/reference/rules/needless-fun-match.md index 992819e..2198d8f 100644 --- a/agents/pages/reference/rules/needless-fun-match.md +++ b/agents/pages/reference/rules/needless-fun-match.md @@ -4,7 +4,9 @@ fun-then-match over an otherwise unused final parameter -**style · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | `fun x -> match x with …` where `x` is used only as the scrutinee is `function` with an extra name: the binding adds nothing a reader can diff --git a/agents/pages/reference/rules/needless-list-length.md b/agents/pages/reference/rules/needless-list-length.md index 0b6e9f4..4e22bbe 100644 --- a/agents/pages/reference/rules/needless-list-length.md +++ b/agents/pages/reference/rules/needless-list-length.md @@ -4,7 +4,9 @@ List.length compared with 0 or 1 to test emptiness -**perf · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | Comparing `List.length` with a constant zero or one to ask "is this list empty?" walks the whole list to answer a constant-time question. diff --git a/agents/pages/reference/rules/needless-list-map-before-concat.md b/agents/pages/reference/rules/needless-list-map-before-concat.md index 84f5b62..766c5f8 100644 --- a/agents/pages/reference/rules/needless-list-map-before-concat.md +++ b/agents/pages/reference/rules/needless-list-map-before-concat.md @@ -4,7 +4,9 @@ List.map feeding concatenation builds an intermediate list -**perf · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `List.concat (List.map f xs)` builds a complete intermediate list of lists only for the concatenation to traverse and discard it; diff --git a/agents/pages/reference/rules/needless-mutually-recursive-types.md b/agents/pages/reference/rules/needless-mutually-recursive-types.md index 54ba92f..bdfed91 100644 --- a/agents/pages/reference/rules/needless-mutually-recursive-types.md +++ b/agents/pages/reference/rules/needless-mutually-recursive-types.md @@ -4,7 +4,9 @@ and-chained type that is not mutually recursive with its group -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | An `and`-chained type group asserts to the reader that its members are mutually recursive. A member that participates in no reference diff --git a/agents/pages/reference/rules/open-of-ordinary-module.md b/agents/pages/reference/rules/open-of-ordinary-module.md index 8dc528a..aa20255 100644 --- a/agents/pages/reference/rules/open-of-ordinary-module.md +++ b/agents/pages/reference/rules/open-of-ordinary-module.md @@ -4,7 +4,9 @@ an open of a module that is not made to be opened -**restriction · warning · nursery · since 1.1 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.1 | An `open` of an ordinary module makes every name of the file a question -- where did it come from? -- and a name the module gains later diff --git a/agents/pages/reference/rules/outdated-str-module.md b/agents/pages/reference/rules/outdated-str-module.md index 58842c1..0d0342e 100644 --- a/agents/pages/reference/rules/outdated-str-module.md +++ b/agents/pages/reference/rules/outdated-str-module.md @@ -4,7 +4,9 @@ reference into the outdated Str module -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `Str` funnels every match through one global state: each `Str.string_match` stores its groups in hidden cells that the next match — diff --git a/agents/pages/reference/rules/quadratic-list-append.md b/agents/pages/reference/rules/quadratic-list-append.md index bb83c39..0df985a 100644 --- a/agents/pages/reference/rules/quadratic-list-append.md +++ b/agents/pages/reference/rules/quadratic-list-append.md @@ -4,7 +4,9 @@ list append folded with the accumulator on the left -**perf · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `(@)` copies its left operand and shares its right. A fold whose accumulator sits on the left of `(@)` therefore copies everything diff --git a/agents/pages/reference/rules/quadratic-string-concat-chain.md b/agents/pages/reference/rules/quadratic-string-concat-chain.md index a395841..3e85457 100644 --- a/agents/pages/reference/rules/quadratic-string-concat-chain.md +++ b/agents/pages/reference/rules/quadratic-string-concat-chain.md @@ -4,7 +4,9 @@ a chain of three or more (^) segments -**pedantic · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `(^)` associates to the right, so `a ^ b ^ c` builds `b ^ c` and then copies it whole into `a ^ (b ^ c)`: every added segment recopies the ones diff --git a/agents/pages/reference/rules/quadratic-string-concat-fold.md b/agents/pages/reference/rules/quadratic-string-concat-fold.md index 37e0076..c47d913 100644 --- a/agents/pages/reference/rules/quadratic-string-concat-fold.md +++ b/agents/pages/reference/rules/quadratic-string-concat-fold.md @@ -4,7 +4,9 @@ string concatenation folded through (^) -**perf · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | Folding `(^)` over a collection copies the whole accumulator for every element: joining n segments allocates quadratically where `String.concat` diff --git a/agents/pages/reference/rules/redundant-bind-return.md b/agents/pages/reference/rules/redundant-bind-return.md index a93d731..efe7504 100644 --- a/agents/pages/reference/rules/redundant-bind-return.md +++ b/agents/pages/reference/rules/redundant-bind-return.md @@ -4,7 +4,9 @@ bind into a bare return re-wraps the value unchanged -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | Binding a computation into its monad's own `return` is the right identity law: every value is re-wrapped exactly as it arrived, so the diff --git a/agents/pages/reference/rules/redundant-boolean-comparison.md b/agents/pages/reference/rules/redundant-boolean-comparison.md index 0d94dce..1164a87 100644 --- a/agents/pages/reference/rules/redundant-boolean-comparison.md +++ b/agents/pages/reference/rules/redundant-boolean-comparison.md @@ -4,7 +4,9 @@ comparison with a boolean constant -**suspicious · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | Comparing a boolean with `true` or `false` restates the operand: `x = true` is `x`, `x = false` is `not x`. The comparison adds noise and diff --git a/agents/pages/reference/rules/redundant-boolean-operator.md b/agents/pages/reference/rules/redundant-boolean-operator.md index 322efc1..febe445 100644 --- a/agents/pages/reference/rules/redundant-boolean-operator.md +++ b/agents/pages/reference/rules/redundant-boolean-operator.md @@ -4,7 +4,9 @@ boolean operator with a constant operand -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A `&&` or `||` with a literal `true` or `false` operand computes nothing the other operand does not already say: `x && true` is `x`, diff --git a/agents/pages/reference/rules/redundant-conversion-roundtrip.md b/agents/pages/reference/rules/redundant-conversion-roundtrip.md index 4cd3c42..9e82e2f 100644 --- a/agents/pages/reference/rules/redundant-conversion-roundtrip.md +++ b/agents/pages/reference/rules/redundant-conversion-roundtrip.md @@ -4,7 +4,9 @@ conversion immediately undone by its inverse -**perf · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | Converting a value out of its type and immediately back does allocation and parsing work to end where it started: diff --git a/agents/pages/reference/rules/redundant-guard-true.md b/agents/pages/reference/rules/redundant-guard-true.md index 8e1fd4b..4bba15f 100644 --- a/agents/pages/reference/rules/redundant-guard-true.md +++ b/agents/pages/reference/rules/redundant-guard-true.md @@ -4,7 +4,9 @@ when guard that is literally true or false -**suspicious · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | A guard that is literally `true` never fails: the case behaves as if unguarded, but the `when` costs the reader a double-take and costs diff --git a/agents/pages/reference/rules/redundant-if-bool.md b/agents/pages/reference/rules/redundant-if-bool.md index c0d811f..5852c59 100644 --- a/agents/pages/reference/rules/redundant-if-bool.md +++ b/agents/pages/reference/rules/redundant-if-bool.md @@ -4,7 +4,9 @@ if whose both branches are boolean literals restates the condition -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | An `if` whose branches are the two boolean literals restates its own condition: `if c then true else false` is `c`, and `then false else diff --git a/agents/pages/reference/rules/redundant-list-roundtrip.md b/agents/pages/reference/rules/redundant-list-roundtrip.md index 4509acc..8a235b4 100644 --- a/agents/pages/reference/rules/redundant-list-roundtrip.md +++ b/agents/pages/reference/rules/redundant-list-roundtrip.md @@ -4,7 +4,9 @@ list converted to a sequence and immediately back -**perf · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `List.of_seq (List.to_seq xs)` walks the list twice and allocates a fresh copy just to end where it started. diff --git a/agents/pages/reference/rules/redundant-match-bool.md b/agents/pages/reference/rules/redundant-match-bool.md index 27385c7..c3c407e 100644 --- a/agents/pages/reference/rules/redundant-match-bool.md +++ b/agents/pages/reference/rules/redundant-match-bool.md @@ -4,7 +4,9 @@ boolean match interrupting an if/else chain -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | A two-case match on a boolean — `match e with true -> a | false -> b`, or the `function` form — is `if`/`else` in longhand. Standalone, diff --git a/agents/pages/reference/rules/redundant-nested-if.md b/agents/pages/reference/rules/redundant-nested-if.md index a71d440..c8f9080 100644 --- a/agents/pages/reference/rules/redundant-nested-if.md +++ b/agents/pages/reference/rules/redundant-nested-if.md @@ -4,7 +4,9 @@ else-less if directly nested in an else-less if -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | An else-less `if` whose then-branch is directly another else-less `if` is one condition spelled as two: `&&`'s short-circuit evaluates diff --git a/agents/pages/reference/rules/redundant-not-not.md b/agents/pages/reference/rules/redundant-not-not.md index 72b287d..874e897 100644 --- a/agents/pages/reference/rules/redundant-not-not.md +++ b/agents/pages/reference/rules/redundant-not-not.md @@ -4,7 +4,9 @@ double boolean negation -**style · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | `not (not e)` is `e`: `not` is total and effect-free, and `e` is evaluated exactly once in both forms, so the double negation is pure diff --git a/agents/pages/reference/rules/redundant-option-comparison.md b/agents/pages/reference/rules/redundant-option-comparison.md index 2ce913d..20210c4 100644 --- a/agents/pages/reference/rules/redundant-option-comparison.md +++ b/agents/pages/reference/rules/redundant-option-comparison.md @@ -4,7 +4,9 @@ comparison with None spells an Option predicate -**pedantic · warning · stable · since 1.0 · fix: sometimes · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | some findings | 1.0 | `o = None` and `o <> None` are `Option.is_none o` and `Option.is_some o` spelled through the polymorphic comparison. The diff --git a/agents/pages/reference/rules/redundant-option-roundtrip.md b/agents/pages/reference/rules/redundant-option-roundtrip.md index a640049..c738d56 100644 --- a/agents/pages/reference/rules/redundant-option-roundtrip.md +++ b/agents/pages/reference/rules/redundant-option-roundtrip.md @@ -4,7 +4,9 @@ option converted to a list only to take its head back -**perf · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [perf](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `List.nth_opt (Option.to_list o) 0` allocates an intermediate list just to rebuild the option it started from — the whole expression is `o`. diff --git a/agents/pages/reference/rules/redundant-return-bind.md b/agents/pages/reference/rules/redundant-return-bind.md index 748c852..289d38c 100644 --- a/agents/pages/reference/rules/redundant-return-bind.md +++ b/agents/pages/reference/rules/redundant-return-bind.md @@ -4,7 +4,9 @@ bind of a fresh return wraps a value only to unwrap it -**style · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | Binding a freshly returned value is the left identity law: the wrap is undone by the bind, so applying the callback to the value directly says diff --git a/agents/pages/reference/rules/restricted-dependency.md b/agents/pages/reference/rules/restricted-dependency.md index 3e16bd1..93ac965 100644 --- a/agents/pages/reference/rules/restricted-dependency.md +++ b/agents/pages/reference/rules/restricted-dependency.md @@ -4,7 +4,9 @@ reference to a dependency forbidden by workspace policy -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A dependency the workspace has moved off — `Str` for `Re`, a bare stdlib helper for the house wrapper — stays reachable forever, and the diff --git a/agents/pages/reference/rules/restricted-export-name.md b/agents/pages/reference/rules/restricted-export-name.md index a1db3de..6d5ac84 100644 --- a/agents/pages/reference/rules/restricted-export-name.md +++ b/agents/pages/reference/rules/restricted-export-name.md @@ -4,7 +4,9 @@ exported name breaking the configured naming policy -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | An exported name is API surface forever: a prime-suffixed `parse'` or a five-underscore `total_count_of_all_things` in an interface makes diff --git a/agents/pages/reference/rules/restricted-global-mutable-state.md b/agents/pages/reference/rules/restricted-global-mutable-state.md index 68fdbaf..e8bc5cf 100644 --- a/agents/pages/reference/rules/restricted-global-mutable-state.md +++ b/agents/pages/reference/rules/restricted-global-mutable-state.md @@ -4,7 +4,9 @@ toplevel mutable state in library code -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | A `ref`, `Hashtbl.t`, or mutable-record value bound at a library's toplevel lives for the whole process: every consumer shares it, tests diff --git a/agents/pages/reference/rules/restricted-public-exception.md b/agents/pages/reference/rules/restricted-public-exception.md index b935d69..f9cd3e8 100644 --- a/agents/pages/reference/rules/restricted-public-exception.md +++ b/agents/pages/reference/rules/restricted-public-exception.md @@ -4,7 +4,9 @@ exception declared in a public library interface -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | An exception in a public interface is an untyped failure path every consumer inherits: the type checker tracks no `exception` the way it diff --git a/agents/pages/reference/rules/suspicious-ambiguous-constructors.md b/agents/pages/reference/rules/suspicious-ambiguous-constructors.md index c2006e2..a7668d4 100644 --- a/agents/pages/reference/rules/suspicious-ambiguous-constructors.md +++ b/agents/pages/reference/rules/suspicious-ambiguous-constructors.md @@ -4,7 +4,9 @@ constructor that shadows a standard constructor -**suspicious · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | A variant that declares a constructor named `Some`, `None`, `Ok`, `Error`, `::`, or `[]` shadows a predefined or stdlib constructor for diff --git a/agents/pages/reference/rules/suspicious-catch-all-handler.md b/agents/pages/reference/rules/suspicious-catch-all-handler.md index 1e4437b..7f11d47 100644 --- a/agents/pages/reference/rules/suspicious-catch-all-handler.md +++ b/agents/pages/reference/rules/suspicious-catch-all-handler.md @@ -4,7 +4,9 @@ wildcard exception handler swallows every exception -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `try … with _ -> …` handles every exception — `Out_of_memory`, `Stack_overflow`, `Assert_failure`, and the one the author never diff --git a/agents/pages/reference/rules/suspicious-duplicate-condition.md b/agents/pages/reference/rules/suspicious-duplicate-condition.md index b75318e..ca933aa 100644 --- a/agents/pages/reference/rules/suspicious-duplicate-condition.md +++ b/agents/pages/reference/rules/suspicious-duplicate-condition.md @@ -4,7 +4,9 @@ else-if condition that duplicates the previous arm's -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `if c then … else if c then e2 …` evaluates the second `c` with nothing between the two evaluations except the first `c` itself: when diff --git a/agents/pages/reference/rules/suspicious-exit-in-library.md b/agents/pages/reference/rules/suspicious-exit-in-library.md index a49ce60..4011e46 100644 --- a/agents/pages/reference/rules/suspicious-exit-in-library.md +++ b/agents/pages/reference/rules/suspicious-exit-in-library.md @@ -4,7 +4,9 @@ exit referenced in library code -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `Stdlib.exit` terminates the process, runs the `at_exit` handlers, and denies every caller above the library a say. Inside library code diff --git a/agents/pages/reference/rules/suspicious-failwith-in-library.md b/agents/pages/reference/rules/suspicious-failwith-in-library.md index be84cbf..ed613d0 100644 --- a/agents/pages/reference/rules/suspicious-failwith-in-library.md +++ b/agents/pages/reference/rules/suspicious-failwith-in-library.md @@ -4,7 +4,9 @@ failwith referenced in library code -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `Failure` is anonymous — the one exception no caller can match meaningfully — and `failwith` in a library manufactures it at the API diff --git a/agents/pages/reference/rules/suspicious-file-exists-race.md b/agents/pages/reference/rules/suspicious-file-exists-race.md index 2500509..1524c81 100644 --- a/agents/pages/reference/rules/suspicious-file-exists-race.md +++ b/agents/pages/reference/rules/suspicious-file-exists-race.md @@ -4,7 +4,9 @@ exists check guarding a filesystem operation on the same path -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `if Sys.file_exists p then ` is two non-atomic steps: the world can change between them — a concurrent test run, an `at_exit` diff --git a/agents/pages/reference/rules/suspicious-general-float-equality.md b/agents/pages/reference/rules/suspicious-general-float-equality.md index 087341d..bdc1c56 100644 --- a/agents/pages/reference/rules/suspicious-general-float-equality.md +++ b/agents/pages/reference/rules/suspicious-general-float-equality.md @@ -4,7 +4,9 @@ bit-exact equality on floats -**pedantic · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `=` and `<>` on floats ask for bit-exact equality of values that arithmetic rarely reproduces bit-exactly: `0.1 +. 0.2 <> 0.3`. diff --git a/agents/pages/reference/rules/suspicious-if-same-branches.md b/agents/pages/reference/rules/suspicious-if-same-branches.md index 32da49a..369cf9f 100644 --- a/agents/pages/reference/rules/suspicious-if-same-branches.md +++ b/agents/pages/reference/rules/suspicious-if-same-branches.md @@ -4,7 +4,9 @@ if whose two branches are written identically -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `if c then A else B` where `A` and `B` are the same bytes decides nothing: either the condition is unnecessary or — more often — one diff --git a/agents/pages/reference/rules/suspicious-ignored-partial-application.md b/agents/pages/reference/rules/suspicious-ignored-partial-application.md index 8f51394..4835bdc 100644 --- a/agents/pages/reference/rules/suspicious-ignored-partial-application.md +++ b/agents/pages/reference/rules/suspicious-ignored-partial-application.md @@ -4,7 +4,9 @@ ignore of a value that is still a function -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `ignore e` where `e` is still a function discards a closure — a partial application whose remaining arguments, and therefore whose diff --git a/agents/pages/reference/rules/suspicious-literal-condition.md b/agents/pages/reference/rules/suspicious-literal-condition.md index 7700b3f..480cc14 100644 --- a/agents/pages/reference/rules/suspicious-literal-condition.md +++ b/agents/pages/reference/rules/suspicious-literal-condition.md @@ -4,7 +4,9 @@ if over a literal true or false condition -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | A literal `true`/`false` condition makes one branch dead and the `if` a lie — almost always a debugging leftover or an unfinished edit. diff --git a/agents/pages/reference/rules/suspicious-lost-backtrace.md b/agents/pages/reference/rules/suspicious-lost-backtrace.md index cbf7bb2..c4afbe7 100644 --- a/agents/pages/reference/rules/suspicious-lost-backtrace.md +++ b/agents/pages/reference/rules/suspicious-lost-backtrace.md @@ -4,7 +4,9 @@ work between catching and re-raising can overwrite the backtrace -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `raise e` on a handler-bound exception compiles to a backtrace- preserving reraise — but what it preserves is the *current* per-domain diff --git a/agents/pages/reference/rules/suspicious-physical-equality.md b/agents/pages/reference/rules/suspicious-physical-equality.md index ab52aac..6a05d91 100644 --- a/agents/pages/reference/rules/suspicious-physical-equality.md +++ b/agents/pages/reference/rules/suspicious-physical-equality.md @@ -4,7 +4,9 @@ physical comparison with a non-immediate operand -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `==` and `!=` compare identity, not contents: on boxed values two structurally equal operands may or may not share one allocation, so the diff --git a/agents/pages/reference/rules/suspicious-polymorphic-compare-on-opaque.md b/agents/pages/reference/rules/suspicious-polymorphic-compare-on-opaque.md index 8ae65e9..128b032 100644 --- a/agents/pages/reference/rules/suspicious-polymorphic-compare-on-opaque.md +++ b/agents/pages/reference/rules/suspicious-polymorphic-compare-on-opaque.md @@ -4,7 +4,9 @@ polymorphic comparison of a Set, Map, or Hashtbl value -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `Set.Make` and `Map.Make` build balanced trees whose shape depends on insertion history, and `Hashtbl.t` is a mutable record of bucket arrays: diff --git a/agents/pages/reference/rules/suspicious-print-debugging.md b/agents/pages/reference/rules/suspicious-print-debugging.md index 46ede3b..3591cce 100644 --- a/agents/pages/reference/rules/suspicious-print-debugging.md +++ b/agents/pages/reference/rules/suspicious-print-debugging.md @@ -4,7 +4,9 @@ console printing entrypoint referenced in library code -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | Library code that writes to stdout or stderr decides something only the application may decide: whether, where, and how to print. A stray diff --git a/agents/pages/reference/rules/suspicious-rec-without-recursion.md b/agents/pages/reference/rules/suspicious-rec-without-recursion.md index 06ff21c..e35b497 100644 --- a/agents/pages/reference/rules/suspicious-rec-without-recursion.md +++ b/agents/pages/reference/rules/suspicious-rec-without-recursion.md @@ -4,7 +4,9 @@ let rec group that never recurses -**suspicious · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | A `let rec` whose bindings never reference the group is wearing a costume: the reader budgets for recursion that never happens, and the diff --git a/agents/pages/reference/rules/suspicious-sequence-ignored-value.md b/agents/pages/reference/rules/suspicious-sequence-ignored-value.md index 903b244..a7a372e 100644 --- a/agents/pages/reference/rules/suspicious-sequence-ignored-value.md +++ b/agents/pages/reference/rules/suspicious-sequence-ignored-value.md @@ -4,7 +4,9 @@ pure projection discarded where the compiler cannot warn -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | In `e1; e2` the compiler warns on a non-unit `e1` (warning 10) — except when `e1`'s type is a type variable, where it must stay silent diff --git a/agents/pages/reference/rules/suspicious-str-formatter.md b/agents/pages/reference/rules/suspicious-str-formatter.md index 1962d6c..4c8942f 100644 --- a/agents/pages/reference/rules/suspicious-str-formatter.md +++ b/agents/pages/reference/rules/suspicious-str-formatter.md @@ -4,7 +4,9 @@ reference to the process-global Format.str_formatter -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `Format.str_formatter` is one process-global buffer formatter. Two interleaved users corrupt each other's output — in a multi-fiber or diff --git a/agents/pages/reference/rules/suspicious-swallowed-cancellation.md b/agents/pages/reference/rules/suspicious-swallowed-cancellation.md index ede5cdc..63261db 100644 --- a/agents/pages/reference/rules/suspicious-swallowed-cancellation.md +++ b/agents/pages/reference/rules/suspicious-swallowed-cancellation.md @@ -4,7 +4,9 @@ total handler around eio code converts cancellation into a value -**suspicious · warning · stable · since 1.0 · fix: sometimes · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | some findings | 1.0 | Eio delivers fiber cancellation as the `Eio.Cancel.Cancelled` exception out of any suspending operation, and a handler must let it diff --git a/agents/pages/reference/rules/suspicious-transposable-arguments.md b/agents/pages/reference/rules/suspicious-transposable-arguments.md index 8eee037..a211882 100644 --- a/agents/pages/reference/rules/suspicious-transposable-arguments.md +++ b/agents/pages/reference/rules/suspicious-transposable-arguments.md @@ -4,7 +4,9 @@ three adjacent same-typed unlabeled parameters -**pedantic · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [pedantic](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | Two adjacent same-typed unlabeled parameters include the symmetric operations — `equal`, `compare`, `append`, `levenshtein` — where labels diff --git a/agents/pages/reference/rules/suspicious-unused-module-binding.md b/agents/pages/reference/rules/suspicious-unused-module-binding.md index dbb9e7a..833495a 100644 --- a/agents/pages/reference/rules/suspicious-unused-module-binding.md +++ b/agents/pages/reference/rules/suspicious-unused-module-binding.md @@ -4,7 +4,9 @@ module binding the unit never uses and never exports -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | A named module binding that the unit never references, and that nothing outside the unit can reference, is dead text: a local diff --git a/agents/pages/reference/rules/suspicious-variant-arity-tuple.md b/agents/pages/reference/rules/suspicious-variant-arity-tuple.md index 3d9b22c..4595eff 100644 --- a/agents/pages/reference/rules/suspicious-variant-arity-tuple.md +++ b/agents/pages/reference/rules/suspicious-variant-arity-tuple.md @@ -4,7 +4,9 @@ constructor whose one argument is a parenthesized tuple -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `C of int * int` declares a two-field constructor — one block, fields inline. `C of (int * int)` declares a one-field constructor diff --git a/agents/pages/reference/rules/suspicious-wall-clock-elapsed.md b/agents/pages/reference/rules/suspicious-wall-clock-elapsed.md index c00b821..9bba98f 100644 --- a/agents/pages/reference/rules/suspicious-wall-clock-elapsed.md +++ b/agents/pages/reference/rules/suspicious-wall-clock-elapsed.md @@ -4,7 +4,9 @@ duration computed from wall-clock reads -**suspicious · warning · stable · since 1.0 · fix: never · on by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | on | stable | none | 1.0 | `Unix.gettimeofday` and `Unix.time` read the wall clock: NTP steps, manual clock changes, and suspend/resume make it jump both ways. diff --git a/agents/pages/reference/rules/trailing-whitespace.md b/agents/pages/reference/rules/trailing-whitespace.md index 1e163e5..8bf4c07 100644 --- a/agents/pages/reference/rules/trailing-whitespace.md +++ b/agents/pages/reference/rules/trailing-whitespace.md @@ -4,7 +4,9 @@ trailing spaces or tabs at end of line -**style · warning · stable · since 1.0 · fix: always · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [style](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | every finding | 1.0 | Trailing whitespace is invisible, churns diffs, and survives only until the next editor with different settings touches the line. diff --git a/agents/pages/reference/rules/unsafe-obj-magic.md b/agents/pages/reference/rules/unsafe-obj-magic.md index f484fde..0b4b799 100644 --- a/agents/pages/reference/rules/unsafe-obj-magic.md +++ b/agents/pages/reference/rules/unsafe-obj-magic.md @@ -4,7 +4,9 @@ use of Obj.magic -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | `Obj.magic` bypasses the type system entirely: the checker accepts any use at any type, and a mistake becomes memory corruption at run time, diff --git a/agents/pages/reference/rules/unsafe-partial-stdlib.md b/agents/pages/reference/rules/unsafe-partial-stdlib.md index e8ed0f2..fccabb7 100644 --- a/agents/pages/reference/rules/unsafe-partial-stdlib.md +++ b/agents/pages/reference/rules/unsafe-partial-stdlib.md @@ -4,7 +4,9 @@ reference to a partial stdlib eliminator -**restriction · warning · stable · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | stable | none | 1.0 | The stdlib's partial eliminators raise on the case their type admits but their contract excludes: `List.hd` and `List.tl` raise `Failure` on diff --git a/agents/pages/reference/rules/untyped-ignore.md b/agents/pages/reference/rules/untyped-ignore.md index a6cb16b..04f6637 100644 --- a/agents/pages/reference/rules/untyped-ignore.md +++ b/agents/pages/reference/rules/untyped-ignore.md @@ -4,7 +4,9 @@ ignore discards a value without naming its type -**restriction · warning · nursery · since 1.1 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.1 | `ignore` throws a value away; naming its type keeps the throw honest. A function later given one more argument is then a partial diff --git a/agents/pages/reference/rules/untyped-wildcard-binding.md b/agents/pages/reference/rules/untyped-wildcard-binding.md index a967e02..38609bb 100644 --- a/agents/pages/reference/rules/untyped-wildcard-binding.md +++ b/agents/pages/reference/rules/untyped-wildcard-binding.md @@ -4,7 +4,9 @@ let _ discards a value without naming its type -**restriction · warning · nursery · since 1.1 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.1 | `let _ = e` throws a value away; naming its type keeps the throw honest, so the day `e` returns a partial application, a promise or a diff --git a/agents/pages/reference/rules/unused-export.md b/agents/pages/reference/rules/unused-export.md index 48040eb..5b7cb92 100644 --- a/agents/pages/reference/rules/unused-export.md +++ b/agents/pages/reference/rules/unused-export.md @@ -4,7 +4,9 @@ exported value never used by another unit -**suspicious · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | An exported value no other unit of the workspace references is surface a maintainer must read, document, and keep compiling for diff --git a/agents/pages/reference/rules/used-underscore-binding.md b/agents/pages/reference/rules/used-underscore-binding.md index 613d91b..566948b 100644 --- a/agents/pages/reference/rules/used-underscore-binding.md +++ b/agents/pages/reference/rules/used-underscore-binding.md @@ -4,7 +4,9 @@ underscore-prefixed binding is used -**suspicious · warning · nursery · since 1.0 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [suspicious](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.0 | A leading underscore declares "this binding is intentionally unused" and silences the compiler's unused warnings. Using the binding anyway diff --git a/agents/pages/reference/rules/wildcard-over-owned-variant.md b/agents/pages/reference/rules/wildcard-over-owned-variant.md index c7900be..c9fc611 100644 --- a/agents/pages/reference/rules/wildcard-over-owned-variant.md +++ b/agents/pages/reference/rules/wildcard-over-owned-variant.md @@ -4,7 +4,9 @@ a wildcard arm in a match over a variant the code owns -**restriction · warning · nursery · since 1.1 · fix: never · off by default** +| Group | Default | Stability | Fix | Since | +|---|---|---|---|---| +| [restriction](../../guide/selecting-rules.md#groups) | [off](../../guide/selecting-rules.md#turn-rules-on-and-off) | experimental | none | 1.1 | A match over a variant the code owns names every case, so a constructor added later is a compile error at every match that should diff --git a/bench/check/bench_check.ml b/bench/check/bench_check.ml index 967b1f7..95cb2a0 100644 --- a/bench/check/bench_check.ml +++ b/bench/check/bench_check.ml @@ -20,8 +20,10 @@ defaults to all,nursery — the full catalog, the prototype's workload. *) let median xs = - let sorted = List.sort compare xs in - List.nth sorted (List.length sorted / 2) + let sorted = List.sort Float.compare xs in + match List.nth_opt sorted (List.length sorted / 2) with + | Some x -> x + | None -> invalid_arg "median: no samples" let tmp_name = let counter = ref 0 in @@ -110,7 +112,7 @@ let () = prerr_endline ("bench-check: unknown argument " ^ arg); exit 2 in - parse (List.tl (Array.to_list Sys.argv)); + parse (match Array.to_list Sys.argv with [] -> [] | _ :: args -> args); let litany, corpus = match (!litany, !corpus) with | Some l, Some c -> (l, c) @@ -134,7 +136,8 @@ let () = (* Workers: medians per -j over [reps] runs, every page byte-compared against the -j 1 reference. One discarded warmup primes the FS cache. *) let reference = tmp_name "ref" in - ignore (run litany (base @ [ "-j"; "1"; "--no-cache" ]) ~out:reference); + ignore + (run litany (base @ [ "-j"; "1"; "--no-cache" ]) ~out:reference : float); let j1 = ref 0. in List.iter (fun j -> @@ -189,4 +192,4 @@ let () = Sys.remove cold_out; Sys.remove reference; (* Best-effort scratch cleanup; the cache dir is bench-local. *) - ignore (Sys.command (Filename.quote_command "rm" [ "-rf"; cache_dir ])) + ignore (Sys.command (Filename.quote_command "rm" [ "-rf"; cache_dir ]) : int) diff --git a/bench/decode/bench_decode.ml b/bench/decode/bench_decode.ml index 7798f6f..5bb5cee 100644 --- a/bench/decode/bench_decode.ml +++ b/bench/decode/bench_decode.ml @@ -26,11 +26,13 @@ module Stats = struct | 0 -> 0. | n -> let rank = int_of_float (ceil (p /. 100. *. float_of_int n)) in - xs.(max 0 (min (n - 1) (rank - 1))) + xs.(Int.max 0 (Int.min (n - 1) (rank - 1))) let median xs = - let sorted = List.sort compare xs in - List.nth sorted (List.length sorted / 2) + let sorted = List.sort Float.compare xs in + match List.nth_opt sorted (List.length sorted / 2) with + | Some x -> x + | None -> invalid_arg "median: no samples" end type rep = { @@ -130,7 +132,7 @@ let measure_corpus ~cmt_root ~source_root () = let wall_s = Unix.gettimeofday () -. t_start in let sorted xs = let a = Array.of_list xs in - Array.sort compare a; + Array.sort Float.compare a; a in { @@ -138,7 +140,9 @@ let measure_corpus ~cmt_root ~source_root () = direct = !direct; derived = !derived; skips = - List.sort compare (Hashtbl.fold (fun k v acc -> (k, v) :: acc) skips []); + List.sort + (fun (a, _) (b, _) -> String.compare a b) + (Hashtbl.fold (fun k v acc -> (k, v) :: acc) skips []); roster_s; wall_s; decoded_files = !decoded_files; @@ -209,7 +213,7 @@ let measure_raw ~cmt_root () = sample, not a failure"]) entries; let sorted = Array.of_list !ms in - Array.sort compare sorted; + Array.sort Float.compare sorted; Printf.printf "raw decode: %d files, %.1f MB in %.2f s -> %.1f MB/s (p50 %.3f ms, p90 \ %.3f ms)\n" @@ -239,7 +243,7 @@ let () = prerr_endline ("bench_decode: unknown argument " ^ arg); exit 2 in - parse (List.tl (Array.to_list Sys.argv)); + parse (match Array.to_list Sys.argv with [] -> [] | _ :: args -> args); match !corpus with | None -> prerr_endline diff --git a/bench/traversal/bench_corpus.ml b/bench/traversal/bench_corpus.ml index b6acaa9..68b68f8 100644 --- a/bench/traversal/bench_corpus.ml +++ b/bench/traversal/bench_corpus.ml @@ -22,7 +22,7 @@ let percentile p xs = | 0 -> 0. | n -> let rank = int_of_float (ceil (p /. 100. *. float_of_int n)) in - xs.(max 0 (min (n - 1) (rank - 1))) + xs.(Int.max 0 (Int.min (n - 1) (rank - 1))) type rep = { entries : int; @@ -74,7 +74,7 @@ let measure ~cmt_root ~source_root ~rules () = entries; let sorted = let a = Array.of_list !analyze_ms in - Array.sort compare a; + Array.sort Float.compare a; a in { @@ -121,7 +121,7 @@ let () = prerr_endline ("bench_corpus: unknown argument " ^ arg); exit 2 in - parse (List.tl (Array.to_list Sys.argv)); + parse (match Array.to_list Sys.argv with [] -> [] | _ :: args -> args); match !corpus with | None -> prerr_endline diff --git a/bench/traversal/bench_traversal.ml b/bench/traversal/bench_traversal.ml index aca84b5..4a05093 100644 --- a/bench/traversal/bench_traversal.ml +++ b/bench/traversal/bench_traversal.ml @@ -51,7 +51,7 @@ let cases = let loaded = load resolver entry in (* Pay the demand-gated parse before sampling: the steady-state cost is traversal + dispatch, not the one-time decode. *) - ignore (analyze ~loaded entry); + ignore (analyze ~loaded entry : Litany.Engine.Report.t); (loaded, entry)) "analyze" (fun (loaded, entry) -> analyze ~loaded entry); @@ -120,7 +120,7 @@ let rule7_gate () = runtest rule's invocation): a filtered, listing, blessing, or help run must not trigger a second measurement. *) let whole_suite_check argv = - Array.to_list argv |> List.tl + (match Array.to_list argv with [] -> [] | _ :: args -> args) |> List.for_all (fun arg -> List.mem arg [ "check"; "--quick"; "--precise" ]) let () = diff --git a/bin/cli_explain.ml b/bin/cli_explain.ml index 128b3b0..648bc23 100644 --- a/bin/cli_explain.ml +++ b/bin/cli_explain.ml @@ -36,15 +36,31 @@ let explain name = | Error code -> code | Ok r -> Printf.printf "%s — %s\n" (Litany.Rule.name r) (Litany.Rule.summary r); - Printf.printf "%s · %s · %s · since %s · fix: %s · %s\n" - (Litany.Rule.Group.to_string (Litany.Rule.group r)) - (match Litany.Rule.Severity.of_group (Litany.Rule.group r) with - | Litany.Rule.Severity.Error -> "error" - | Litany.Rule.Severity.Warning -> "warning") - (Litany.Rule.Stability.to_string (Litany.Rule.stability r)) - (Litany.Rule.since r) (Cli_common.fix_word r) - (if Litany.Rule.on_by_default r then "on by default" - else "off by default"); + (* One line of sentences, the default first: what a reader with a + finding, or deciding to adopt the rule, needs before the doc. *) + let name = Litany.Rule.name r in + let sentences = + [ + (if Litany.Rule.on_by_default r then "On by default." + else + Printf.sprintf "Off by default: turn it on with `(extend %s)`." + name); + ] + @ (match Litany.Rule.Severity.of_group (Litany.Rule.group r) with + | Litany.Rule.Severity.Error -> [ "Reported as an error." ] + | Litany.Rule.Severity.Warning -> []) + @ (match Litany.Rule.stability r with + | Litany.Rule.Stability.Nursery -> [ "Experimental." ] + | Litany.Rule.Stability.Stable -> []) + @ [ + (match Litany.Rule.fix r with + | Litany.Fix.Always -> "Every finding has an automatic fix." + | Litany.Fix.Sometimes -> "Some findings have an automatic fix." + | Litany.Fix.Never -> "No automatic fix."); + Printf.sprintf "Added in %s." (Litany.Rule.since r); + ] + in + print_endline (String.concat " " sentences); print_newline (); let doc = Litany.Rule.doc r in print_string doc; diff --git a/bin/cli_rules.ml b/bin/cli_rules.ml index 5c42ca6..c5689d0 100644 --- a/bin/cli_rules.ml +++ b/bin/cli_rules.ml @@ -15,7 +15,7 @@ let rules () = let catalog = Cli_common.catalog in let name_w = List.fold_left - (fun w r -> max w (String.length (Litany.Rule.name r))) + (fun w r -> Int.max w (String.length (Litany.Rule.name r))) 0 catalog in List.iter @@ -42,33 +42,30 @@ let rules () = (fun r -> Litany.Rule.stability r = Litany.Rule.Stability.Nursery) catalog) in - (* The census names the tier's one distinguishing fact — outside [all], - cherry-picked — so a reader without the manual can see it from the - table alone. *) + (* Restriction rules are the one group [all] leaves out, so the line says + how they are turned on, for a reader without the manual. *) Printf.printf - "%d rules · %d on by default (stable correctness, suspicious, perf) · %d \ - restriction (cherry-picked; outside all) · %d nursery\n" - n on restriction nursery; + "%d rules, %d on by default. %d are experimental. %d are restrictions, \ + each turned on by name.\n" + n on nursery restriction; Cli_common.exit_ok let man = [ `S Manpage.s_description; `P - "$(iname) lists the built-in catalog, one rule per line: name, group \ - (correctness, suspicious, perf, style, pedantic, restriction), \ - stability tier (stable or nursery), fix promise (never, sometimes, \ - always), whether the rule is on by default, and its one-line summary. \ - The table derives from the same declarations the engine runs, so it \ - cannot drift."; + "$(iname) lists every rule, one per line: its name, its group \ + (correctness, suspicious, perf, style, pedantic, restriction), whether \ + it is stable or experimental (nursery), whether its findings have an \ + automatic fix (never, sometimes, always), whether it is on by default, \ + and what it finds."; `P - "Group is policy: correctness findings render as errors, everything else \ - as warnings; stable correctness, suspicious, and perf rules are the \ - default set. Nursery rules are off under every group and set until \ - graduated — select them with $(b,--select nursery) or by exact name. \ - Restriction rules are house policies over legitimate code — outside \ - $(b,all), cherry-picked by exact name. $(b,litany explain) $(i,RULE) \ - prints one rule's full story."; + "Correctness findings are errors and the rest are warnings. The stable \ + correctness, suspicious and perf rules run by default. An experimental \ + rule runs only under $(b,--select nursery) or its own name. Restriction \ + rules forbid code that is valid in general, so $(b,all) leaves them out \ + and each is turned on by name. $(b,litany explain) $(i,RULE) prints one \ + rule's documentation."; ] let cmd = diff --git a/docs/catalog.ts b/docs/catalog.ts index a6e8585..c2d9e69 100644 --- a/docs/catalog.ts +++ b/docs/catalog.ts @@ -88,6 +88,26 @@ function body(doc: string): string { rmSync(out, { recursive: true, force: true }); mkdirSync(out, { recursive: true }); +// A rule's facts, as a table apart from its doc: its group, whether it runs +// by default, whether it is experimental, whether its findings carry a fix, +// and since when. The row gives all but the version, which only +// `litany explain` prints. +function facts(row: Row, policy: string): string[] { + const since = /Added in ([^ ]+)\.$/.exec(policy)?.[1]; + if (!since) { + console.error(`litany explain ${row.name} names no version: ${policy}`); + process.exit(2); + } + const on = row.state === "on" ? "on" : "[off](/litany/guide/selecting-rules/#turn-rules-on-and-off)"; + const stability = row.stability === "nursery" ? "experimental" : "stable"; + const fix = { never: "none", sometimes: "some findings", always: "every finding" }[row.fix]; + return [ + "| Group | Default | Stability | Fix | Since |", + "|---|---|---|---|---|", + `| [${row.group}](/litany/guide/selecting-rules/#groups) | ${on} | ${stability} | ${fix} | ${since} |`, + ]; +} + for (const row of rows) { const [, policy, , ...doc] = litany("explain", row.name).trimEnd().split("\n"); writeFileSync( @@ -100,7 +120,7 @@ for (const row of rows) { "", generated(`litany explain ${row.name}`), "", - `**${policy}**`, + ...facts(row, policy), "", body(doc.join("\n")), ].join("\n"), @@ -125,10 +145,7 @@ writeFileSync( "", generated("litany rules"), "", - "[Selecting rules](/litany/guide/selecting-rules/) says what the columns", - "decide.", - "", - `**${total}**`, + `${total} [Selecting rules](/litany/guide/selecting-rules/) explains the columns.`, "", "| Rule | Group | Stability | Fix | Default | Finds |", "|---|---|---|---|---|---|", diff --git a/docs/src/content/docs/guide/build-integration.md b/docs/src/content/docs/guide/build-integration.md index 56560f5..d705a7c 100644 --- a/docs/src/content/docs/guide/build-integration.md +++ b/docs/src/content/docs/guide/build-integration.md @@ -86,10 +86,13 @@ The file is [canonical s-expressions](https://en.wikipedia.org/wiki/Canonical_S- 3. `(cmi-dirs ...)`, 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. diff --git a/docs/src/content/docs/guide/ci.md b/docs/src/content/docs/guide/ci.md index e95109e..8a94841 100644 --- a/docs/src/content/docs/guide/ci.md +++ b/docs/src/content/docs/guide/ci.md @@ -24,9 +24,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 diff --git a/docs/src/content/docs/guide/configuration.md b/docs/src/content/docs/guide/configuration.md index 3dc88fa..87bd36a 100644 --- a/docs/src/content/docs/guide/configuration.md +++ b/docs/src/content/docs/guide/configuration.md @@ -31,17 +31,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](/litany/guide/selecting-rules/#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](/litany/guide/selecting-rules/) explains. To keep a `restriction` rule out of tests, adopt it and ring them off: @@ -64,7 +55,7 @@ Four rules take options, each documented on its own page: | [`restricted-export-name`](/litany/reference/rules/restricted-export-name/) | `(forbid-suffix )`, `(max-underscores )` | reports nothing | | [`wildcard-over-owned-variant`](/litany/reference/rules/wildcard-over-owned-variant/) | `(owned ...)` | 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 diff --git a/docs/src/content/docs/guide/fixing.md b/docs/src/content/docs/guide/fixing.md index 4b36c95..1f4e18d 100644 --- a/docs/src/content/docs/guide/fixing.md +++ b/docs/src/content/docs/guide/fixing.md @@ -18,7 +18,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 diff --git a/docs/src/content/docs/guide/selecting-rules.md b/docs/src/content/docs/guide/selecting-rules.md index 73d03f4..41b183c 100644 --- a/docs/src/content/docs/guide/selecting-rules.md +++ b/docs/src/content/docs/guide/selecting-rules.md @@ -1,68 +1,97 @@ --- title: Selecting rules -description: "Groups, stability, fix promises and the project rules." +description: "Choose which rules run." --- -`litany rules` lists every rule with its group, stability, fix promise and -default state; [the rules](/litany/reference/rules/) are the same list, here. -Choose what runs with `--select` and `--ignore`, or in -[the `litany` file](/litany/guide/configuration/). +By default litany runs the rules that find bugs. You turn on everything else. +[The rules](/litany/reference/rules/) 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](/litany/guide/configuration/): + +```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](/litany/guide/fixing/). +Each rule says whether `--fix` can repair what it finds: always, sometimes or +never. Its tests hold it to that. [Fixing](/litany/guide/fixing/) 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`](/litany/guide/configuration/#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`](/litany/guide/configuration/#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. diff --git a/docs/src/content/docs/guide/suppression.md b/docs/src/content/docs/guide/suppression.md index acfef44..653f2b7 100644 --- a/docs/src/content/docs/guide/suppression.md +++ b/docs/src/content/docs/guide/suppression.md @@ -30,7 +30,7 @@ reported. ## What attributes can't cover - Text rules (`trailing-whitespace`, `missing-final-newline`) aren't tied to a - node; use [`per-path`](/litany/guide/configuration/#ignoring-by-path). + node. Use [`per-path`](/litany/guide/configuration/#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. diff --git a/docs/src/content/docs/guide/writing-a-rule.mdx b/docs/src/content/docs/guide/writing-a-rule.mdx index 1d707d2..624c84f 100644 --- a/docs/src/content/docs/guide/writing-a-rule.mdx +++ b/docs/src/content/docs/guide/writing-a-rule.mdx @@ -14,7 +14,7 @@ A rule is one OCaml value in one file, a registry entry and a fixture. - **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](/litany/guide/selecting-rules/#groups)). - **Stability**: every new rule is `Nursery`: write @@ -115,12 +115,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 diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index 7ed4229..1602b49 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -25,7 +25,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](/litany/guide/build-integration/#unit-files). Given this library: diff --git a/docs/src/content/docs/reference.md b/docs/src/content/docs/reference.md index d15ea21..52324ca 100644 --- a/docs/src/content/docs/reference.md +++ b/docs/src/content/docs/reference.md @@ -23,12 +23,12 @@ on findings, 2 on a refusal and 3 on an internal error. | `--fix`, `--unsafe` | [apply safe fixes](/litany/guide/fixing/), and unsafe ones too | | `--format=FMT` | [`text`, `json` or `github`](/litany/guide/ci/#output-formats) | | `--root=DIR` | run against the workspace at `DIR` | -| `--no-build` | don't build first; stale artifacts are skips | +| `--no-build` | don't build first, and skip stale artifacts | | `--list-units` | list the units that would be linted and those skipped, and run no rule | | `--explain-withheld` | say which skip blocked which [project rule](/litany/guide/selecting-rules/#project-rules) | | `--units=FILE` | take the units from [a unit file](/litany/guide/build-integration/#unit-files) | | `--cmt-root=DIR` | [walk a directory of artifacts](/litany/guide/build-integration/#a-directory-of-artifacts) | -| `--trust-build` | with a build litany didn't run, lint preprocessed units instead of skipping them; a stale one is still skipped | +| `--trust-build` | with a build litany didn't run, lint preprocessed units instead of skipping them, but still skip a stale one | | `-j N`, `--jobs=N` | [use `N` worker processes](/litany/guide/build-integration/#workers) | | `--cache-dir=DIR`, `--no-cache`, `--cache-stats` | [control the cache](/litany/guide/build-integration/#the-cache) | | `--no-progress` | don't draw the progress line, which only a terminal gets | @@ -37,7 +37,7 @@ on findings, 2 on a refusal and 3 on an internal error. | Option | What it does | |---|---| -| `--dump` | print the file readably; the default | +| `--dump` | print the file readably, the default | | `--save=FILE` | write it to `FILE` | | `--root=DIR`, `--no-build`, `--cmt-root=DIR` | as for `litany check` | @@ -54,7 +54,13 @@ on findings, 2 on a refusal and 3 on an internal error. | `LITANY_CACHE_DIR`, `XDG_CACHE_HOME` | [where the cache is](/litany/guide/build-integration/#the-cache) | | `LITANY_NO_PROGRESS` | as `--no-progress` | | `GITHUB_ACTIONS` | makes `github` the default format | -| `NO_COLOR`, `OCAML_COLOR` | `NO_COLOR` turns colour off; `OCAML_COLOR` is `always` or `never` | +| `NO_COLOR`, `OCAML_COLOR` | `NO_COLOR` turns colour off, and `OCAML_COLOR` is `always` or `never` | + +## The packages + +| Package | Libraries | What it is | +|---|---|---| +| `hypha-litany` | none | The `litany` command and its rules. Its libraries are private to its source tree, as below | ## Libraries diff --git a/lib/apply.ml b/lib/apply.ml index 3ae30b4..3c07498 100644 --- a/lib/apply.ml +++ b/lib/apply.ml @@ -153,7 +153,7 @@ let parses ~path bytes = Fun.protect ~finally:(fun () -> Warnings.restore warnings) (fun () -> - let (_ : Warnings.alert option) = Warnings.parse_options false "-a" in + ignore (Warnings.parse_options false "-a" : Warnings.alert option); match if Filename.check_suffix path ".mli" then ignore (Parse.interface lexbuf : Parsetree.signature) diff --git a/lib/cache.ml b/lib/cache.ml index df5dae8..aa7574d 100644 --- a/lib/cache.ml +++ b/lib/cache.ml @@ -187,7 +187,8 @@ let dir t = Filename.concat t.root t.digest let ensure_marker t = let marker = Filename.concat (dir t) marker_name in if not (Sys.file_exists marker) then - ignore (write_atomic ~dir:(dir t) ~name:marker_name (t.workspace ^ "\n")) + ignore + (write_atomic ~dir:(dir t) ~name:marker_name (t.workspace ^ "\n") : bool) (* {1 Storing and loading} *) @@ -197,7 +198,7 @@ let store t ~now key payload = ensure_marker t; let hex = Key.to_hex key in if write_atomic ~dir ~name:hex (encode_entry key payload) then - ignore (write_atomic ~dir ~name:(hex ^ ".stamp") (stamp_bytes now)) + ignore (write_atomic ~dir ~name:(hex ^ ".stamp") (stamp_bytes now) : bool) let load t key = match read_file (Filename.concat (dir t) (Key.to_hex key)) with @@ -219,7 +220,8 @@ let stamp_read t ~now read = (fun key -> let hex = Key.to_hex key in if Sys.file_exists (Filename.concat dir hex) then - ignore (write_atomic ~dir ~name:(hex ^ ".stamp") (stamp_bytes now))) + ignore + (write_atomic ~dir ~name:(hex ^ ".stamp") (stamp_bytes now) : bool)) read (* Evict entries unread for [max_age]; re-stamp entries whose stamp is @@ -241,7 +243,9 @@ let sweep_entries t ~now = incr evicted end | None -> - ignore (write_atomic ~dir ~name:(name ^ ".stamp") (stamp_bytes now)) + ignore + (write_atomic ~dir ~name:(name ^ ".stamp") (stamp_bytes now) + : bool) end else if Filename.check_suffix name ".stamp" diff --git a/lib/config_file.ml b/lib/config_file.ml index ea2a152..2e1d2fd 100644 --- a/lib/config_file.ml +++ b/lib/config_file.ml @@ -303,7 +303,7 @@ let each_key ~context ~keys items handle = else fail line col "unknown key %S in (%s ...)%s" key context (hint ~candidates:keys key) - | _ -> + | Sexp.Atom _ | Sexp.List _ -> fail item.line item.col "expected a (key ...) form in (%s ...)" context) items diff --git a/lib/driver.ml b/lib/driver.ml index 62c2510..4b72fc7 100644 --- a/lib/driver.ml +++ b/lib/driver.ml @@ -380,7 +380,7 @@ module Parallel = struct | None -> 1 | Some p -> ( match (Unix.stat p).Unix.st_size with - | s -> max 1 s + | s -> Int.max 1 s | exception Unix.Unix_error _ -> 1) in let k = least_loaded () in @@ -625,7 +625,7 @@ module Parallel = struct let check ~progress ~jobs ~cache ~rules ~catalog ~keep ~roster ~build_current = let entries = Roster.entries roster in - let jobs = min jobs (List.length entries) in + let jobs = Int.min jobs (List.length entries) in if jobs < 2 then None else begin let shards = split ~shards:jobs entries in @@ -1040,7 +1040,7 @@ let apply_pass ~unsafe ~into report ~baselines = let run_engine ~progress ~label ~jobs ~cache roster ~build_current ~rules ~catalog ~keep = let total = List.length (Roster.entries roster) in - Progress.jobs progress (max 1 (min jobs total)); + Progress.jobs progress (Int.max 1 (Int.min jobs total)); Progress.counting progress ~label ~total; match if jobs > 1 then diff --git a/lib/fix.ml b/lib/fix.ml index c189ae7..8c06553 100644 --- a/lib/fix.ml +++ b/lib/fix.ml @@ -44,7 +44,7 @@ let v ?(applicability = Unsafe) ~title edits = "Fix.v: conflicting edits (overlapping, or an insertion inside a \ replaced range)"; if not (Span.is_empty e.span) then - max_stop := max !max_stop (Span.stop e.span)) + max_stop := Int.max !max_stop (Span.stop e.span)) edits; { title; applicability; edits } diff --git a/lib/render.ml b/lib/render.ml index cc62ab6..ceed0b4 100644 --- a/lib/render.ml +++ b/lib/render.ml @@ -171,8 +171,8 @@ let text ?(color = false) ?(fixes = `Hint) ?(notes_detail = false) && p.pos_cnum <= q.pos_cnum then let lead = p.pos_cnum - Span.start sp in - let stop = min q.pos_cnum (Span.stop sp) in - let count = max 1 (stop - p.pos_cnum) in + let stop = Int.min q.pos_cnum (Span.stop sp) in + let count = Int.max 1 (stop - p.pos_cnum) in add "%s%s" (String.make (String.length gutter + lead) ' ') (paint (sev_color severity) (String.make count '^')))); diff --git a/lib/rule.ml b/lib/rule.ml index fcdfe46..06e3577 100644 --- a/lib/rule.ml +++ b/lib/rule.ml @@ -338,7 +338,7 @@ let select ~catalog ~select ~ignore = let tier tokens r = List.fold_left (fun best tok -> - if mentions tok r then max best (specificity tok) else best) + if mentions tok r then Int.max best (specificity tok) else best) (-1) tokens in let chosen = List.filter (fun r -> tier sel r > tier ign r) catalog in diff --git a/lib/rules/dead_code_solver.ml b/lib/rules/dead_code_solver.ml index 6eebca1..1ee232c 100644 --- a/lib/rules/dead_code_solver.ml +++ b/lib/rules/dead_code_solver.ml @@ -87,8 +87,8 @@ let merged_decls decls = let unreachable ~decls ~edges = let decls = merged_decls decls in let count = Uid_map.cardinal decls in - let index_of_uid = Hashtbl.create (max 16 count) in - let decl_array = Array.make (max 1 count) None in + let index_of_uid = Hashtbl.create (Int.max 16 count) in + let decl_array = Array.make (Int.max 1 count) None in let next = ref 0 in Uid_map.iter (fun uid decl -> @@ -96,7 +96,7 @@ let unreachable ~decls ~edges = decl_array.(!next) <- Some decl; incr next) decls; - let successors = Array.make (max 1 count) [] in + let successors = Array.make (Int.max 1 count) [] in List.iter (fun edge -> match @@ -106,7 +106,7 @@ let unreachable ~decls ~edges = | Some user, Some used -> successors.(user) <- used :: successors.(user) | (None | Some _), (None | Some _) -> ()) edges; - let reached = Array.make (max 1 count) false in + let reached = Array.make (Int.max 1 count) false in let stack = Stack.create () in Array.iteri (fun index decl -> diff --git a/lib/rules/trailing_whitespace.ml b/lib/rules/trailing_whitespace.ml index 1a27d9d..c6c68ce 100644 --- a/lib/rules/trailing_whitespace.ml +++ b/lib/rules/trailing_whitespace.ml @@ -42,7 +42,7 @@ let string_ranges text = Fun.protect ~finally:(fun () -> Warnings.restore warnings) (fun () -> - let (_ : Warnings.alert option) = Warnings.parse_options false "-a" in + ignore (Warnings.parse_options false "-a" : Warnings.alert option); go []) let rule = diff --git a/lib/span.ml b/lib/span.ml index 269b455..ddef2fe 100644 --- a/lib/span.ml +++ b/lib/span.ml @@ -18,7 +18,7 @@ let length s = s.stop - s.start let is_empty s = s.start = s.stop let contains s i = s.start <= i && i < s.stop let includes s sub = s.start <= sub.start && sub.stop <= s.stop -let overlaps s s' = max s.start s'.start < min s.stop s'.stop +let overlaps s s' = Int.max s.start s'.start < Int.min s.stop s'.stop let of_location (loc : Location.t) = let start = loc.loc_start.pos_cnum and stop = loc.loc_end.pos_cnum in diff --git a/lib/suggest.ml b/lib/suggest.ml index 89eae8d..d4d098d 100644 --- a/lib/suggest.ml +++ b/lib/suggest.ml @@ -13,7 +13,9 @@ let levenshtein a b = row.(0) <- i; for j = 1 to lb do let cost = if a.[i - 1] = b.[j - 1] then 0 else 1 in - let v = min (min (row.(j) + 1) (row.(j - 1) + 1)) (!diag + cost) in + let v = + Int.min (Int.min (row.(j) + 1) (row.(j - 1) + 1)) (!diag + cost) + in diag := row.(j); row.(j) <- v done diff --git a/lib/suppress.ml b/lib/suppress.ml index 91bf82b..682d2b6 100644 --- a/lib/suppress.ml +++ b/lib/suppress.ml @@ -23,8 +23,8 @@ module Directive = struct let deletion ~source d = let len = String.length source in - let start = min (Span.start d.span) len - and stop = min (Span.stop d.span) len in + let start = Int.min (Span.start d.span) len + and stop = Int.min (Span.stop d.span) len in let rec back i = if i > 0 && horizontal source.[i - 1] then back (i - 1) else i in @@ -334,7 +334,7 @@ let of_structure ~source_length tree = mark c sp; let scope = Span.v ~start:(Span.start sp) - ~stop:(max c.source_length (Span.start sp)) + ~stop:(Int.max c.source_length (Span.start sp)) in record c attr ~scope end diff --git a/litany b/litany index 5560f5c..255abe9 100644 --- a/litany +++ b/litany @@ -1,5 +1,230 @@ -; litany's own workspace config. The default set is the gate (runtest); -; the full catalog is the audit spelling, run deliberately: +; Hypha's lint set, as litany holds it. Every Hypha repository's litany file +; selects each rule here and keeps each forbid as it is written here; what is +; the repository's own -- a forbid more, a per-path -- is added with its +; reason. Hypha's OCAML.md says what each rule is for. + +(litany-config 1) + +(lint + (select default) + (extend + unsafe-partial-stdlib + unsafe-obj-magic + untyped-ignore + ignored-result + wildcard-over-owned-variant + open-of-ordinary-module + restricted-dependency)) + +(rule restricted-dependency + ; Refused in every file. + (forbid Stdlib.failwith + (use "a result; a test that raises on purpose declares its own exception")) + (forbid Stdlib.compare + (use "the type's own comparison: Int.compare, String.compare")) + (forbid Stdlib.min + (use "the type's own: Int.min, Float.min")) + (forbid Stdlib.max + (use "the type's own: Int.max, Float.max")) + (forbid Unix.time + (use "the clock the caller gives, read as a Ptime.t")) + (forbid Unix.gettimeofday + (use "the clock the caller gives, read as a Ptime.t")) + (forbid Stdlib.Sys.time + (use "Eio.Time.Mono.now, for time that has passed")) + (forbid Unix.sleep + (use "Eio.Time.Mono.sleep_span")) + (forbid Unix.alarm + (use "Eio.Time.Timeout.v")) + (forbid Unix.setitimer + (use "Eio.Time.Timeout.v")) + (forbid Unix.getitimer + (use "Eio.Time.Mono.now")) + (forbid Eio_unix.sleep + (use "Eio.Time.Mono.sleep_span")) + (forbid Eio.Time.sleep + (use "Eio.Time.Mono.sleep_span")) + (forbid Eio.Time.sleep_until + (use "Eio.Time.Mono.sleep_span, over the span from now to the instant")) + (forbid Eio.Time.with_timeout + (use "Eio.Time.Timeout.v, given an Mtime.Span.t")) + (forbid Eio.Time.with_timeout_exn + (use "Eio.Time.Timeout.v, given an Mtime.Span.t")) + (forbid Eio.Time.Timeout.seconds + (use "Eio.Time.Timeout.v, given an Mtime.Span.t")) + (forbid Eio.Time.Mono.sleep + (use "Eio.Time.Mono.sleep_span")) + (forbid Uri.query + (use "what the router decoded and validated")) + (forbid Uri.get_query_param + (use "what the router decoded and validated")) + ; Refused outside a library's clock module. + (forbid Eio.Time.now + (use "the library's instant.ml, which gives a Ptime.t") + (except **/instant.ml)) + (forbid Unix.sleepf + (use "the library's instant.ml, which takes an Mtime.Span.t") + (except **/instant.ml)) + ; Refused in a library: a program, a test and an example own their process, + ; wherever in the tree its bin/, test/, examples/ or bench/ is. + (forbid Stdlib.Sys.getenv + (use "a value the executable read at startup and passed in") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.getenv_opt + (use "a value the executable read at startup and passed in") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Unix.getenv + (use "a value the executable read at startup and passed in") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Unix.environment + (use "a value the executable read at startup and passed in") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Unix.putenv + (use "an argument: a library sets no global state") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.argv + (use "a value the executable read at startup and passed in") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.signal + (use "the executable: it owns the process's signals") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.set_signal + (use "the executable: it owns the process's signals") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.chdir + (use "a directory capability the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Sys.command + (use "Eio.Process, on the process manager the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.at_exit + (use "Eio.Switch.on_release, on the switch the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Random.self_init + (use "a Random.State.t, or the secure random source the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Random.init + (use "a Random.State.t, or the secure random source the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Logs.set_reporter + (use "the executable: it configures the log reporter") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Logs.set_level + (use "the executable: it configures the log level") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_string + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_endline + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_bytes + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_char + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_int + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_float + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.print_newline + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_string + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_endline + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_bytes + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_char + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_int + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_float + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.prerr_newline + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.stdout + (use "a sink the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.stderr + (use "a sink the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Printf.printf + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Printf.eprintf + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Format.printf + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Format.eprintf + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Format.print_string + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Format.std_formatter + (use "a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Stdlib.Format.err_formatter + (use "a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Fmt.pr + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Fmt.epr + (use "a log on the library's own source, or a formatter the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Eio_main.run + (use "the env, switch or capability the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Ptime_clock.now + (use "the clock or ~now the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Mtime_clock.now + (use "the clock the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Mtime_clock.elapsed + (use "the clock the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Mtime_clock.counter + (use "the clock the caller gives") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + ; Refused in a Melange library: the console is the page's. + (forbid Js.log + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Js.log2 + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Js.log3 + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Js.log4 + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Js.logMany + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**)) + (forbid Js.Console + (use "a value returned to the caller") + (except **/bin/** **/test/** **/examples/** **/bench/**))) + +; litany's own. +; +; The full catalog is the audit spelling, run deliberately: ; litany check --select all,restriction,nursery ; ; The fixture trees under test/ hold @@ -16,5 +241,35 @@ (per-path (paths bench/**) - (ignore suspicious-wall-clock-elapsed) + (ignore suspicious-wall-clock-elapsed restricted-dependency) (reason "a benchmark reports wall time; the stdlib has no monotonic clock")) + +(per-path + (paths lib/rules/**) + (ignore open-of-ordinary-module) + (reason "open Litany is the rule author's whole vocabulary")) + +(per-path + (paths bin/**) + (ignore open-of-ordinary-module) + (reason "open Cmdliner: a library of combinators every line of a command reads")) + +(per-path + (paths test/**) + (ignore open-of-ordinary-module) + (reason "open Windtrap is the tests' vocabulary; every test file opens it")) + +(per-path + (paths examples/custom-binary/my_rules/my_rules.ml) + (ignore open-of-ordinary-module) + (reason "the site shows this file whole, as a rule author writes it: open Litany")) + +(per-path + (paths lib/driver.ml lib/progress.ml lib/adapter.ml) + (ignore restricted-dependency) + (reason "the command's own: it prints, reads its environment, enters a directory and stamps wall time")) + +(per-path + (paths test/vendor_ocamlc_loc/**) + (ignore all) + (reason "vendored from dune and kept as dune wrote it, the report page's oracle")) diff --git a/test/cli/explain.t/run.t b/test/cli/explain.t/run.t index 1429bf2..9d10806 100644 --- a/test/cli/explain.t/run.t +++ b/test/cli/explain.t/run.t @@ -5,7 +5,7 @@ markdown doc — the same source odoc renders on the docs site. $ litany explain needless-list-length needless-list-length — List.length compared with 0 or 1 to test emptiness - perf · warning · stable · since 1.0 · fix: sometimes · on by default + On by default. Some findings have an automatic fix. Added in 1.0. Comparing `List.length` with a constant zero or one to ask "is this list empty?" walks the whole list to answer a constant-time question. diff --git a/test/cli/rules.t/run.t b/test/cli/rules.t/run.t index 4a29831..067f547 100644 --- a/test/cli/rules.t/run.t +++ b/test/cli/rules.t/run.t @@ -25,11 +25,11 @@ all, cherry-picked by exact name: $ litany rules | grep -E "^ignored-result " ignored-result restriction stable never off result or option value is discarded by a wildcard binding -The summary counts the whole catalog, names the default-set law, and -names the cherry-picked tier (restriction is outside all): +The summary counts the catalog, the rules on by default, the experimental +ones and the restrictions, which all leaves out, so each is turned on by name: $ litany rules | tail -1 - 84 rules · 30 on by default (stable correctness, suspicious, perf) · 14 restriction (cherry-picked; outside all) · 16 nursery + 84 rules, 30 on by default. 16 are experimental. 14 are restrictions, each turned on by name. One line per rule plus the summary — the table and the count cannot disagree: diff --git a/test/rules/local_alias_hop/test_local_alias_hop.ml b/test/rules/local_alias_hop/test_local_alias_hop.ml index 8ec8b7c..0280b66 100644 --- a/test/rules/local_alias_hop/test_local_alias_hop.ml +++ b/test/rules/local_alias_hop/test_local_alias_hop.ml @@ -24,13 +24,13 @@ let shadow_cmt_path = "fixtures/.fix_hop.objs/byte/fix_hop__Fix_shadow.cmt" let name s = match Name.of_string s with | Ok n -> n - | Error _ -> failwith ("malformed canonical name " ^ s) + | Error _ -> failf "malformed canonical name %s" s let structure_of path = let infos = Cmt_format.read_cmt path in match infos.Cmt_format.cmt_annots with | Cmt_format.Implementation str -> str - | _ -> failwith "fixture cmt is not an implementation" + | _ -> fail "fixture cmt is not an implementation" let structure () = structure_of cmt_path @@ -58,7 +58,7 @@ let type_head str key = iter.structure iter str; match !found with | Some head -> head - | None -> failwith ("no constructor-typed use site for " ^ key) + | None -> failf "no constructor-typed use site for %s" key let scope local = let resolver = Resolver.create ~cmi_dirs:[ Config.standard_library ] in diff --git a/test/rules/needless_append_empty/test_needless_append_empty.ml b/test/rules/needless_append_empty/test_needless_append_empty.ml index 7580eea..e79b04c 100644 --- a/test/rules/needless_append_empty/test_needless_append_empty.ml +++ b/test/rules/needless_append_empty/test_needless_append_empty.ml @@ -18,7 +18,7 @@ let fixes () = (fun (_, f) -> match Litany.Finding.fix f with | Some fix -> fix - | None -> failwith "finding without a fix") + | None -> fail "finding without a fix") (Litany.Engine.Report.findings (Support.report rule ~source ~cmt)) let () = diff --git a/test/rules/quadratic_string_concat_chain/test_quadratic_string_concat_chain.ml b/test/rules/quadratic_string_concat_chain/test_quadratic_string_concat_chain.ml index c4a4166..e22bbb0 100644 --- a/test/rules/quadratic_string_concat_chain/test_quadratic_string_concat_chain.ml +++ b/test/rules/quadratic_string_concat_chain/test_quadratic_string_concat_chain.ml @@ -20,15 +20,16 @@ let config_src n = text, positions included. *) let options_of src = match Litany.Config_file.parse src with - | Ok c -> - Litany.Config_file.Rule_options.options - (List.hd (Litany.Config_file.rules c)) - | Error e -> failwith (Litany.Config_file.Error.to_string e) + | Ok c -> ( + match Litany.Config_file.rules c with + | r :: _ -> Litany.Config_file.Rule_options.options r + | [] -> fail "the config has no (rule ...) form") + | Error e -> fail (Litany.Config_file.Error.to_string e) let configured n = match Litany.Rule.configure rule (options_of (config_src n)) with | Ok r -> r - | Error e -> failwith e.Litany.Rule.Options.message + | Error e -> fail e.Litany.Rule.Options.message let () = exit diff --git a/test/rules/support/rules_test_support.ml b/test/rules/support/rules_test_support.ml index abc2988..53bfde5 100644 --- a/test/rules/support/rules_test_support.ml +++ b/test/rules/support/rules_test_support.ml @@ -203,10 +203,9 @@ let check_project_marshal rule units = match Litany.Unit.load ~resolver ~build_current:true entry with | Ok u -> collect u | Error sk -> - failwith - (Format.asprintf "fixture unit skipped: %s (%a)" - (Litany.Roster.Entry.source entry) - Litany.Unit.Skip.pp sk)) + failf "fixture unit skipped: %s (%a)" + (Litany.Roster.Entry.source entry) + Litany.Unit.Skip.pp sk) (project_entries units) in (* [Litany.Rule.project] seals each fact as one Marshal frame inside @@ -228,4 +227,4 @@ let check_project_marshal rule units = (list (triple string string int)) (view (report facts)) (view (report facts)) - | _ -> failwith "check_project_marshal: not a project rule" + | _ -> fail "check_project_marshal: not a project rule" diff --git a/test/rules/unused_export/test_unused_export.ml b/test/rules/unused_export/test_unused_export.ml index e03c087..1fc4313 100644 --- a/test/rules/unused_export/test_unused_export.ml +++ b/test/rules/unused_export/test_unused_export.ml @@ -9,6 +9,9 @@ [@litany.root] annotation) plus one executable. *) open Windtrap + +exception Collect_boom + module Support = Rules_test_support let rule = Litany_rules.Unused_export.rule @@ -182,7 +185,7 @@ let honesty = (Litany.Rule.meta ~name:"boom-collect" ~group:Litany.Rule.Suspicious ~since:"1.0" ~fix:Litany.Rule.Never ~summary:"test rule" ~doc:"test rule" ()) - ~collect:(fun _ -> failwith "collect boom") + ~collect:(fun _ -> raise Collect_boom) ~report:(fun _ -> []) in let rep = Support.project_report [ rule; boom ] (units ()) in diff --git a/test/unit/test_adapter.ml b/test/unit/test_adapter.ml index 8816ac7..4ec5cb3 100644 --- a/test/unit/test_adapter.ml +++ b/test/unit/test_adapter.ml @@ -91,7 +91,7 @@ let dune_tests = let r = dune_roster dir in let alias = entry_for r "_build/default/lib/inv__.ml-gen" in equal (option string) (Some "inv") (Roster.Entry.library alias); - ignore (entry_for r "lib/inv.ml")); + ignore (entry_for r "lib/inv.ml" : Roster.Entry.t)); test "a private library reads Private; an unfound stanza stays Unknown" (fun () -> let dir, write = craft () in @@ -145,9 +145,9 @@ let dune_tests = ""; write "_build/default/bin/.main.eobjs/byte/dune__exe.cmt" ""; let r = dune_roster dir in - equal int 1 (List.length (Roster.entries r)); - equal string "lib/store.ml" - (Roster.Entry.source (List.hd (Roster.entries r)))); + match Roster.entries r with + | [ entry ] -> equal string "lib/store.ml" (Roster.Entry.source entry) + | entries -> failf "expected one entry, got %d" (List.length entries)); test "same-leaf qualified units cannot steal each other's sources" (fun () -> (* [inv__Fs__Types] and [inv__Other__Types] both look up @@ -163,7 +163,7 @@ let dune_tests = write "_build/default/lib/.inv.objs/byte/inv__Fs__Types.cmt" ""; write "_build/default/lib/.inv.objs/byte/inv__Other__Types.cmt" ""; let r = dune_roster dir in - ignore (entry_for r "lib/fs/types.ml"); + ignore (entry_for r "lib/fs/types.ml" : Roster.Entry.t); let sources = List.map Roster.Entry.source (Roster.entries r) in equal int ~msg:"no duplicate pairing" 1 (List.length (List.filter (String.equal "lib/fs/types.ml") sources))); @@ -180,7 +180,7 @@ let dune_tests = write "other/read_file.ml" ""; write "_build/default/lib/.inv.objs/byte/inv__Fs__Read_file.cmt" ""; let r = dune_roster dir in - ignore (entry_for r "lib/fs/read_file.ml")); + ignore (entry_for r "lib/fs/read_file.ml" : Roster.Entry.t)); test "a built pp source rides its entry" (fun () -> let dir, write = craft () in write "lib/dune" "(library (name inv))\n"; diff --git a/test/unit/test_cache.ml b/test/unit/test_cache.ml index 4289d4a..aa3ee75 100644 --- a/test/unit/test_cache.ml +++ b/test/unit/test_cache.ml @@ -305,7 +305,7 @@ let eviction = with_cache (fun t ~root:_ ~ws:_ -> Cache.store t ~now:t0 (key ()) "payload"; Sys.remove (entry_path t (key ())); - ignore (Cache.sweep t ~now:t0 ~read:[]); + ignore (Cache.sweep t ~now:t0 ~read:[] : Cache.sweep); is_false (Sys.file_exists (entry_path t (key ()) ^ ".stamp")))); test "leftover temp files are deleted" (fun () -> with_cache (fun t ~root:_ ~ws:_ -> @@ -314,7 +314,7 @@ let eviction = Filename.concat (Cache.dir t) ".litany.99999.7.tmp" in write_file residue "half-written"; - ignore (Cache.sweep t ~now:t0 ~read:[]); + ignore (Cache.sweep t ~now:t0 ~read:[] : Cache.sweep); is_false (Sys.file_exists residue))); test "stamping a key never read is harmless" (fun () -> with_cache (fun t ~root:_ ~ws:_ -> @@ -391,7 +391,7 @@ let workspaces = with_cache (fun t ~root ~ws:_ -> let stray = Filename.concat root "README" in write_file stray "not a workspace"; - ignore (Cache.sweep t ~now:t0 ~read:[]); + ignore (Cache.sweep t ~now:t0 ~read:[] : Cache.sweep); is_true (Sys.file_exists stray))); ] diff --git a/test/unit/test_config.ml b/test/unit/test_config.ml index c3c4337..dea00d9 100644 --- a/test/unit/test_config.ml +++ b/test/unit/test_config.ml @@ -132,7 +132,9 @@ let reading_tests = equal (list string) [ "a"; "b" ] (List.map (fun p -> - Glob.to_string (snd (List.hd (Config.Per_path.globs p)))) + match Config.Per_path.globs p with + | (_, glob) :: _ -> Glob.to_string glob + | [] -> fail "a per-path with no glob") (Config.per_paths t))); test "Per_path.matches consults every glob" (fun () -> let t = ok "(per-path (paths vendor/** gen/*.ml) (ignore all))" in diff --git a/test/unit/test_engine.ml b/test/unit/test_engine.ml index 51a9a9f..1a00ac1 100644 --- a/test/unit/test_engine.ml +++ b/test/unit/test_engine.ml @@ -10,6 +10,9 @@ contract is exercised by fabricating locations. *) open Windtrap + +exception Boom of string + module Engine = Litany.Engine module Report = Litany.Engine.Report module Rule = Litany.Rule @@ -264,10 +267,10 @@ let kinds_tests = (fun (d : Typedtree.type_declaration) -> d.typ_name.txt) ds in - [ - Finding.v ~loc:(List.hd ds).Typedtree.typ_name.loc - (String.concat "," names); - ]) + match ds with + | [] -> [] + | (d : Typedtree.type_declaration) :: _ -> + [ Finding.v ~loc:d.typ_name.loc (String.concat "," names) ]) in let rep = run ~rules:[ r ] [ entry_kinds () ] in (* Anchors ascend in source order, so report order is group @@ -359,8 +362,9 @@ let kinds_tests = let r = Rule.export (meta "exp") (fun u x -> let anchor = - (List.hd (Litany.Unit.implementation u).Typedtree.str_items) - .Typedtree.str_loc + match (Litany.Unit.implementation u).Typedtree.str_items with + | item :: _ -> item.Typedtree.str_loc + | [] -> Location.none in let k = match Litany.Unit.Export.kind x with @@ -618,7 +622,7 @@ let failure_tests = | Typedtree.Texp_constant (Asttypes.Const_int 41) -> [ Finding.v ~loc:e.exp_loc "before boom" ] | Typedtree.Texp_constant (Asttypes.Const_int 1) -> - failwith "boom" + raise (Boom "boom") | _ -> []) in let rep = @@ -795,15 +799,13 @@ let suppression_tests = test "no rule may take an engine-owned audit name" (fun () -> raises_match (function Invalid_argument _ -> true | _ -> false) - (fun () -> - run ~rules:[ flag_int ~name:"unused-allow" () ] [] |> ignore); + (fun () -> run ~rules:[ flag_int ~name:"unused-allow" () ] []); raises_match (function Invalid_argument _ -> true | _ -> false) (fun () -> run ~catalog:[ flag_int ~name:"unfulfilled-expect" () ] - ~rules:[] [] - |> ignore)); + ~rules:[] [])); test "a floating directive covers the rest of the file" (fun () -> let rep = run ~rules:[ flag_int () ] [ allow_entry flo_source ] in equal shape_t @@ -921,7 +923,9 @@ let suppression_tests = (messages rep); equal int 1 (Report.exit_code rep)); test "a failed rule's directives audit nothing on that unit" (fun () -> - let bomb = Rule.expr (meta "flag-int") (fun _ _ -> failwith "boom") in + let bomb = + Rule.expr (meta "flag-int") (fun _ _ -> raise (Boom "boom")) + in let rep = run ~rules:[ bomb ] [ allow_entry alw_source ] in equal shape_t [] (shape rep); equal suppressed_t [] (suppressed_shape rep); @@ -1302,7 +1306,7 @@ let unit_cache_tests = same_report plain rep); test "a unit with a rule failure is reported but never stored" (fun () -> let tbl, uc = store_all () in - let boom = Rule.expr (meta "boom") (fun _ _ -> failwith "boom") in + let boom = Rule.expr (meta "boom") (fun _ _ -> raise (Boom "boom")) in let rep = Engine.run ~unit_cache:uc ~rules:[ boom ] ~catalog:[ boom ] ~roster:(Litany.Roster.v [ entry_a () ]) diff --git a/test/unit/test_fix.ml b/test/unit/test_fix.ml index 5115656..13b2ae0 100644 --- a/test/unit/test_fix.ml +++ b/test/unit/test_fix.ml @@ -84,7 +84,9 @@ let constructors = Fix.safe_replace Location.none "x" ~title:"t")); test "a zero-width location is an insertion point" (fun () -> let f = Fix.safe_replace (loc 7 7) "\n" ~title:"t" in - is_true (Span.is_empty (List.hd (spans f)))); + match spans f with + | span :: _ -> is_true (Span.is_empty span) + | [] -> fail "the fix has no edit"); ] let updating = diff --git a/test/unit/test_formats.ml b/test/unit/test_formats.ml index 7f7559d..523914d 100644 --- a/test/unit/test_formats.ml +++ b/test/unit/test_formats.ml @@ -12,6 +12,9 @@ create. *) open Windtrap + +exception Boom of string + module Engine = Litany.Engine module Rule = Litany.Rule module Finding = Litany.Finding @@ -151,10 +154,12 @@ let json_tests = (* The exit-3 law's machine channel: a consumer that never parses the text page still sees which rule failed where, and the trailer's exit says the code hardened. *) - let boom = Rule.expr (meta "boom") (fun _ _ -> failwith "kaboom") in + let boom = + Rule.expr (meta "boom") (fun _ _ -> raise (Boom "kaboom")) + in equal string ("{\"summary\":{\"schema\":1,\"rules_selected\":1,\"findings\":0,\"fixable\":0,\"units\":1,\"linted\":1,\"facts_only\":0,\"suppressed\":0,\"skipped\":[]," - ^ "\"failures\":[{\"rule\":\"boom\",\"path\":\"fixtures/engine/plain/emit_a.ml\",\"message\":\"Failure(\\\"kaboom\\\")\"}]," + ^ "\"failures\":[{\"rule\":\"boom\",\"path\":\"fixtures/engine/plain/emit_a.ml\",\"message\":\"Dune__exe__Test_formats.Boom(\\\"kaboom\\\")\"}]," ^ "\"degraded\":[],\"notes\":[],\"dropped\":0,\"roster\":[],\"exit\":3}}\n" ) (json (report ~rules:[ boom ] [ entry_a () ]))); diff --git a/test/unit/test_pat.ml b/test/unit/test_pat.ml index 0b65967..5fdad45 100644 --- a/test/unit/test_pat.ml +++ b/test/unit/test_pat.ml @@ -275,12 +275,12 @@ let constant_tests = (fun () -> let e = find "List.length xs" in let calls = ref 0 in - let _ = - run - Pat.(apply (ident "Stdlib.List.length") (__ ^:: nil)) - e - (fun _ -> incr calls) - in + ignore + (run + Pat.(apply (ident "Stdlib.List.length") (__ ^:: nil)) + e + (fun _ -> incr calls) + : unit option); equal int 1 !calls); test "a failed match never applies the continuation" (fun () -> (* The mli's contract: captures are staged, and [k] runs exactly @@ -675,7 +675,10 @@ let views_kinds = run Pat.(erecord none) (find "{ px = 40; py = 41 }") - (fun fs -> Pat.Lbl.res_head (Pat.Field.label (List.hd fs))) + (fun fs -> + match fs with + | field :: _ -> Pat.Lbl.res_head (Pat.Field.label field) + | [] -> None) with | Some (Some p) -> p | _ -> failf "no construction head" @@ -736,10 +739,16 @@ let registry_tests = group "registry" [ test "literal combinators record their names, per namespace" (fun () -> - ignore (Pat.ident "Stdlib.List.length"); - ignore (Pat.ident "Stdlib.List.length"); - ignore (Pat.idents [ "Stdlib.min"; "Stdlib.(@)" ]); - ignore (Pat.typ "Stdlib.result"); + ignore + (Pat.ident "Stdlib.List.length" + : (Typedtree.expression, unit, unit) Pat.t); + ignore + (Pat.ident "Stdlib.List.length" + : (Typedtree.expression, unit, unit) Pat.t); + ignore + (Pat.idents [ "Stdlib.min"; "Stdlib.(@)" ] + : (Typedtree.expression, unit, unit) Pat.t); + ignore (Pat.typ "Stdlib.result" : (Types.type_expr, unit, unit) Pat.t); let values = List.map Litany.Naming.Name.to_string (Pat.Registry.names ()) in diff --git a/test/unit/test_render.ml b/test/unit/test_render.ml index c239cd5..2530f55 100644 --- a/test/unit/test_render.ml +++ b/test/unit/test_render.ml @@ -15,6 +15,9 @@ their justification. *) open Windtrap + +exception Boom of string + module Engine = Litany.Engine module Rule = Litany.Rule module Finding = Litany.Finding @@ -359,12 +362,12 @@ let golden_tests = and corroboration unavailable\n") (render (report ~rules:[ flag_int () ] [ entry_nope () ]))); test "rule failures are listed under the summary" (fun () -> - let bomb = Rule.expr (meta "bomb") (fun _ _ -> failwith "boom") in + let bomb = Rule.expr (meta "bomb") (fun _ _ -> raise (Boom "boom")) in equal string ("1 rule selected \xc2\xb7 1 unit \xc2\xb7 0 findings \xc2\xb7 0 \ skipped\n" ^ "rule bomb failed on fixtures/engine/plain/emit_a.ml: \ - Failure(\"boom\")\n") + Dune__exe__Test_render.Boom(\"boom\")\n") (render (report ~rules:[ bomb ] [ entry_a () ]))); ] @@ -455,8 +458,10 @@ let grammar_tests = in let reports = Ocamlc_loc.parse out in equal (list string) [ a_loc "13-15"; a_loc "18-19" ] (locations out); - equal string "first\n deeper\nlast" - (List.hd reports).Ocamlc_loc.message); + match reports with + | (first : Ocamlc_loc.report) :: _ -> + equal string "first\n deeper\nlast" first.message + | [] -> fail "the page parsed to no report"); test "a multi-line span is the lines L-M form" (fun () -> let out = render (report ~rules:[ two_line_span ] [ entry_a () ]) in equal (list string) diff --git a/test/unit/test_rule.ml b/test/unit/test_rule.ml index bbf0d63..58c2df8 100644 --- a/test/unit/test_rule.ml +++ b/test/unit/test_rule.ml @@ -18,7 +18,7 @@ let meta_tests = [ test "kebab-case names are accepted" (fun () -> List.iter - (fun name -> ignore (meta ~name ())) + (fun name -> ignore (meta ~name () : Rule.meta)) [ "a"; "needless-list-length"; "utf8-in-2024"; "x0" ]); test "non-kebab-case names are refused" (fun () -> List.iter @@ -35,7 +35,7 @@ let meta_tests = "dotted.name"; ]); test "aliases obey the same grammar" (fun () -> - ignore (meta ~renamed_from:[ "old-name" ] ()); + ignore (meta ~renamed_from:[ "old-name" ] () : Rule.meta); raises_match invalid (fun () -> meta ~renamed_from:[ "Bad" ] ())); test "an empty summary is refused" (fun () -> raises_match invalid (fun () -> meta ~summary:"" ())); diff --git a/test/unit/test_source.ml b/test/unit/test_source.ml index eb00489..b2e59bb 100644 --- a/test/unit/test_source.ml +++ b/test/unit/test_source.ml @@ -115,7 +115,7 @@ let lines_and_line = let sp = require_some ~msg:(string_of_int n) (Source.line s n) in equal string ~msg:(Printf.sprintf "line %d" n) - (List.nth parts (n - 1)) + (require_some (List.nth_opt parts (n - 1))) (require_some (Source.slice s sp)) done); ] @@ -127,7 +127,7 @@ let slicing = Gen.(pair gen_contents (pair (int_range 0 40) (int_range 0 40))) (fun (contents, (a, b)) -> let s = src contents in - let start = min a b and stop = max a b in + let start = Int.min a b and stop = Int.max a b in let sp = Span.v ~start ~stop in let expected = if stop <= String.length contents then @@ -234,7 +234,7 @@ let locations = Gen.(pair gen_contents (pair (int_range 0 40) (int_range 0 40))) (fun (contents, (a, b)) -> let s = src contents in - let sp = Span.v ~start:(min a b) ~stop:(max a b) in + let sp = Span.v ~start:(Int.min a b) ~stop:(Int.max a b) in if Span.stop sp <= Source.length s then let loc = require_some (Source.location s sp) in equal span sp (Span.of_location loc)); diff --git a/test/unit/test_span.ml b/test/unit/test_span.ml index 8de4b0f..46f138e 100644 --- a/test/unit/test_span.ml +++ b/test/unit/test_span.ml @@ -13,7 +13,7 @@ let gen_span = let open Gen in with_pp Span.pp (let+ a = int_range 0 200 and+ b = int_range 0 200 in - Span.v ~start:(min a b) ~stop:(max a b)) + Span.v ~start:(Int.min a b) ~stop:(Int.max a b)) let gen_offset = Gen.int_range (-10) 220 diff --git a/test/unit/test_unit.ml b/test/unit/test_unit.ml index f362bdb..e6c8ef4 100644 --- a/test/unit/test_unit.ml +++ b/test/unit/test_unit.ml @@ -679,7 +679,7 @@ let uses_tests = List.map (fun (l : Location.t) -> l.loc_start.pos_cnum) locs in is_true ~msg:"traversal order is source order here" - (List.sort compare offsets = offsets)); + (List.equal Int.equal (List.sort Int.compare offsets) offsets)); test "a qualified use through a module path joins by uid" (fun () -> let u = require_load (Entry.v ~source:uses_source ~cmt:uses_cmt ()) in equal int 2 (List.length (Unit.uses u (bound_uid u "hidden")))); diff --git a/test/unit/test_write.ml b/test/unit/test_write.ml index a6eb62d..ffe22d1 100644 --- a/test/unit/test_write.ml +++ b/test/unit/test_write.ml @@ -34,7 +34,7 @@ let () = test "no temp residue after success or failure" (fun () -> in_dir @@ fun dir -> let path = Filename.concat dir "out" in - ignore (W.atomic ~path "bytes"); + require_ok (W.atomic ~path "bytes"); (match W.atomic ~path:(Filename.concat dir "no/such/dir") "x" with | Ok () -> fail "write into a missing directory succeeded" | Error _ -> ()); @@ -61,11 +61,14 @@ let () = test "a failed write leaves the target's bytes alone" (fun () -> in_dir @@ fun dir -> let path = Filename.concat dir "out" in - ignore (W.atomic ~path "keep"); + require_ok (W.atomic ~path "keep"); (* A directory in place of the temp target's rename destination: rename over an existing non-empty directory fails. *) let clash = Filename.concat dir "clash" in Unix.mkdir clash 0o755; - ignore (W.atomic ~path:(Filename.concat clash "no/way") "x"); + ignore + (require_error + (W.atomic ~path:(Filename.concat clash "no/way") "x") + : string); equal string "keep" (read path)); ]