Skip to content

fix: make --dry-run correctly report formatting issues#257

Merged
shenxianpeng merged 1 commit into
mainfrom
bugfix/dry-run-return-code
Jul 19, 2026
Merged

fix: make --dry-run correctly report formatting issues#257
shenxianpeng merged 1 commit into
mainfrom
bugfix/dry-run-return-code

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

Problem: --dry-run mode always returned 0, never blocking commits even when clang-format detected unformatted files. This was caused by:

  1. run_clang_format() replacing the actual exit code with -1
  2. main() converting -1 back to 0

This contradicted user intuition (dry-run should fail if formatting needs fixing) and differed from mirrors-clang-format's behavior.

Fix:

  • Remove the special -1 code path entirely
  • Auto-inject --Werror when --dry-run is present, so clang-format returns non-zero when formatting changes are needed (mirrors-clang- format behavior)
  • Pass through the real exit code from clang-format

Tests updated: dry-run on unformatted file expects 1, on formatted file expects 0.

Summary

Related Issues

Problem: --dry-run mode always returned 0, never blocking commits even
when clang-format detected unformatted files. This was caused by:
1. run_clang_format() replacing the actual exit code with -1
2. main() converting -1 back to 0

This contradicted user intuition (dry-run should fail if formatting
needs fixing) and differed from mirrors-clang-format's behavior.

Fix:
- Remove the special -1 code path entirely
- Auto-inject --Werror when --dry-run is present, so clang-format
  returns non-zero when formatting changes are needed (mirrors-clang-
  format behavior)
- Pass through the real exit code from clang-format

Tests updated: dry-run on unformatted file expects 1, on formatted
file expects 0.
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@shenxianpeng, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6247d33c-306f-4dc2-a742-88b40c9821cf

📥 Commits

Reviewing files that changed from the base of the PR and between 21f53f4 and 1206023.

📒 Files selected for processing (2)
  • cpp_linter_hooks/clang_format.py
  • tests/test_clang_format.py

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.

@shenxianpeng shenxianpeng changed the title fix(clang-format): make --dry-run correctly report formatting issues fix: make --dry-run correctly report formatting issues Jul 19, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions github-actions Bot added the bug Something isn't working label Jul 19, 2026
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.51%. Comparing base (21f53f4) to head (1206023).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #257   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files           3        3           
  Lines         241      241           
=======================================
  Hits          235      235           
  Misses          6        6           

☔ 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.

@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 90 untouched benchmarks
🆕 2 new benchmarks
⏩ 54 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_run_clang_format_dry_run_formatted N/A 840.3 µs N/A
🆕 test_run_clang_format_dry_run_unformatted N/A 891.1 µs N/A

Comparing bugfix/dry-run-return-code (1206023) with main (12c3973)2

Open in CodSpeed

Footnotes

  1. 54 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.

  2. No successful run was found on main (21f53f4) during the generation of this report, so 12c3973 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@shenxianpeng
shenxianpeng merged commit 0ca532e into main Jul 19, 2026
31 checks passed
@shenxianpeng
shenxianpeng deleted the bugfix/dry-run-return-code branch July 19, 2026 17:36
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.

1 participant