Use this rule in pull request CI after the coverage producers have finished. It catches untested edits even when overall repository coverage stays high.
Check that the changed, instrumented lines in each scoped file meet a minimum covered percentage. The rule merges LCOV shards first, so a line covered in any shard counts as covered once.
rules:
- rule: coverage-patch
scope: repository
include: ['src/**/*.ts']
options:
base: origin/main
lcovFiles: [coverage/unit.lcov, coverage/integration.lcov]
min: 90Run no-mistakes check --format json from the repository root after collecting
coverage for the same checkout. The merge base of options.base and HEAD
defines the older tree. The current worktree supplies added and modified lines,
including untracked source files. When Git detects a rename, only edits in the
renamed file count as changes. Deleted lines and changed lines without LCOV
line entries are outside the denominator. When a scoped changed file has no
LCOV record, the rule parses Rust (.rs) and TypeScript/JavaScript
(.ts, .tsx, .mts, .cts, .js, .jsx, .mjs, .cjs, including
.d.ts) sources and reports the file as unanalyzable only when at least one
added or modified line falls inside an executable construct (such as a function
body, runtime statement, or runtime TypeScript namespace header) and contains
non-comment, non-whitespace code. Declaration-only changes outside executable
bodies — such as Rust mod, use, type, struct, enum, union,
extern, trait signatures without default bodies, attributes, and comments, or
TypeScript type/interface/ambient declarations, type-only namespaces, and
.d.ts files — as well as comment-only and blank lines inside multiline
executable constructs (such as a multiline Rust function signature or body, or a
multiline TypeScript runtime import) pass without an LCOV record. Unreadable
files, unparseable sources, and unsupported extensions still report as
unanalyzable. Configure options.unanalyzable using the
analysis policy; it defaults to report.
The rule judges DA: line hits only; BRDA: branch records never change a
verdict. The parser still accepts them the way the producing toolchain emits
them. - means not taken, and a negative count such as BRDA:83,13,1,-51 (which
llvm-cov writes when a counter expression wraps) has no usable hit count, so it
records zero hits for that branch. It is not an error and does not make the
report unanalyzable. A BRDA: count that is not an integer or - still reports
a scoped malformed-line diagnostic.
Compliant example: both changed executable lines have a positive hit count, even if another unchanged line is uncovered.
Counterexample: a new return statement has zero hits, leaving one of two changed
instrumented lines covered. With min: 90, the finding points to that return
statement. To fix it, add a test that exercises it, then regenerate the LCOV reports.
A failing file produces one finding. Its line is the first uncovered changed
line, its uncoveredLines field lists every uncovered changed line in order,
and the default message names them as compact ranges:
{
"file": "src/main.ts",
"line": 2,
"message": "test lines 2-3, 7: 0/3 instrumented changed lines are covered; at least 100% required",
"rule": "coverage-patch",
"target": "uncovered-lines",
"uncoveredLines": [2, 3, 7]
}A custom message replaces the text only; uncoveredLines is always present.
Use check --format github to turn each finding into a GitHub Actions
annotation on its file and first uncovered line
(docs).
The Git base, LCOV paths, and threshold have no defaults. The baseline and exceptions default to no allowances.
baseis a Git revision available in the local checkout.lcovFilesnames one or more repository-relative trace files. Missing or unreadable reports fail the check. Malformed entries report as unanalyzable.minis an integer percentage between 0 and 100 inclusive. It applies to each scoped file. Use separate rule applications with different path filters to set different thresholds for different folders.baselineFileandexceptionsuse the shared baseline format. Each entry uses the symboluncovered-linesand amaxnumber of uncovered changed lines for its file. Tighten the cap as tests are added.
Suppress a finding with no-mistakes-disable-next-line coverage-patch,
no-mistakes-disable-line coverage-patch, or
no-mistakes-disable-file coverage-patch in the source language's comment syntax.
Suppression is per line. A line directive excuses only its own uncovered line: that line leaves
uncoveredLines, the message, and the min percentage (it counts as neither
covered nor uncovered; a directive on a covered line changes nothing). The file still fails while any other uncovered changed
line remains, and the finding's line moves to the first line that is not
excused. Suppressing every uncovered line passes the file.
no-mistakes-disable-file excuses all of the file's lines.
Node callers can use async check() or the check report from
analyzeProject() with the same YAML and LCOV files. The package exports
CoveragePatchRuleOptions.
crap combines coverage with per-function complexity.