Skip to content

Commit 30ca9e9

Browse files
committed
feat: update README and code to support clang-tidy auto-fix with version v1.4.0
1 parent 15a2158 commit 30ca9e9

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Add this configuration to your `.pre-commit-config.yaml` file:
3232
```yaml
3333
repos:
3434
- repo: https://github.com/cpp-linter/cpp-linter-hooks
35-
rev: v1.2.0 # Use the tag or commit you want
35+
rev: v1.4.0 # Use the tag or commit you want
3636
hooks:
3737
- id: clang-format
3838
args: [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
@@ -47,7 +47,7 @@ To use custom configurations like `.clang-format` and `.clang-tidy`:
4747
```yaml
4848
repos:
4949
- repo: https://github.com/cpp-linter/cpp-linter-hooks
50-
rev: v1.2.0
50+
rev: v1.4.0
5151
hooks:
5252
- id: clang-format
5353
args: [--style=file] # Loads style from .clang-format file
@@ -56,7 +56,7 @@ repos:
5656
```
5757

5858
> [!TIP]
59-
> The `rev` tag (e.g. `v1.2.0`) is the **project** version, not the clang tool version. Each release bundles a default version of `clang-format` and `clang-tidy` — check the [release notes](https://github.com/cpp-linter/cpp-linter-hooks/releases) to see which tool version a given `rev` ships with. To pin an exact tool version independently of the project release, use `--version` as shown below.
59+
> The `rev` tag (e.g. `v1.4.0`) is the **project** version, not the clang tool version. Each release bundles a default version of `clang-format` and `clang-tidy` — check the [release notes](https://github.com/cpp-linter/cpp-linter-hooks/releases) to see which tool version a given `rev` ships with. To pin an exact tool version independently of the project release, use `--version` as shown below.
6060

6161
### Custom Clang Tool Version
6262

@@ -65,7 +65,7 @@ To use specific versions of clang-format and clang-tidy (using Python wheel pack
6565
```yaml
6666
repos:
6767
- repo: https://github.com/cpp-linter/cpp-linter-hooks
68-
rev: v1.2.0
68+
rev: v1.4.0
6969
hooks:
7070
- id: clang-format
7171
args: [--style=file, --version=21] # Specifies version
@@ -89,7 +89,7 @@ automatically — no configuration needed for most projects:
8989
```yaml
9090
repos:
9191
- repo: https://github.com/cpp-linter/cpp-linter-hooks
92-
rev: v1.2.0
92+
rev: v1.4.0
9393
hooks:
9494
- id: clang-tidy
9595
args: [--checks=.clang-tidy]
@@ -204,7 +204,7 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
204204
```yaml
205205
repos:
206206
- repo: https://github.com/cpp-linter/cpp-linter-hooks
207-
rev: v1.2.0
207+
rev: v1.4.0 # requires the version that introduced --fix
208208
hooks:
209209
- id: clang-tidy
210210
args: [--checks=.clang-tidy, --fix]
@@ -223,7 +223,7 @@ repos:
223223

224224
```yaml
225225
- repo: https://github.com/cpp-linter/cpp-linter-hooks
226-
rev: v1.2.0
226+
rev: v1.4.0
227227
hooks:
228228
- id: clang-format
229229
args: [--style=file, --version=21]
@@ -238,7 +238,7 @@ or `-j`:
238238

239239
```yaml
240240
- repo: https://github.com/cpp-linter/cpp-linter-hooks
241-
rev: v1.2.0
241+
rev: v1.4.0
242242
hooks:
243243
- id: clang-tidy
244244
args: [--checks=.clang-tidy, --version=21, --jobs=4]
@@ -267,7 +267,7 @@ This approach ensures that only modified files are checked, further speeding up
267267
```yaml
268268
repos:
269269
- repo: https://github.com/cpp-linter/cpp-linter-hooks
270-
rev: v1.2.0
270+
rev: v1.4.0
271271
hooks:
272272
- id: clang-format
273273
args: [--style=file, --version=21, --verbose] # Shows processed files

cpp_linter_hooks/clang_tidy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ def run_clang_tidy(args=None) -> Tuple[int, str]:
155155

156156
clang_tidy_args, source_files = _split_source_files(other_args)
157157

158-
if hook_args.fix:
158+
if (
159+
hook_args.fix
160+
and "-fix" not in clang_tidy_args
161+
and "-fix-errors" not in clang_tidy_args
162+
):
159163
clang_tidy_args.append("-fix")
160164

161165
# Parallel execution is unsafe when arguments include flags that write to a

tests/test_clang_tidy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def test_fix_flag_appends_fix_to_command():
335335
):
336336
run_clang_tidy(["--fix", "-p", "./build", "dummy.cpp"])
337337

338+
mock_exec.assert_called_once()
338339
cmd = mock_exec.call_args[0][0]
339340
assert "-fix" in cmd
340341

0 commit comments

Comments
 (0)