Skip to content

refactor(findings): name every reported rule through one catalogue - #35

Merged
SizzleUnrlsd merged 1 commit into
mainfrom
refactor/rule-catalogue
Oct 23, 2026
Merged

SizzleUnrlsd merged 1 commit into
mainfrom
refactor/rule-catalogue

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Closes #32.

Change

src/findings.cpp only, no change in what the analyzer reports.

  • kRules is the one catalogue of the rules ParseFindings reports: id, title, description, confidence.
  • kBoundsRules, kVtableRules, the double-free and memory-leak reports and the vtable-diagnostic fallback hold a const CatalogueRule& obtained from RuleNamed("<id>"), a consteval lookup into kRules. OneLineFinding takes a catalogue entry instead of a string.
  • DescribeRule reads kRules; its own table is gone.

A rule the parser reports but the catalogue does not describe, or a misspelled id, no longer compiles. The tests in unittests/sarif_test.cpp keep their expected values written out, not read back from the catalogue.

Test first

This is a refactor with a compile-time guarantee, so the red step is a build failure. With RuleNamed("double-free") misspelled as RuleNamed("double-fre"):

src/findings.cpp:400:57: error: call to consteval function '...RuleNamed' is not a constant expression
src/findings.cpp:79:13: note: subexpression not valid in a constant expression
   79 |             throw "rule missing from kRules";

With the ids right, ctest --test-dir build passes 17/17 before and after the change; scripts/format-check.sh is clean on the changed file.

Independent of #34 (which only touches unittests/sarif_test.cpp): either can merge first.

A rule's id, title, description and confidence were spread over the
parser tables, inline ids in ParseFindings and the DescribeRule table,
matched by string. A rule added to the parser and left out of
DescribeRule shipped with no SARIF description and no confidence, and
nothing failed.

kRules is now the one catalogue. The parser tables, the one-line reports
and the vtable fallback name their rule through RuleNamed, a consteval
lookup into kRules, so a rule missing from the catalogue or a misspelled
id does not compile. DescribeRule reads the same catalogue. The SARIF
tests keep their own expected values.

Closes #32
@SizzleUnrlsd
SizzleUnrlsd merged commit dd65981 into main Oct 23, 2026
7 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the refactor/rule-catalogue branch October 23, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rules: keep the parser, the rule descriptions and their tests in one catalogue

1 participant