Skip to content

docs: add guide on setting up a clang-format pre-commit hook - #63

Open
shenxianpeng wants to merge 2 commits into
mainfrom
docs/howto-clang-format-pre-commit
Open

shenxianpeng wants to merge 2 commits into
mainfrom
docs/howto-clang-format-pre-commit

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

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

@netlify

netlify Bot commented Sep 19, 2026

Copy link
Copy Markdown

Deploy Preview for cpp-linter-github-io ready!

Name Link
🔨 Latest commit a87af6e
🔍 Latest deploy log https://app.netlify.com/projects/cpp-linter-github-io/deploys/6aaefe0ddd098e00086695b3
😎 Deploy Preview https://deploy-preview-63--cpp-linter-github-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

1 participant