Skip to content

feat: merge review suggestions from both clang tools#358

Merged
2bndy5 merged 2 commits into
mainfrom
join-tools-reviews
Jun 18, 2026
Merged

feat: merge review suggestions from both clang tools#358
2bndy5 merged 2 commits into
mainfrom
join-tools-reviews

Conversation

@2bndy5

@2bndy5 2bndy5 commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

This is a culmination of

As this builds on the plan discussed in cpp-linter/cpp-linter#82, it it the last step needed before providing a patch that consumers can push to auto-fix lints.

Intended flow of data

  1. run clang-tidy before running clang-format
  2. after running clang-tidy save the patched file to cache
  3. after running clang-format:
    • check for clang-tidy patch in cache.
    • if cached patch is present, run clang-format on the clang-tidy patch. This step includes formatting lines that clang-tidy changed and lines that clang-format changed.
    • if cached patch is not present (clang-tidy was not run on the file), then cache the clang-format fixes instead.
    • --lines-changed-only is respected, but this may need tweaking in the future.
  4. when creating a PR review,
    • only add hunks to the patch that are not present in the review comments.
    • I added a parameter to also calculate (and display) how many review comments were reused in previous PR reviews.
    • PR review summaries are worded better if the env var CPP_LINTER_PR_REVIEW_SUMMARY_ONLY = 1. If PR review is a summary only, then the patch will include all fixes that would have been posted in the diff.

Adjusted tests accordingly.

Summary by CodeRabbit

  • Bug Fixes

    • Improved formatting/tidy patch handling to generate more accurate review diffs and line-range suggestions.
    • Refined how review summaries are produced (including “summary-only” behavior and reused-review messaging).
    • Improved review comment metadata when line ranges are identical.
  • Tests

    • Expanded diff and three-way diff coverage.
    • Updated review-body expectation logic to match the new summary rules.
  • Chores

    • Updated documentation dependency.
    • Refined caching and output processing for more reliable review generation.

@2bndy5 2bndy5 added the enhancement New feature or request label Jun 14, 2026
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.96573% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.35%. Comparing base (badba09) to head (aa76d57).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cpp-linter/src/clang_tools/clang_format.rs 84.00% 20 Missing ⚠️
cpp-linter/src/common_fs.rs 89.65% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #358      +/-   ##
==========================================
- Coverage   92.81%   92.35%   -0.46%     
==========================================
  Files          23       23              
  Lines        3450     3597     +147     
==========================================
+ Hits         3202     3322     +120     
- Misses        248      275      +27     

☔ View full report in Codecov by Harness.
📢 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.

@2bndy5 2bndy5 force-pushed the join-tools-reviews branch 3 times, most recently from b5e7407 to e48fbfc Compare June 16, 2026 00:01
This is a culmination of
- #354
- #347

It it the last step needed before providing a patch that consumers can push to auto-fix lints.

# Intended flow of data
1. run clang-tidy before running clang-format
2. after running clang-tidy save the patched file to cache
3. after running clang-format:
    - check for clang-tidy patch in cache.
    - if cached patch is present, run clang-format on the clang-tidy patch. This step includes formatting lines that clang-tidy changed and lines that clang-format changed.
    - if cached patch is not present (clang-tidy was not run on the file), then cache the clang-format fixes instead.
    - `--lines-changed-only` is respected, but this may need tweaking in the future.
4. when creating a PR review, only add hunks that are not present in the review comments. I added a parameter to also calculate (and display) how many review comments were reused in previous PR reviews. If PR review is a summary only, then the patch will include all fixes that would have been posted in the diff.

Adjusted tests accordingly.
@2bndy5 2bndy5 force-pushed the join-tools-reviews branch from dd4c541 to 9254f94 Compare June 16, 2026 01:16
@2bndy5 2bndy5 marked this pull request as ready for review June 16, 2026 02:23
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 66641de2-4d83-4a6c-87d6-d0a7a1a6c94a

📥 Commits

Reviewing files that changed from the base of the PR and between 9254f94 and aa76d57.

📒 Files selected for processing (2)
  • cpp-linter/src/clang_tools/clang_format.rs
  • cpp-linter/src/common_fs.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • cpp-linter/src/clang_tools/clang_format.rs
  • cpp-linter/src/common_fs.rs

📝 Walkthrough

Walkthrough

The PR refactors the clang tool pipeline to consolidate cached patched-file ownership into a new FileObj.patched_path field, removing per-tool patched: PathBuf fields from TidyAdvice and FormatAdvice, and deleting the MakeSuggestions trait. ReviewComments aggregation fields are unified to single tool_total/full_patch values, and the summarize signature gains total_review_comments and summary_only parameters. A new get_suggestions helper drives hunk-by-hunk suggestion generation. mkdocs-material is bumped to 9.7.6.

Changes

Unified patched_path & ReviewComments refactor

Layer / File(s) Summary
ClangParams cache path infrastructure
cpp-linter/src/cli/structs.rs, cpp-linter/src/run.rs
Adds CACHE_DIR constant and get_cache_path() method to ClangParams; updates run.rs to use ClangParams::CACHE_DIR instead of the now-removed clang_tools::CACHE_DIR.
FileObj.patched_path, DisplayStringFailed error, and get_suggestions helper
cpp-linter/src/error.rs, cpp-linter/src/common_fs.rs
Extends FileObj with patched_path: Option<PathBuf>, adds the DisplayStringFailed error variant, restructures make_suggestions_from_patch to load from patched_path, handles summary_only mode to skip line-range suggestions when appropriate, aggregates clang-tidy diagnostics, and introduces the get_suggestions helper that iterates diff hunks and accumulates full_patch/tool_total.
clang-tidy: remove patched field, store path on FileObj
cpp-linter/src/clang_tools/clang_tidy.rs
Removes patched: PathBuf from TidyAdvice, drops MakeSuggestions for TidyAdvice, adds the inherent get_suggestion_help method, changes cache path construction to get_cache_path(), and stores the result in file.patched_path. Updates test setup to pre-create the cache directory.
clang-format: remove patched field, branch on file.patched_path
cpp-linter/src/clang_tools/clang_format.rs
Removes patched: PathBuf from FormatAdvice and MakeSuggestions for FormatAdvice. run_clang_format uses get_cache_path() and make_patch, then branches: runs clang-format -i in-place when file.patched_path exists (prior clang-tidy output), otherwise writes stdout to a new cache path and sets file.patched_path. Adds three_way_diff tests.
ReviewComments model, trait removal, analyze_single_file, and summarize
cpp-linter/src/clang_tools/mod.rs
Removes CACHE_DIR constant and MakeSuggestions trait, reorders analyze_single_file to run clang-tidy before clang-format, fixes Suggestion::as_review_comment line_start edge case, simplifies ReviewComments to single tool_total/full_patch, rewrites summarize with total_review_comments/summary_only params, and adds summarize_reused_reviews unit test.
post_feedback and integration test updates
cpp-linter/src/rest_client.rs, cpp-linter/tests/reviews.rs
Updates post_feedback to compute total_review_comments, derive has_changes from unified tool_total, and call summarize with the expanded signature. Removes patched fields from test fixtures. Updates integration tests to replace per-tool summary helpers with an inline conditional tool_summary regex.

Docs dependency bump

Layer / File(s) Summary
mkdocs-material version bump
docs/pyproject.toml
Bumps mkdocs-material from 9.7.1 to 9.7.6.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • cpp-linter/cpp-linter-rs#347: Modifies the same run_clang_format caching/diff workflow and FormatAdvice structure that this PR further refactors.
  • cpp-linter/cpp-linter-rs#354: Directly connected at the clang_tidy.rs level — refactors TidyAdvice's cached patched path and wires it into patch/suggestion generation, the exact pattern this PR completes.
  • cpp-linter/cpp-linter-rs#349: Changes how working/cache directories are rooted in --repo-root across clang_format.rs and clang_tidy.rs, which is directly related to this PR's get_cache_path() consolidation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: merge review suggestions from both clang tools' accurately and concisely describes the main objective of merging suggestions from both clang-tidy and clang-format tools, which is the core focus of this changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@cpp-linter/src/clang_tools/clang_format.rs`:
- Around line 154-185: The joint_ranges are built using hunk.before which
contains original-file line coordinates, but the code is formatting the cached
tidy-patched file where line numbers have shifted due to tidy
insertions/deletions. Replace hunk.before with hunk.after in the map function
that builds joint_ranges to use the correct patched-file coordinates.
Additionally, translate any non-overlapping original ranges from the ranges
parameter before adding them to joint_ranges, since they also refer to
original-file coordinates and must be converted to patched-file coordinates
before being passed as --lines arguments to clang-format.

In `@cpp-linter/src/common_fs.rs`:
- Around line 261-263: The UnifiedDiffPrinter's display_hunk() method requires
that display_header() be called first to emit the hunk header line (the @@ -a,b
+c,d @@ syntax). Locate where display_hunk() is being called on the
BasicLineDiffPrinter instance and ensure that display_header() is invoked on the
printer before any display_hunk() calls to generate valid unified diff output
that can be applied as a patch.

In `@cpp-linter/src/rest_client.rs`:
- Around line 218-233: In summary-only mode, clang-tidy diagnostics without
fixes are not being added to review_comments before the decision logic runs,
causing review_comments.tool_total to be zero and allowing invalid PR approvals.
Before the block that determines options.action and options.summary (which uses
has_changes derived from review_comments.tool_total), ensure that no-fix
clang-tidy diagnostics are included in the review_comments concern count in
summary-only mode. This likely requires modifying make_suggestions_from_patch or
the code that populates review_comments to include no-fix diagnostics in the
tool_total count even when summary_only is true, so the action and summary
decisions reflect all tidy warnings.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 94621f1a-8c9c-4e79-9abb-b55f70c74f3d

📥 Commits

Reviewing files that changed from the base of the PR and between d45a232 and 9254f94.

📒 Files selected for processing (10)
  • cpp-linter/src/clang_tools/clang_format.rs
  • cpp-linter/src/clang_tools/clang_tidy.rs
  • cpp-linter/src/clang_tools/mod.rs
  • cpp-linter/src/cli/structs.rs
  • cpp-linter/src/common_fs.rs
  • cpp-linter/src/error.rs
  • cpp-linter/src/rest_client.rs
  • cpp-linter/src/run.rs
  • cpp-linter/tests/reviews.rs
  • docs/pyproject.toml

Comment thread cpp-linter/src/clang_tools/clang_format.rs
Comment thread cpp-linter/src/common_fs.rs
Comment thread cpp-linter/src/rest_client.rs
and some other review changes
@2bndy5 2bndy5 merged commit edd66db into main Jun 18, 2026
73 checks passed
@2bndy5 2bndy5 deleted the join-tools-reviews branch June 18, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant