Skip to content

Conversation

@2bndy5
Copy link
Collaborator

@2bndy5 2bndy5 commented Dec 23, 2025

Corresponds to cpp-linter/cpp-linter#173. This should never happen in the wild, but just in case there's an underlying problem with parsing clang-tidy output...

This fixes a problem about hyperlinking a clang-tidy diagnostic name to the clang-tidy docs.

Specifically when the diagnostic name does not satisfy the following conditions:

  • starts with "clang-analyzer-"
  • starts with "clang-diagnostic-"
  • contains at least 1 hyphen (-)

This also removes the .unwrap() calls (bad practice) and adds a test for code coverage.

Summary by CodeRabbit

  • Bug Fixes

    • Improved diagnostic-link generation so certain diagnostic identifiers are not turned into broken links and recognizable patterns produce correct external reference links.
    • Added validation to ensure links are only constructed when both parts are valid, reducing incorrect or misleading link rendering.
  • Tests

    • Added a test to confirm unrecognized diagnostic values are returned unchanged and do not produce invalid links.

✏️ Tip: You can customize this high-level summary in your review settings.

Corresponds to cpp-linter/cpp-linter#173. This should never happen in the wild, but just in case there's an underlying problem with parsing clang-tidy output...

This fixes a problem about hyperlinking a clang-tidy diagnostic name to the clang-tidy docs.

Specifically when the diagnostic name does not satisfy the following conditions:
- starts with "clang-analyzer-"
- starts with "clang-diagnostic-"
- contains at least 1 hyphen (`-`)

This also removes the `.unwrap()` calls (bad practice) and adds a test for code coverage.
@2bndy5 2bndy5 added the bug Something isn't working label Dec 23, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

Updates diagnostic_link in clang_tidy.rs to treat clang-diagnostic- prefixed diagnostics as non-documentable, unify handling for clang-analyzer- and other prefixes to derive category/name, build clang-tidy docs links when possible, and return original diagnostic unchanged when not recognized. Adds a unit test for the invalid case.

Changes

Cohort / File(s) Summary
Diagnostic link logic & test
cpp-linter/src/clang_tools/clang_tidy.rs
Modify diagnostic_link to: treat clang-diagnostic- as non-documentable and return as-is; unify extraction for clang-analyzer- and generic hyphen-split cases to produce (category,name); assert non-empty parts before constructing https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html links using original text as link text; fallback returns original string. Add invalid_diagnostic_link unit test ensuring unrecognized diagnostics remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: use diagnostic name by default' directly relates to the main change: modifying diagnostic_link behavior to return diagnostic names unchanged when they don't match expected patterns, instead of attempting to construct documentation links.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch diag-link-err

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d474f89 and 850dadb.

📒 Files selected for processing (1)
  • cpp-linter/src/clang_tools/clang_tidy.rs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-04T06:50:10.870Z
Learnt from: 2bndy5
Repo: cpp-linter/cpp-linter-rs PR: 208
File: cpp-linter/src/clang_tools/mod.rs:60-115
Timestamp: 2025-11-04T06:50:10.870Z
Learning: In the cpp-linter-rs project, path validation (such as checking whether a path is a file or directory) should be performed in CLI parsing (cpp-linter/src/cli/structs.rs) rather than in the tool lookup logic (cpp-linter/src/clang_tools/mod.rs). This maintains proper separation of concerns.

Applied to files:

  • cpp-linter/src/clang_tools/clang_tidy.rs
📚 Learning: 2025-01-21T09:56:32.771Z
Learnt from: 2bndy5
Repo: cpp-linter/cpp-linter-rs PR: 101
File: cpp-linter/src/clang_tools/clang_format.rs:155-161
Timestamp: 2025-01-21T09:56:32.771Z
Learning: In cpp-linter-rs, the XML output being parsed is generated programmatically by clang-format tool. The only failure case for XML parsing is when clang-format produces a blank XML document, in which case falling back to empty results (using unwrap_or) is the desired behavior.

Applied to files:

  • cpp-linter/src/clang_tools/clang_tidy.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: Build current binary
  • GitHub Check: x86_64-pc-windows-msvc
  • GitHub Check: aarch64-unknown-linux-gnu
  • GitHub Check: powerpc-unknown-linux-gnu
  • GitHub Check: aarch64-pc-windows-msvc
  • GitHub Check: arm-unknown-linux-gnueabihf
  • GitHub Check: s390x-unknown-linux-gnu
  • GitHub Check: Build x86_64-unknown-linux-musl
  • GitHub Check: Build aarch64-pc-windows-msvc
  • GitHub Check: Build aarch64-unknown-linux-musl
  • GitHub Check: Build aarch64-unknown-linux-gnu
  • GitHub Check: Build armv7-unknown-linux-gnueabihf
  • GitHub Check: Build x86_64-apple-darwin
  • GitHub Check: Build i686-pc-windows-msvc
  • GitHub Check: Build x86_64-unknown-linux-gnu
  • GitHub Check: test (windows-latest)
  • GitHub Check: Build x86_64-pc-windows-msvc
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: Build FreeBSD
🔇 Additional comments (3)
cpp-linter/src/clang_tools/clang_tidy.rs (3)

77-81: LGTM! Correct handling of compiler diagnostics.

Returning clang-diagnostic-* diagnostics as-is is appropriate since these are compiler diagnostics without dedicated clang-tidy documentation pages.


