Skip to content

Commit 39b0aaa

Browse files
committed
update readme and debug clang-tidy
1 parent fd4bb70 commit 39b0aaa

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: reorder-python-imports
1818
language_version: python3
1919
- repo: https://github.com/asottile/pyupgrade
20-
rev: v1.16.1
20+
rev: v2.36.0
2121
hooks:
2222
- id: pyupgrade
2323
- repo: https://github.com/pycqa/flake8
@@ -39,9 +39,9 @@ repos:
3939
rev: main
4040
hooks:
4141
- id: clang-format
42-
args: [--style=Google, --version=14]
42+
args: [--style=Google, --version=13]
4343
- id: clang-tidy
44-
args: [--checks="boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*"]
44+
args: [--checks=testing/.clang-tidy, --version=13]
4545
# or specify the path of .clang-tidy
4646
# args: [--config-file=."]
4747
# End: for development testing

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ repos:
1717
hooks:
1818
- id: clang-format
1919
args: [--style=Google]
20-
# - id: clang-tidy ## Work in progress
21-
# args: [--config-file=file]
20+
- id: clang-tidy
21+
args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']
22+
```
23+
24+
Use specific version. for example `clang-format` is version 13, `clang-tidy` is version 12.
25+
26+
```yaml
27+
repos:
28+
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
29+
rev: v0.1.0 # Use the ref you want to point at
30+
hooks:
31+
- id: clang-format
32+
args: [--style=Google, --version=13]
33+
- id: clang-tidy
34+
args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*', --version=12]
2235
```
2336

2437
## Support hooks
@@ -30,6 +43,31 @@ Prevent committing unformatted C/C++ code.
3043
* Set coding style: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit with `args: [--style=LLVM]`
3144
* Load coding style configuration file `.clang-format` with `args: [--style=file]`
3245

46+
output
47+
48+
```
49+
clang-format.............................................................Failed
50+
- hook id: clang-format
51+
- files were modified by this hook
52+
```
53+
modified file
54+
```diff
55+
--- a/testing/main.c
56+
+++ b/testing/main.c
57+
@@ -1,3 +1,6 @@
58+
#include <stdio.h>
59+
-int main() {for (;;) break; printf("Hello world!\n");return 0;}
60+
-
61+
+int main() {
62+
+ for (;;) break;
63+
+ printf("Hello world!\n");
64+
+ return 0;
65+
+}
66+
```
67+
3368
### `clang-tidy`
3469

3570
Prevent committing typical programming errors, like style violations, interface misuse, or bugs that can be deduced.
71+
72+
* Set checks like `args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']`
73+
* Or set specify the path of .clang-tidy like `args: [--checks=path/to/.clang-tidy]`

cpp_linter_hooks/clang_tidy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def run_clang_tidy(args) -> int:
1313
if arg == expect_version or arg.startswith("--version"):
1414
continue
1515
command.append(arg)
16+
print(command)
1617
try:
1718
subprocess.run(command, stdout=subprocess.PIPE)
1819
return 0

0 commit comments

Comments
 (0)