feat: add stable rule IDs and a rules reference - #512
Conversation
✅ Deploy Preview for commit-check ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThe change adds stable rule identifiers and documentation URLs to catalog entries, generated rules, validation outcomes, and failure output. It adds a complete rules reference and tests metadata propagation, formatting, catalog filtering, and documentation anchors. ChangesRule metadata flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant RulesCatalog
participant RuleBuilder
participant ValidationEngine
participant FailureReporter
RulesCatalog->>RuleBuilder: provide rule_id and docs_url
RuleBuilder->>ValidationEngine: build metadata-bearing ValidationRule
ValidationEngine->>FailureReporter: pass metadata in CheckOutcome
FailureReporter-->>ValidationEngine: render identified failure output
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #512 +/- ##
==========================================
+ Coverage 97.27% 97.43% +0.15%
==========================================
Files 12 12
Lines 1175 1207 +32
==========================================
+ Hits 1143 1176 +33
+ Misses 32 31 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/rules.rst`:
- Around line 8-12: Update the rules output example to include the Docs:
<rule-url> line after the failure message and suggestion, or show separate
examples distinguishing output modes where the documentation link is omitted in
compact output.
In `@tests/rules_catalog_test.py`:
- Around line 81-86: Update test_internal_entries_have_no_id to assert that the
ignore_authors catalog entry exists and has rule_id set to None, removing the
conditional if rule is not None guard so omission cannot satisfy the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c8b4550e-9d1a-4f80-ade4-54f64ff5212b
📒 Files selected for processing (7)
commit_check/engine.pycommit_check/rule_builder.pycommit_check/rules_catalog.pycommit_check/util.pydocs/index.mddocs/rules.rsttests/rules_catalog_test.py
Merging this PR will regress 1 benchmark
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_signoff_validator_missing_signoff |
410.5 µs | 461.6 µs | -11.08% |
| ⚡ | test_empty_message_passes |
2.9 ms | 2.3 ms | +27.52% |
| 🆕 | test_built_rule_has_id_and_docs_url |
N/A | 607.2 µs | N/A |
| 🆕 | test_internal_entries_have_no_id |
N/A | 631.3 µs | N/A |
| 🆕 | test_to_dict_includes_id_and_docs_url |
N/A | 625.8 µs | N/A |
| 🆕 | test_diagnostic_rules_all_have_ids |
N/A | 264.4 µs | N/A |
| 🆕 | test_docs_url_derives_from_id |
N/A | 279.2 µs | N/A |
| 🆕 | test_name_is_kebab_case |
N/A | 277.1 µs | N/A |
| 🆕 | test_no_docs_url_without_id |
N/A | 271.3 µs | N/A |
| 🆕 | test_rule_ids_are_unique |
N/A | 281 µs | N/A |
| 🆕 | test_rule_ids_are_well_formed |
N/A | 464 µs | N/A |
| 🆕 | test_every_rule_is_documented |
N/A | 931.5 µs | N/A |
| 🆕 | test_identified_checks_are_unique |
N/A | 270.8 µs | N/A |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feature/rule-ids (3f4f6ee) with main (c8303f5)
Footnotes
-
115 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
f682b70 to
d7c519b
Compare
Every check that can report a failure now has a stable rule ID (CC001, CC003, ...) plus a link to its documentation. IDs are assigned in the catalog and attached centrally when rules are built, so new rules inherit their identity automatically. Rule IDs and docs links now appear in the default, compact, and JSON output, giving users a durable handle to reference and look up. Add docs/rules.rst documenting every rule, and a test that fails if a rule ships without a corresponding entry in that page.
Assert unconditionally that the ignore_authors catalog entry and its built rule carry no rule ID; the previous conditional guard let the test pass vacuously if the rule were never built. Show the complete default output in the rules reference, including the Docs link, and document the compact form alongside it.
Attaching the rule ID with dataclasses.replace() rebuilt every rule on each build_all_rules() call, roughly doubling its cost (19us -> 41us) and showing up as a broad benchmark regression. Expose rule_id and docs_url as properties backed by a check-name lookup into the catalog. Identity still lives in one place, so rules cannot carry a stale copy, and building them no longer does extra work. Add a test asserting the lookup's key assumption that identified check names are unique.
Rule IDs print a link to their reference section, and that link ships in terminal output and JSON results. Settle it on the project's own domain before the first release that carries it, so the URLs do not need redirecting later.
effdf71 to
3f4f6ee
Compare
|



Summary
Every check that can report a failure now has a stable rule ID (
CC001,CC003, …) and a link to its documentation. Rule IDs give users a durable handle to reference in code review, docs, and tooling — the same way ESLint, ruff, and SonarQube do.ID ranges
CC0xxCC001message,CC003subject-imperative,CC012require-signed-off-by,CC013ai-attributionCC1xxCC101author-name,CC102author-emailCC2xxCC201branch,CC202merge-baseCC3xxCC301no-force-pushInternal bookkeeping entries that never produce a diagnostic (
ignore_authors) intentionally carry no ID.Output
Default:
Compact:
JSON (
--format json) gainsrule_idanddocs_urlper check.The redundant
Typeprefix was dropped now that the rule ID leads the line.Implementation notes
rules_catalog.py.ValidationRuleexposesrule_id/docs_urlas properties that look the check up in the catalog, so no per-rule copying happens at build time and the ~10ValidationRuleconstruction sites stay untouched. New rules inherit their identity automatically, so this can't drift.docs_urlis derived from the ID, so there is a single source of truth.build_all_rules()benchmarks flat againstmain.Documentation
Adds
docs/rules.rst— a rules reference with a summary table and a section per rule (anchored as#cc001,#cc003, …), wired into the toctree.Testing
tests/rules_catalog_test.py: ID uniqueness, format, propagation into built rules andto_dict(),docs_urlderivation, and that internal entries have no ID.docs/rules.rst.Follow-ups this unlocks
Rule IDs are the prerequisite for SARIF output (
ruleId), per-rule suppression (e.g.# cchk-disable CC003), and linking each finding to its docs from the GitHub Action's PR comment.