402-416: LGTM! Good test coverage for the edge case.

This test validates that unrecognized diagnostic names (without hyphens) are returned unchanged, which aligns with the PR objectives to avoid panics when diagnostic names don't meet expected patterns.


82-98: URL format verification complete.

The clang-tidy documentation URL format in the code is correct. The pattern https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html properly handles both standard diagnostics and clang-analyzer checks. Dots in diagnostic names (e.g., core.NullDereference) are preserved in the URL and correctly map to existing documentation pages.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
cpp-linter/src/clang_tools/clang_tidy.rs (1)

77-79: Consider adding a clarifying comment for the special case.

The early return for "clang-diagnostic-*" diagnostics is correct, but it would help future maintainers to understand why these diagnostics are treated differently (i.e., they don't have dedicated documentation pages).

🔎 Suggested comment addition
 pub fn diagnostic_link(&self) -> String {
+    // clang-diagnostic-* diagnostics are compiler diagnostics and don't have
+    // dedicated clang-tidy documentation pages, so return the name as-is.
     if self.diagnostic.starts_with("clang-diagnostic-") {
         return self.diagnostic.clone();
     }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4575ec and d474f89.

📒 Files selected for processing (1)
  • cpp-linter/src/clang_tools/clang_tidy.rs
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: 2bndy5
Repo: cpp-linter/cpp-linter-rs PR: 208
File: cpp-linter/src/clang_tools/mod.rs:60-115
Timestamp: 2025-11-04T06:50:10.870Z
Learning: In the cpp-linter-rs project, path validation (such as checking whether a path is a file or directory) should be performed in CLI parsing (cpp-linter/src/cli/structs.rs) rather than in the tool lookup logic (cpp-linter/src/clang_tools/mod.rs). This maintains proper separation of concerns.
📚 Learning: 2025-11-04T06:50:10.870Z
Learnt from: 2bndy5
Repo: cpp-linter/cpp-linter-rs PR: 208
File: cpp-linter/src/clang_tools/mod.rs:60-115
Timestamp: 2025-11-04T06:50:10.870Z
Learning: In the cpp-linter-rs project, path validation (such as checking whether a path is a file or directory) should be performed in CLI parsing (cpp-linter/src/cli/structs.rs) rather than in the tool lookup logic (cpp-linter/src/clang_tools/mod.rs). This maintains proper separation of concerns.

Applied to files:

  • cpp-linter/src/clang_tools/clang_tidy.rs
📚 Learning: 2025-01-21T09:56:32.771Z
Learnt from: 2bndy5
Repo: cpp-linter/cpp-linter-rs PR: 101
File: cpp-linter/src/clang_tools/clang_format.rs:155-161
Timestamp: 2025-01-21T09:56:32.771Z
Learning: In cpp-linter-rs, the XML output being parsed is generated programmatically by clang-format tool. The only failure case for XML parsing is when clang-format produces a blank XML document, in which case falling back to empty results (using unwrap_or) is the desired behavior.

Applied to files:

  • cpp-linter/src/clang_tools/clang_tidy.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: build-mkdocs
  • GitHub Check: Build x86_64-unknown-linux-gnu
  • GitHub Check: Build i686-pc-windows-msvc
  • GitHub Check: Build armv7-unknown-linux-gnueabihf
  • GitHub Check: Build aarch64-apple-darwin
  • GitHub Check: Build aarch64-unknown-linux-gnu
  • GitHub Check: Build x86_64-unknown-linux-musl
  • GitHub Check: Build aarch64-unknown-linux-musl
  • GitHub Check: Build aarch64-pc-windows-msvc
  • GitHub Check: arm-unknown-linux-gnueabihf
  • GitHub Check: Build x86_64-pc-windows-msvc
  • GitHub Check: s390x-unknown-linux-gnu
  • GitHub Check: powerpc64-unknown-linux-gnu
  • GitHub Check: armv7-unknown-linux-gnueabihf
  • GitHub Check: powerpc-unknown-linux-gnu
  • GitHub Check: aarch64-unknown-linux-gnu
  • GitHub Check: Build FreeBSD
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: Build current binary
  • GitHub Check: test (windows-latest)
🔇 Additional comments (2)
cpp-linter/src/clang_tools/clang_tidy.rs (2)

400-414: LGTM! Test validates the fallback behavior.

The test correctly verifies that diagnostics without recognized patterns (no hyphen, not starting with "clang-analyzer-" or "clang-diagnostic-") return the diagnostic name as-is. Combined with existing tests, this provides good coverage of the diagnostic_link logic.


80-96: The refactored logic correctly handles all diagnostic patterns and generates valid documentation links.

The implementation properly:

  • Extracts category and name for "clang-analyzer-*" diagnostics by stripping the prefix
  • Splits other diagnostics on the first hyphen for link construction
  • Falls back to returning the diagnostic name when no pattern matches

The URL format https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html matches the actual clang-tidy documentation structure. The debug_assert! is acceptable given that clang-tidy doesn't produce diagnostics with empty categories or names.

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.88%. Comparing base (a4575ec) to head (850dadb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #236      +/-   ##
==========================================
- Coverage   96.93%   96.88%   -0.06%     
==========================================
  Files          14       14              
  Lines        3033     3048      +15     
==========================================
+ Hits         2940     2953      +13     
- Misses         93       95       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants