Skip to content

fix: shift changed lines past clang-tidy fixes above them - #491

Merged
2bndy5 merged 1 commit into
mainfrom
claude/rs-test-coverage-7cgkd7
Oct 15, 2026
Merged

2bndy5 merged 1 commit into
mainfrom
claude/rs-test-coverage-7cgkd7

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Before: when clang-tidy fixes and clang-format both run, and a clang-tidy fix adds or removes lines entirely above a changed line range, the range given to clang-format keeps its old line numbers. With lines-changed-only, format advice is then filtered against the wrong lines.

After: the changed range is shifted by the lines that fix added or removed, so clang-format checks the lines that actually changed.

This came out of a coverage pass on main after #488. The "tidy hunk is before the og range" branch of three_way_diff() was the only uncovered code in clang_format.rs, and its first test failed: for an original range 5..=6 with a fix that turns line 2 into two lines, it returned [2..=3, 5..=6] instead of [2..=3, 6..=7].

How: that branch updated line_shift but never recomputed merged_start/merged_end, which are set once before the loop. It now recomputes them after shifting, the same way the "contained within" branch recomputes merged_end. The new test three_way_diff_tidy_hunk_before_range covers it.

Coverage notes, for context (local Linux run, nothing else changed here): clang_format.rs now has no uncovered lines. The other uncovered lines on main are platform-only branches (Windows/macOS/arm64), error arms that can't fail (writing to a String), and the other-file branch in clang_tidy/mod.rs that #489/#490 will rewrite, so it is left alone.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: db275f35-f321-4b57-924a-bc8d4bbd3d1e
📥 Commits

Reviewing files that changed from the base of the PR and between db106b5 and af4ab25.

📒 Files selected for processing: 1
  • cpp-linter/src/clang_tools/clang_format.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

When a clang-tidy fix lands entirely above a changed line range,
`three_way_diff()` added the fix's line delta to `line_shift` but kept
the range's start and end computed before the loop. The range passed to
clang-format then pointed at the old line numbers, so format advice was
filtered against the wrong lines in `lines-changed-only` mode.

Add a test for that case, which also covers the last uncovered lines in
clang_format.rs.
@shenxianpeng
shenxianpeng force-pushed the claude/rs-test-coverage-7cgkd7 branch from f1ebcf0 to af4ab25 Compare October 15, 2026 19:31
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (db106b5) to head (af4ab25).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #491      +/-   ##
==========================================
+ Coverage   99.18%   99.25%   +0.07%     
==========================================
  Files          26       26              
  Lines        5653     5664      +11     
==========================================
+ Hits         5607     5622      +15     
+ Misses         46       42       -4     

☔ 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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch! I'll pay closer attention to indirect coverage changes from now on.

BTW, I'm glad to get a second pair of eyes on that 3-way-diff function. My dreams turned into chains of boolean decisions when I was writing, reviewing, rewriting, and re-reviewing that patch.

@2bndy5
2bndy5 merged commit aca88b5 into main Oct 15, 2026
77 checks passed
@2bndy5
2bndy5 deleted the claude/rs-test-coverage-7cgkd7 branch October 15, 2026 20:31
2bndy5 pushed a commit that referenced this pull request Oct 15, 2026
<!-- claude-projects-attribution: {"github_login":"shenxianpeng"} -->

Before: compared with the Python cpp-linter (v1), v2 shows clang-tidy
annotations on the whole file instead of the line, posts an approving PR
review even with `--no-lgtm` (the default), posts a new review when
every suggestion was already posted, lists files in a random order, lets
one failed check pass under `PRE_COMMIT=1`, and rejects or mishandles a
few inputs v1 accepts (`-e ".cpp, .h"`, `--extra-arg` with double
spaces, `-v 10`, `CPP_LINTER_PR_REVIEW_SUMMARY_ONLY=True`, meson-style
relative paths in clang-tidy output).

After: v2 behaves like v1 in those places. Intentional v2 changes
(`--pr-review`, parallel by default, SARIF, the fix patch, #488's header
fix) are untouched.

I compared both CLIs, defaults, env vars, file filtering and every
feedback path (annotations, step summary, thread comment, PR review,
outputs, exit code). This PR only fixes the clear gaps. Differences that
look deliberate or need a maintainer's call (for example
`lines-changed-only` defaulting to `true`, the swapped `-t`/`-g` short
flags, no `--jobs`/`--fix`) are left out and listed in a separate report
for @2bndy5 to weigh in on.

## Changes

- **Annotations**: clang-tidy annotations set
`start_line`/`start_column`. Before, only `end_line`/`end_column` were
set, and git-bot-feedback only writes `line=` from `start_line`, so the
annotation had no line. The title also names the check, as in v1.
- **`--no-lgtm` for PR reviews**: restored the check lost in the
git-bot-feedback migration (d1e2136). Outdated reviews are still culled;
only the approving review is skipped.
- **Reused review comments**: when every review comment was already
posted in a previous review, no new review is posted (v1.15
`rest_api.py` L468-473).
- **Stable file order**: the file lists from git-bot-feedback
(`HashMap`/`HashSet`) are sorted, as v1 does.
- **`PRE_COMMIT=1`**: `checks_failed > 1` → `> 0`.
- **`--extensions`**: trims whitespace and a leading `.`; empty values
are still an error.
- **`--extra-arg`**: splits on any whitespace and drops empty values, so
clang-tidy never gets `--extra-arg=`.
- **`--verbosity`**: accepts `10` (debug) and `20` (info), like v1.
- **`CPP_LINTER_PR_REVIEW_SUMMARY_ONLY`**: compared case-insensitively.
- **Compilation database paths**: a clang-tidy path that equals a unit's
`file` (relative to its `directory`, as meson writes it) now resolves
through that unit, like v1.
- **Review diagnostics**: unfixed clang-tidy diagnostics about another
file (eg. a header) are no longer posted on the analyzed file's lines
(v1 has this bug too).
- **Local runs**: warn when `--pr-review` is set outside CI, like v1.
- **Thread comment**: `clang-tidy (vX) reports: <strong>N
concern(s)</strong>`, matching the clang-format line.
- **`--style` help**: no longer says the style is passed to clang-tidy
(it isn't since #488).

Nothing here touches `clang_format.rs` (#491) or the fix-application
code planned for #489/#490.

## How

Each fix has a test. The `no_lgtm` review test now asserts no review is
POSTed, and it and `summary_only` (now using `True`) fail on `main` and
pass here. The new `all_suggestions_reused` test runs a review once,
feeds its comments back as existing review threads, and asserts the
second run posts nothing and keeps the old review; it fails without the
fix. `cargo clippy --all-features --all-targets` is clean and `cargo
nextest run --all-features -p cpp-linter` passes locally (124 tests,
clang 18).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved clang-tidy diagnostic matching for compilation database paths
and excluded diagnostics for other files from suggestions.
* Tidy review annotations now point to the diagnostic’s location and
include clearer titles and summaries.
* Pre-commit runs now fail when any check fails, and file feedback
appears in a consistent order.
* **Review Improvements**
* Avoided posting duplicate review comments and LGTM reviews when LGTM
is disabled.
* Added a warning when pull-request reviews are requested outside a
supported CI environment.
* **CLI Improvements**
* Normalized extension and extra-argument input, and accepted additional
verbosity and mixed-case summary-only values.
* Clarified that the clang-format style also applies to clang-tidy
suggestions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants