Skip to content

Commit 0569232

Browse files
authored
docs: add "Why cpp-linter?", showcase and the first blog posts (#60)
1 parent 2e2e9e1 commit 0569232

9 files changed

Lines changed: 593 additions & 44 deletions

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ This repository hosts the public site at <https://cpp-linter.github.io/>, includ
1818

1919
- Project overview and landing page content
2020
- Getting started documentation
21+
- "Why cpp-linter?": how the toolchain compares with other clang-format / clang-tidy actions and hooks
22+
- Showcase of open-source projects that use cpp-linter
23+
- Blog posts and guides
2124
- Clang tools distribution guides (static binaries, Docker images, Python wheels)
2225
- Discussion and community entry points
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
date:
3+
created: 2026-09-12
4+
categories:
5+
- Guides
6+
tags:
7+
- cpp-linter-action
8+
- clang-format
9+
- clang-tidy
10+
- migration
11+
authors:
12+
- shenxianpeng
13+
---
14+
15+
# Moving to cpp-linter from other clang-format and clang-tidy actions
16+
17+
A common C++ workflow on GitHub has two lint jobs that grew up separately: a format check that
18+
fails the build, and a clang-tidy job that posts review comments. They pin different clang
19+
versions, they run on different triggers, and when one of them starts flaking nobody remembers why
20+
it was configured that way. Both jobs can be one cpp-linter-action step.
21+
22+
<!-- more -->
23+
24+
## The starting point
25+
26+
Two jobs, two actions, two versions of clang:
27+
28+
```yaml title=".github/workflows/lint.yml (before)"
29+
jobs:
30+
format:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v5
34+
- uses: jidicula/clang-format-action@v4.18.0
35+
with:
36+
clang-format-version: '17'
37+
check-path: 'src'
38+
39+
tidy:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v5
43+
- run: cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
44+
- uses: ZedThree/clang-tidy-review@v0.23.1
45+
with:
46+
clang_tidy_version: '21'
47+
build_dir: build
48+
config_file: .clang-tidy
49+
- uses: ZedThree/clang-tidy-review/upload@v0.23.1
50+
```
51+
52+
The format job fails with a diff in the log; the tidy job builds a Docker image, runs, uploads an
53+
artifact, and a second workflow posts the review. Contributors see a red check for formatting and a
54+
review for clang-tidy, and still fix the formatting by hand.
55+
56+
## The replacement
57+
58+
```yaml title=".github/workflows/lint.yml (after)"
59+
name: cpp-linter
60+
on:
61+
pull_request:
62+
branches: [main]
63+
push:
64+
branches: [main]
65+
66+
jobs:
67+
cpp-linter:
68+
runs-on: ubuntu-latest
69+
permissions:
70+
contents: read
71+
pull-requests: write
72+
steps:
73+
- uses: actions/checkout@v5
74+
- run: cmake -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
75+
- uses: cpp-linter/cpp-linter-action@v2
76+
id: linter
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
with:
80+
version: '21'
81+
style: file
82+
tidy-checks: ''
83+
database: build
84+
lines-changed-only: true
85+
format-review: true
86+
tidy-review: true
87+
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
88+
- name: Fail on lint errors
89+
if: steps.linter.outputs.checks-failed > 0
90+
run: exit 1
91+
```
92+
93+
What each input replaces:
94+
95+
| Before | After | Notes |
96+
| --- | --- | --- |
97+
| `clang-format-version: '17'` and `clang_tidy_version: '21'` | `version: '21'` | One LLVM major for both tools. Reformat the tree once when you unify. |
98+
| `check-path: 'src'` | default `files-changed-only: true` | Only files touched by the pull request are checked. Use `ignore` to exclude directories. |
99+
| `config_file: .clang-tidy` | `tidy-checks: ''` | Empty means "use `.clang-tidy`". `style: file` does the same for `.clang-format`. |
100+
| `build_dir: build` | `database: build` | Directory that holds `compile_commands.json`. |
101+
| the `upload` step and post workflow | `tidy-review: true` | Reviews are posted from the same job. |
102+
| the failing format job | `format-review: true` | Formatting differences become review suggestions a contributor can apply from the browser. |
103+
104+
The `checks-failed` output plus the final `exit 1` step keeps the red check for anything not fixed.
105+
`thread-comments: update` keeps a single summary comment on the pull request and rewrites it on
106+
every push instead of adding a new one.
107+
108+
## Adopting a strict `.clang-tidy` on an old code base
109+
110+
Teams usually keep clang-tidy out of pull requests because of the first run, which reports
111+
thousands of findings in files nobody is touching. Two inputs handle that:
112+
113+
- `files-changed-only: true` (the default) limits analysis to files in the pull request.
114+
- `lines-changed-only: true` limits reported clang-tidy findings to lines the pull request changed.
115+
116+
With both set, contributors only see findings on the lines they changed. You clean up the rest of
117+
the tree gradually, or in one pass with the `cpp-linter` CLI.
118+
119+
## What contributors see
120+
121+
- Formatting problems show up as review suggestions. Clicking "Commit suggestion" fixes them
122+
without a local round trip.
123+
- clang-tidy findings appear as review comments on the changed lines, with the check name, and as
124+
annotations in the "Files changed" tab.
125+
- One thread comment summarizes the run and is updated in place.
126+
127+
## Keep the local side in sync
128+
129+
Add the pre-commit hooks with the same version, so the same clang-format runs before the commit
130+
exists:
131+
132+
```yaml title=".pre-commit-config.yaml"
133+
repos:
134+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
135+
rev: v1.6.0
136+
hooks:
137+
- id: clang-format
138+
args: [--style=file, --version=21]
139+
- id: clang-tidy
140+
args: [--checks=.clang-tidy, --version=21]
141+
```
142+
143+
Contributors who use the hook never see the review suggestions, because there is nothing left to
144+
suggest. The action becomes the safety net for everyone else.
145+
146+
## Things to check after switching
147+
148+
- The `pull-requests: write` permission is required for reviews and thread comments.
149+
Pull requests from forks get a read-only `GITHUB_TOKEN`; file annotations and the step summary
150+
still work there.
151+
- If your build needs generated headers, run the build before the action, or point `database` at
152+
a directory produced by an earlier step.
153+
- Compare the first run against the old jobs on one pull request before removing them.
154+
155+
The full input reference is in the
156+
[cpp-linter-action documentation](https://cpp-linter.github.io/cpp-linter-action/), and the
157+
[comparison page](../../why-cpp-linter.md) covers the other actions you might be coming from.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
date:
3+
created: 2026-09-12
4+
categories:
5+
- Guides
6+
tags:
7+
- clang-format
8+
- clang-tidy
9+
- cpp-linter-action
10+
- cpp-linter-hooks
11+
- clang-tools
12+
authors:
13+
- shenxianpeng
14+
---
15+
16+
# One clang-format version everywhere: pre-commit, CI and your laptop
17+
18+
A pull request fails the format check. The author runs `clang-format -i` locally, pushes, and it
19+
fails again with a different diff. Nothing is wrong with the code. The laptop has clang-format 18,
20+
CI installed 21 from a package repository last week, and the reviewer's editor plugin ships 19.
21+
22+
Every major LLVM release changes clang-format's output in small ways: new style options, changed
23+
defaults, fixed bugs. `clang-tidy` is worse, because new checks appear and old ones move between
24+
categories. Pinning the *project* version of a linter wrapper does not help if the wrapper pulls
25+
whatever clang happens to be around.
26+
27+
<!-- more -->
28+
29+
The cpp-linter tools are built to pick one LLVM major version and use it in every place code gets
30+
checked.
31+
32+
## Pick the version once
33+
34+
Write it down somewhere visible, for example in `CONTRIBUTING.md`:
35+
36+
```text
37+
Formatting and static analysis use LLVM 21 (clang-format 21, clang-tidy 21).
38+
```
39+
40+
Everything below pins `21`. When you move to 22, change it in all places in one commit, reformat
41+
the tree in the same commit, and the history stays clean.
42+
43+
## Pre-commit: cpp-linter-hooks
44+
45+
[cpp-linter-hooks](https://github.com/cpp-linter/cpp-linter-hooks) installs `clang-format` and
46+
`clang-tidy` as Python wheels, so every contributor gets the same binary regardless of what their
47+
distribution ships. The `rev` is the hooks release; the tool version is a separate `--version`
48+
argument:
49+
50+
```yaml title=".pre-commit-config.yaml"
51+
repos:
52+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
53+
rev: v1.6.0
54+
hooks:
55+
- id: clang-format
56+
args: [--style=file, --version=21]
57+
- id: clang-tidy
58+
args: [--checks=.clang-tidy, --version=21]
59+
```
60+
61+
`--style=file` and `--checks=.clang-tidy` read the same `.clang-format` and `.clang-tidy` files
62+
that CI will use, so the rules, like the version, are defined in one place.
63+
64+
## CI: cpp-linter-action
65+
66+
[cpp-linter-action](https://github.com/cpp-linter/cpp-linter-action) installs the requested
67+
version itself; the workflow does not need `apt-get install clang-format-21` or a matching LLVM
68+
apt repository. The `version` input takes the LLVM major version. It also accepts a path to tools
69+
you installed yourself, or an empty string for whatever the runner has; the
70+
[input reference](https://cpp-linter.github.io/cpp-linter-action/inputs-outputs/#version) has the
71+
details.
72+
73+
```yaml title=".github/workflows/lint.yml"
74+
name: cpp-linter
75+
on:
76+
pull_request:
77+
branches: [main]
78+
push:
79+
branches: [main]
80+
81+
jobs:
82+
cpp-linter:
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
pull-requests: write
87+
steps:
88+
- uses: actions/checkout@v5
89+
- uses: cpp-linter/cpp-linter-action@v2
90+
id: linter
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
with:
94+
version: '21'
95+
style: file
96+
tidy-checks: ''
97+
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
98+
- name: Fail on lint errors
99+
if: steps.linter.outputs.checks-failed > 0
100+
run: exit 1
101+
```
102+
103+
`style: file` and an empty `tidy-checks` tell the action to use `.clang-format` and
104+
`.clang-tidy` from the repository, the same files pre-commit used a minute earlier on the
105+
developer's machine. The result is a thread comment on the pull request that is updated on every
106+
push instead of a new comment each time, plus file annotations in the diff view.
107+
108+
## Local one-off runs: clang-tools
109+
110+
Sometimes you want the binary itself: a quick `clang-format --dry-run` over a directory, or a
111+
`clang-tidy` run with a hand-written compile database. [clang-tools](https://github.com/cpp-linter/clang-tools-pip)
112+
downloads a statically linked binary for the exact major version and falls back to the Python
113+
wheel when there is no binary for your platform:
114+
115+
```bash
116+
pip install clang-tools
117+
clang-tools install clang-format clang-tidy --version 21
118+
clang-format-21 --version
119+
```
120+
121+
The binaries come from [clang-tools-static-binaries](https://github.com/cpp-linter/clang-tools-static-binaries),
122+
which publishes a rolling window of recent LLVM majors for Linux, macOS and Windows, on x86-64 and
123+
ARM64; each release lists its exact versions in
124+
[`versions.json`](https://github.com/cpp-linter/clang-tools-static-binaries/releases/latest/download/versions.json).
125+
The same release is what cpp-linter-action downloads in CI, so the bytes match.
126+
127+
## Containers and other package managers
128+
129+
The same versions are available as
130+
[Docker images](https://github.com/cpp-linter/clang-tools-docker) tagged by major version:
131+
132+
```bash
133+
docker run -v "$PWD":/src xianpengshen/clang-tools:21 clang-format --dry-run --Werror /src/main.cpp
134+
```
135+
136+
The [Homebrew tap](https://github.com/cpp-linter/homebrew-tap) and the
137+
[asdf plugin](https://github.com/cpp-linter/asdf-clang-tools) are built from the same static
138+
binaries, for teams that already manage tool versions that way:
139+
140+
```bash
141+
brew install cpp-linter/tap/clang-format@21 cpp-linter/tap/clang-tidy@21
142+
```
143+
144+
## Upgrading
145+
146+
When LLVM 22 is the version you want:
147+
148+
1. Change `21` to `22` in `.pre-commit-config.yaml`, the workflow and `CONTRIBUTING.md`.
149+
2. Run `pre-commit run clang-format --all-files` and commit the reformatted tree together with the
150+
version change.
151+
3. Open the pull request. cpp-linter-action runs with 22 and should report nothing, because the
152+
tree was formatted with the same version a moment ago.
153+
154+
If the action reports differences at this point, the two tools are not on the same version, and
155+
the numbers above are the first thing to check.
156+
157+
## clang-tidy drifts more than clang-format
158+
159+
`clang-format` version drift produces noisy diffs. `clang-tidy` version drift produces different
160+
findings: checks that were added, renamed or made stricter. A pull request that passes locally and
161+
fails in CI with a check nobody has heard of is usually a version mismatch. With the hook and the
162+
action pinned to the same major version, the two numbers to compare are `--version` in
163+
`.pre-commit-config.yaml` and `version` in the workflow.

‎docs/blog/posts/myfirst.md‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎docs/blog/posts/mysecond.md‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎docs/index.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
hide:
33
- navigation
44
- toc
5+
- feedback
56
template: home.html
67
title: C/C++ Linting
78
---
@@ -139,7 +140,7 @@ title: C/C++ Linting
139140
<span>GitHub Users</span>
140141
</div>
141142
<div class="stat">
142-
<strong>20K+</strong>
143+
<strong>30K+</strong>
143144
<span>Downloads/Month</span>
144145
</div>
145146
<div class="stat">
@@ -148,6 +149,8 @@ title: C/C++ Linting
148149
</div>
149150
</div>
150151

152+
[See who uses cpp-linter →](showcase.md){ .md-button }
153+
151154
</div>
152155

153156
## Quick Start

0 commit comments

Comments
 (0)