rint.git / README.md
README.mdpreviewREADME.mdsource188 lines · 11.8 kB · raw

rint

A linter, written in Rust, that stops Rust code from eroding one change at a time. Every change looks fine on its own; the damage is the slope. rint scores a whole tree and, given a git base, fails when a score gets worse, rather than enforcing a fixed limit that can be sat under forever (complexity 9 passes a limit of 10 every time; it cannot pass a ratchet).

The signals come from SlopCodeBench (arXiv 2603.24755). Test code is never scored as product code. HANDOFF.md has the research and the decisions this is built on.

Use

Everything runs through mise. It installs buck2, reindeer and rust-script; the nix devshell adds the C compiler mise cannot bring, so on a bare machine prefix each command with nix develop -c.

mise trust && mise install        the toolchain
mise tasks                        what can be run
mise run test                     every test, through buck2
mise run rint -- check            score this tree (or: -- check --path ~/some-repo)
mise run rint -- diff HEAD~5      fail if anything got worse since HEAD~5
mise run dogfood                  rint on its own source

The binary takes the same arguments directly (buck2 build //crates/rint-cli:rint, or cargo rint once cargo-rint is on PATH):

rint check                   score the tree; a report, exit 0 unless rint.toml sets deny or limits
rint check --base <rev>      the same, then compare with the git revision
rint diff <rev>              the comparison only
rint erosion | concentration | clones | wrappers | single-use | dispatch
     | allows | tests | branches | casts | lets | graph        one signal each
global flags:  -C <dir>  --config <file>  --format text|json

Exit codes: 0 clean, 1 a regression or a violation, 2 a usage or internal error. The base revision is read with git without checking it out, so a dirty work tree is fine.

Install

rint is released for Linux (x86_64 and aarch64, static musl), macOS (Apple silicon and Intel) and Windows (x86_64) as signed packslip archives, each holding rint and cargo-rint. In a repository's mise.toml:

[tools]
"packslip:github.com/jevgineer/rint" = { version = "0.1.0", pubkey = "RWRBRJ8J7sFC5gpZdjHhDlYlF4P0YsYpi1c5AwnlNsoSYiYyCCR3Alnq", allow_unlogged = true }

allow_unlogged is needed because the release is signed with a key and not recorded in a public transparency log; pubkey is tools/release.pub. mise run release:build and mise run release:sign make a release, and mise run release:refresh signs the list of releases again before it expires; none publishes anything.

The repository is public, but GitHub answers 404 to everyone except the jevgineer account for every jevgineer repository (measured 2026-11-02: api.github.com/repos/jevgineer/rint is 404 anonymously and with another account's token, 200 with jevgineer's). Until that lifts, mise needs that account's token in GITHUB_TOKEN to find the release.

The same release is served without a token by the code host, which reads GitHub with its own token: "packslip:code.lmjtfy.fun/rint" in place of "packslip:github.com/jevgineer/rint", same version and pubkey (the list is https://code.lmjtfy.fun/.well-known/packslip/rint.json). Only pinned versions resolve there while the account is hidden: GitHub lists the account's releases as empty, so latest is 404. And the hidden account's API quota is 60 requests an hour (measured 2026-11-07), of which the code host uses at most 30; when they are spent it answers 502 GitHub did not answer for every release file until the hour's reset.

What it measures

Complexity is computed twice, cyclomatic (the paper's measure, threshold 10) and cognitive (SonarSource's, threshold 15), and every score is reported and ratcheted separately for each.

SignalWhat it findsRatchet
erosionshare of complexity mass (complexity * sqrt(sloc)) in functions above the thresholdrise beyond tolerance
concentrationGini of mass across functions, and the top-20% sharerise beyond tolerance
function growtha function's cyclomatic, cognitive or nesting grew above a floor, or a new one starts above the thresholdany
clonesnormalised-token windows repeated across functionsclone ratio rises
wrappersprivate fns whose whole body forwards their arguments to one callany new
single-useprivate fns with exactly one call site (name-based); a fn on a call cycle, directly or through other fns, is skippedany new, as a warning
dispatchmatch / if chains comparing one value to four or more string literalsany new
branchessibling match arms / if branches with token-identical bodies (names and literals kept, so mergeable with |); bodies differing only in a name belong to clonesany new
allows#[allow(..)] attributes, except those whose lints are all in [allows] permittedany new
casts.clone() or as heavy functions, Rc<RefCell<..>>, Box<dyn Any>any new
letslet x = ..; read once, in the very next statementany new, as a warning
graphmodule cycles and propagation cost per crate (use edges)new cycle, cost rises
teststest inventory; public functions no test mentionsinformational, never fails

Test code is a #[cfg(test)] item, a #[test] / #[bench] / #[tokio::test] function, or any file under tests/, benches/, examples/ (configurable). It is read only to count references to product names.

Flat matches. A match with no catch-all arm (_ or a lowercase binding), no guards, and no branching inside any arm counts 1 in cyclomatic, not one per arm: the "modified cyclomatic complexity" of Lizard (-m) and SciTools Understand. Without a catch-all the compiler checks exhaustiveness, so adding a variant to a data enum is not new logic. Cognitive already scores any match as +1. A match that fails the test counts per arm as before; [complexity] flat_match = "per_arm" turns this off.

Warnings. single-use and lets are reported by check and diff (text and JSON both carry a severity of warning) but never fail the ratchet or a plain check. rint judges them by shape alone: a let can be required by the borrow checker (E0499, E0502) and syn cannot see that, and single-use helpers are often exactly what the growth gate asked a long function to be split into.

Configuration

rint.toml at the scanned root (or --config). Every threshold, with its default, is listed in this repository's own rint.toml. Unknown keys are an error. The numbers are starting guesses.

  • deny = [..] names signals whose findings fail a plain check; it also makes a warning signal an error again, so deny = ["lets"] opts a repository back in.
  • warn = [..] is the list of warning signals, default ["single-use", "lets"]; warn = [] makes every signal an error.
  • [allows] permitted = ["refining_impl_trait", ..]: an #[allow(..)] whose lints are all listed is not a finding. Names match exactly as written, so clippy::too_many_arguments and too_many_arguments are separate entries.
  • [complexity] flat_match = "one" | "per_arm", default "one".

Clippy preset

clippy-preset/ ships a clippy.toml and a lint list for what Clippy can enforce per function, so rint does not reimplement it. See clippy-preset/.

First runs

Read-only runs of the binary built from this tree, 2026-11-01 (rint reads files and git show; it wrote nothing in either repository). check is the plain report; diff HEAD~5 is the ratchet against five commits back, and exits 1 in both repositories because both grew.

~/bootspan~/jevboard~/rint (itself)
functions / sloc / files134 / 1,259 / 123,528 / 36,768 / 330167 / 2,022 / 25
erosion, cyclomatic / cognitive0.000 / 0.0000.349 / 0.4500.280 / 0.266
high functions (above 10 / above 15)0 / 0119 / 808 / 4
largest function9 / 760 / 8216 / 31
Gini of mass, cyclomatic / cognitive0.490 / 0.7160.676 / 0.8570.607 / 0.765
top-20% share0.530 / 0.7310.726 / 0.8950.660 / 0.793
clone ratio0.0110.062 (238 regions)0.011
wrappers / single-use / dispatch4 / 35 / 021 / 341 / 150 / 39 / 0
branches / allows / casts / lets1 / 0 / 0 / 4293 / 12 / 60 / 1,1658 / 0 / 0 / 63
module cycles0170

What the ratchet found. In bootspan, diff HEAD~5 fails on three new single-use helpers (number_json, text_json, container_json), while erosion fell from 0.069 to 0.000 over the same five commits: the shape of a function being split up. In jevboard it fails on 54 items: ten functions that grew (resolve in packages/node/src/entities.rs went from cyclomatic 8 to 18; Because::fmt 13 to 15), four new functions that start above the threshold (Facts::join_said, cognitive 28), a new #[allow(clippy::too_many_arguments)], a new five-arm string match in packages/records, a function with eight .clone() calls, two new module cycles in packages/config and packages/prefs, the prefs propagation cost rising 0.654 to 0.680, and 27 single-use lets.

On itself. Both complexity measures concentrate in a few functions (Walker::visit_expr, cyclomatic 16; signals::clones::find; signals::scc::components, cognitive 31), and the exec and collect modules have several two-arm matches with equal bodies. Those are real findings and are left as found; rint diff on this repository is the check that they do not get worse.

How much to trust it. The thresholds are untuned guesses, and these runs show which signals are noisy. lets (1,165 in jevboard) and single-use (341) fire on a great deal of ordinary, readable code, so as plain counts they are not informative; they are useful only as the ratchet's "new since the base". The module-cycle finding counts a parent module and its child importing from each other, which is common in Rust and real, but a lower-severity cycle than two siblings. Two defects were found and fixed by these runs: files pulled in by #[cfg(test)] mod tests; (also with #[path]) were being scored as product code, and an unchanged erosion printed as -0.000.

Layout

PathWhat
crates/rint-corethe engine: parse with syn, measure, score, compare
crates/rint-clithe command line (library rint_cli and the rint binary)
crates/cargo-rintthe cargo rint forwarder
clippy-preset/clippy.toml and the recommended deny list
rint.tomlrint's own configuration
tools/repository scripts (rust-script)
platforms/, toolchains/, third-party/, .buckconfigbuck2 build setup, shared with the estate's other repositories
HANDOFF.mdthe research and decisions

Outstanding

  • dylint lints (a later, optional phase; not built): the checks that need types, such as a .clone() that exists only to satisfy the borrow checker, a Result that can never be Err, a needless as cast. They need a pinned nightly and compiling code, which is why the syn core does not try.
  • Dependency entropy, the paper's third graph metric: only cycles and propagation cost are built.
  • Thresholds are untuned. They are guesses; tuning needs real before/after pairs of agent-written changes, which this repository does not have.
  • Extra defensive checks (a Result/Option that is never Err/None) need types: dylint.
  • Name-based approximations: single-use, the untested-public list and recursion detection match by name, because syn does no name resolution. Names defined more than once are skipped.