Expand description
Custom config-defined checks ([rules.checks.<id>]) — a config-only linter
primitive.
A CheckDef pairs a CEL boolean when predicate with a diagnostic
message. The predicate is evaluated per node over everything the node
carries: its numeric / boolean / string attributes (tloc, unsafe,
cyclomatic, …) plus derived path strings (path, name, stem,
ext, dir). String predicates use CEL’s own stdlib (contains,
startsWith, endsWith, matches regex, size, double, …); on top of it
we register only the graph-aware functions (depends_on / depended_on_by /
file_exists). When the predicate is true, the check fires and produces a
CheckHit the CLI turns into a violation.
This is what lets a project express a custom linter — e.g. “no inline tests
in a production file” (tloc > 0 && !path.endsWith("_tests.rs")) — entirely
in code-ranker.toml, with no Rust change. It complements
[rules.thresholds.file] (which only does metric > limit) with an arbitrary
boolean expression and a path-aware, string-aware context.
Structs§
- Check
Compile Error - A
whenpredicate that failed to compile (reported up-front, so the gate fails loudly instead of silently skipping a misspelled check). - Check
Def - One custom check from
[rules.checks.<id>]. - Check
Hit - A fired check on a node — the data a violation is built from.
- Compiled
Check - A compiled check: its id, the parsed predicate program, its definition, and which graph collections the predicate references (so eval binds only those).
- Graph
View - A read-only view of the fully-built level, prepared once per
checkrun and shared across every node’s predicate. Holds the dependency adjacency (by node id → neighbour labels) and the project’s file set / per-folder index. A node’s label is its repo-relativepathattribute when present, else its id (so an external crate staysext:<name>).
Functions§
- compile
- Compile one check’s
whenpredicate. Named helpers from[rules.defs]are expanded into the predicate first (see [expand_defs]), so a check can reuse a shared vocabulary (is_domain,is_test_file, …).