docs: add guide on running clang-tidy on pull requests with GitHub Actions - #62
Conversation
✅ Deploy Preview for cpp-linter-github-io ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
## 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.
41251fc to
1606c22
Compare
|
It would be nice to also have some explanation about using third-party libs with clang-tidy because it often requires a compilation database to inform clang-tidy the |
IIRC, the private repo support was dependent on the getting raw MD text in comments via HTTP response's JSON. I thought we fixed that by adding But recently, we had a user report failures to post thread comments on a private repo. I guess we could do a test run on a private repo in the cpp-linter org (or in a individual account's private repo). |
Why
People search for "clang-tidy github actions" and "clang-tidy pull request comments", and for those queries platisd/clang-tidy-pr-comments and ZedThree/clang-tidy-review rank ahead of cpp-linter-action. The site has no page that answers that question from start to finish; the two existing posts assume the reader already has a lint workflow. This is the first of a few how-to posts written around what people actually search for.
What's in this PR
One new post in the Guides category: Run clang-tidy on pull requests with GitHub Actions (
docs/blog/posts/2026-09-20-clang-tidy-pull-requests-github-actions.md), published at/blog/2026/09/20/clang-tidy-github-actions-pull-requests/(explicitslug, plus a metadescription).It follows the places where people get stuck:
.clang-tidy(bugprone-*,performance-*,clang-analyzer-*, explicitHeaderFilterRegex).compile_commands.jsonwith CMake, Meson, Make + Bear, orextra-argswhen there is no build system.files-changed-only/lines-changed-onlyand what each value reports.clang-tidy-checks-failedoutput, and rolling that out gradually.pull_request_target.Two details worth a look from someone who knows the action well:
tidy-checksvalue is appended to theChecksin.clang-tidy, and recommendstidy-checks: ''. That is taken from the input description inaction.yml.HeaderFilterRegexmatches. That is from the LLVM 22 release notes, and is the reason the starter config setsHeaderFilterRegexexplicitly.I left out the note about thread comments being disabled on private repositories, because I could not find the matching behaviour in the cpp-linter source.
Checks
action.ymlat v2.22.0,docs/permissions.mdanddocs/pr-review-caveats.md; the hook arguments against the cpp-linter-hooks README..clang-tidywas run with clang-tidy 22.1.0 on a small demo project:--verify-configreports no errors, a finding ininclude/is reported and the same finding inthird_party/is filtered out.mkdocs build --strictpasses locally, and the repository's pre-commit hooks pass on the new file.format-revieware gone, clang-format is off (style: ''),step-summaryis on, and the fail step usesclang-tidy-checks-failed.