fix: make --dry-run correctly report formatting issues - #257
Conversation
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.
|
Warning Review limit reached
Next review available in: 46 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. 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: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
## Why cpp-linter-hooks already gets more Google traffic than the action (52 of its 288 repository views in the last 14 days came from Google, against 21 for cpp-linter-action), so people are searching for "clang-format pre-commit hook". The site has no page for that query. This is the second how-to written around a search term, after #62; the two PRs are independent. ## What's in this PR One new post in the Guides category: **Set up a clang-format pre-commit hook for C and C++** (`docs/blog/posts/2026-09-20-clang-format-pre-commit-hook.md`), published at `/blog/2026/09/20/clang-format-pre-commit-hook/` (explicit `slug`, plus a meta `description`). 1. A starter `.clang-format`. 2. Installing pre-commit and adding the hook; `rev` is the hook version, `--version` is the clang-format version (`21` resolves to the newest 21.x wheel, a full version pins it exactly). 3. What the first commit looks like, and why "Failed" means the files were fixed. 4. Formatting only your own code: `exclude`, a `DisableFormat` `.clang-format` in the vendored directory, and `types_or` for CUDA and Protobuf. 5. Existing code bases: reformat once with `.git-blame-ignore-revs`, or format as you go; `git clang-format` mentioned for changed-lines-only. 6. Enforcing the same configuration in CI with `pre-commit run --all-files --show-diff-on-failure`, or review suggestions from cpp-linter-action with `format-review`. 7. A troubleshooting table. 8. When to add the clang-tidy hook. ## Checks - Every command and output in the post was run in a scratch git repository with `rev: v1.6.0` and `--version=21` (resolved to clang-format 21.1.8): the blocked commit and the retry, `exclude`, the per-directory `DisableFormat`, `.cu` and `.proto` formatting via `types_or`, `SKIP=clang-format`, the CI output (pasted verbatim) and `blame.ignoreRevsFile`. - The compile database auto-detection mentioned in the last section was checked against `clang_tidy.py` at v1.6.0. - `mkdocs build --strict` passes locally, and the repository's pre-commit hooks pass on the new file. ## Notes - The post does not recommend `--dry-run`. With the released v1.6.0 the hook reports "Passed" for an unformatted file when `--dry-run` is set, with or without `--Werror`; the fix (cpp-linter/cpp-linter-hooks#257) is on `main` but not in a release yet. Once it is released, a check-only variant can be added to step 6. - There is no link to the clang-tidy guide from #62, because that page does not exist on `main` yet and the strict build would fail. The two posts can be cross-linked in a small follow-up once both are merged.



Problem: --dry-run mode always returned 0, never blocking commits even when clang-format detected unformatted files. This was caused by:
This contradicted user intuition (dry-run should fail if formatting needs fixing) and differed from mirrors-clang-format's behavior.
Fix:
Tests updated: dry-run on unformatted file expects 1, on formatted file expects 0.
Summary
Related Issues