fix: link rule IDs to their documentation in terminal output - #520
Conversation
|
Warning Review limit reached
Next review available in: 51 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe change formats length-rule suggestions with configured limits and adds OSC 8 hyperlink support for validation failure output. It also updates check-name formatting, documentation-link rendering, and related spacing tests. ChangesValidation message improvements
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Sequence Diagram(s)sequenceDiagram
participant FailureOutput
participant print_error_message
participant supports_hyperlinks
participant hyperlink
participant Terminal
FailureOutput->>print_error_message: Pass rule_id and docs_url
print_error_message->>supports_hyperlinks: Check OSC 8 support
supports_hyperlinks-->>print_error_message: Return terminal capability
alt Hyperlinks supported
print_error_message->>hyperlink: Link rule ID to documentation
hyperlink-->>print_error_message: Return OSC 8-formatted ID
end
print_error_message->>Terminal: Print formatted failure message
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 |
The rule ID now carries an OSC 8 hyperlink to its section of the rules reference, the way ruff links its codes, so the ID itself is what you click. Where that renders, the separate "Docs:" line is dropped: it was repeating an address the reader already has. Where it does not — a pipe, a CI log, a terminal that would print the escape as junk — the line stays, because there it is the only way to reach the address at all. Three things the previous output got wrong, all visible in a two-failure run: The blank line closed the suggestion rather than the block, so "Docs:" was separated from the rule it belonged to and butted against the next one. It now closes the block. The name was printed as the config key, subject_min_length, while the rules reference titles its sections in kebab-case. Reading a name off the terminal and searching the documentation for it found nothing. Both now say subject-min-length. The advice for the two length rules named no length: "Provide a meaningful subject (>= configured min)", directly under an error that had already said "at least 5 characters". The suggestion is now templated on the same value as the error.
9817088 to
5a707e7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
commit_check/rule_builder.py (1)
245-249: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd regression coverage for suggestion formatting.
The current test uses a suggestion without placeholders. It does not verify
{max_len}or{min_len}substitution. Add a test for both length rules with a configured value.🤖 Prompt for 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. In `@commit_check/rule_builder.py` around lines 245 - 249, Add regression coverage around the suggestion formatting logic in the rule-builder tests, using configured suggestions containing both {max_len} and {min_len} placeholders for each length rule. Assert that the generated suggestions substitute the configured length value correctly.
🤖 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 `@commit_check/util.py`:
- Around line 322-323: Update the FORCE_HYPERLINK check in the
hyperlink-detection function to return True only when the environment value is
exactly "1", while preserving normal TTY behavior otherwise. Add a regression
test covering FORCE_HYPERLINK="0" with sys.stdout.isatty() returning False and
verify hyperlinks are not forced.
---
Nitpick comments:
In `@commit_check/rule_builder.py`:
- Around line 245-249: Add regression coverage around the suggestion formatting
logic in the rule-builder tests, using configured suggestions containing both
{max_len} and {min_len} placeholders for each length rule. Assert that the
generated suggestions substitute the configured length value correctly.
🪄 Autofix
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: aef7df59-3e58-487c-b501-efdf5498017b
📒 Files selected for processing (4)
commit_check/rule_builder.pycommit_check/rules_catalog.pycommit_check/util.pytests/util_test.py
| if os.environ.get("FORCE_HYPERLINK"): | ||
| return True |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Treat FORCE_HYPERLINK as an explicit boolean.
Line 322 enables hyperlinks for any nonempty value. FORCE_HYPERLINK=0 therefore emits OSC 8 sequences even for piped output. The PR contract specifies FORCE_HYPERLINK=1 as the forcing value.
Proposed fix
- if os.environ.get("FORCE_HYPERLINK"):
+ if os.environ.get("FORCE_HYPERLINK") == "1":
return TrueAdd a regression test with FORCE_HYPERLINK="0" and sys.stdout.isatty() set to False.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if os.environ.get("FORCE_HYPERLINK"): | |
| return True | |
| if os.environ.get("FORCE_HYPERLINK") == "1": | |
| return True |
🤖 Prompt for 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.
In `@commit_check/util.py` around lines 322 - 323, Update the FORCE_HYPERLINK
check in the hyperlink-detection function to return True only when the
environment value is exactly "1", while preserving normal TTY behavior
otherwise. Add a regression test covering FORCE_HYPERLINK="0" with
sys.stdout.isatty() returning False and verify hyperlinks are not forced.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #520 +/- ##
==========================================
+ Coverage 97.43% 97.48% +0.05%
==========================================
Files 12 12
Lines 1207 1231 +24
==========================================
+ Hits 1176 1200 +24
Misses 31 31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Any non-empty value counted as on, so FORCE_HYPERLINK=0 — the obvious way to ask for links to be turned off — turned them on instead. It now follows what FORCE_COLOR established and what ruff does: 0 disables even on a terminal that renders links, any other value enables. Also covers the length-rule substitution that had none. Removing the .format() call leaves the four new cases failing, so they hold the placeholder from reaching a user as a literal brace.
|
Merging this PR will degrade performance by 12.27%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|



The rule ID now carries an OSC 8 hyperlink to its section of the rules reference, so the ID itself is what you click — the same mechanism
ruffuses for its codes.Verified against
ruffrather than assumed: under a terminal it advertises support for, it emitsand prints no separate documentation line, which is why its output stays compact.
The URL still has to survive CI
commit-checkruns in a lot of placesruffdoes not, so dropping theDocs:line outright would lose the address wherever the escape cannot render. The line is kept unless the ID is actually a link:CC001is clickable, noDocs:lineCC001,Docs:line keptTERM=dumb, unknown terminalCC001,Docs:line keptFORCE_HYPERLINK=1All four were exercised against a real pty, not just unit-tested.
Three things the output got wrong
Visible in any two-failure run:
The blank line closed the suggestion, not the block.
Docs:ended up separated from the rule it belonged to and butted against the next one:The name was the config key, not the documented one. Output said
subject_min_length; the rules reference titles that sectionsubject-min-length. Reading a name off the terminal and searching the docs for it found nothing.RuleCatalogEntry.namealready existed for this and simply was not being used.The advice for the length rules named no length.
Suggest: Provide a meaningful subject (>= configured min)sat directly underSubject must be at least 5 characters— vaguer than the line above it. Both length suggestions are now templated on the same value as the error, so CC004 and CC005 name the actual limit.Before / after
Trailing whitespace on the failure and suggestion lines is gone as a side effect of the rewrite.
Testing
The failure is
test_load_config_file_permission_error, which usesos.chmod(0o000)and cannot fail as root; it reproduces onmain.TestHyperlinksadds 11 cases: the escape shape, terminal detection across nine environments including a malformedVTE_VERSION, that the ID is linked only when supported, that theDocs:line appears exactly when the ID is not a link, and that the blank line closes the block.Two existing assertions in
test_print_error_messagewere checking forauthor_emailin the output. They now assertauthor-emailand additionally that no underscore survives into the printed name, so the kebab-case contract is pinned rather than merely accommodated.Not in this PR
The banner says "Commit rejected by Commit-Check." and then "Commit rejected." on either side of the ASCII art, and there is still no summary count of failures. Both change the shape of the output rather than fix a defect in it, so they belong with the Action output rework on the roadmap.
Summary by CodeRabbit
Bug Fixes
Usability Improvements