Credence.Corpus.Findings (credence v0.8.0)

Copy Markdown

Resolves every Pattern finding on a corpus package to a stable identity, used for snapshot-based over-fire regression testing.

Each finding becomes one line:

<corpus-relative path>:<line>  <rule>

with a trailing (xN) on the rare occasion the same (file, line, rule) fires more than once. The accepted set of these lines is pinned in test/corpus/accepted_findings.txt; test/corpus/over_firing_test.exs asserts the live set equals the pin, per package — so a NEW finding (a candidate over-fire) shows up as an unexpected line and fails the suite, rather than being silently swallowed by a rule-level allowlist. Re-pin intentionally with:

mix credence.corpus --update-snapshot

Keying on file:line makes every finding distinct, so the pin is maximally sensitive: any new firing site — even one inside an already-pinned function — is a diff. The cost is that bumping a package version shifts line numbers and forces a re-pin, which is intended: you re-review a package's findings when you upgrade it.

Summary

Functions

Sorted finding-identity lines across every pinned corpus entry.

Sorted finding-identity lines for a single package — the live set to compare against the snapshot's lines for that package.

Format raw {relative_path, line, rule} findings into sorted identity lines, collapsing exact duplicates with an (xN) count. Public for unit testing.

The accepted lines recorded in the snapshot file (blank lines and # comments stripped). Returns [] if the file does not exist yet.

Absolute path to the committed snapshot file.

Functions

all()

@spec all() :: [String.t()]

Sorted finding-identity lines across every pinned corpus entry.

for_package(pkg)

@spec for_package(atom()) :: [String.t()]

Sorted finding-identity lines for a single package — the live set to compare against the snapshot's lines for that package.

format(raw)

@spec format([{String.t(), pos_integer() | nil, atom()}]) :: [String.t()]

Format raw {relative_path, line, rule} findings into sorted identity lines, collapsing exact duplicates with an (xN) count. Public for unit testing.

snapshot_lines()

@spec snapshot_lines() :: [String.t()]

The accepted lines recorded in the snapshot file (blank lines and # comments stripped). Returns [] if the file does not exist yet.

snapshot_path()

@spec snapshot_path() :: String.t()

Absolute path to the committed snapshot file.