Skip to content

Commit dd98f39

Browse files
committed
update clang-tidy
1 parent cf62613 commit dd98f39

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ repos:
3636

3737
# Start: for development testing
3838
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
39-
rev: 39b0aaa721fb0b1d6fb07214e6bfa63322419e5a
39+
rev: cf62613fe77f66cc826cbebcf2693bf0872dc764
4040
hooks:
4141
- id: clang-format
4242
args: [--style=Google, --version=13]
4343
- id: clang-tidy
44-
verbose: true
4544
args: [--checks=testing/.clang-tidy, --version=13]
4645
# or specify the path of .clang-tidy
4746
# args: [--config-file=."]

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,25 @@ Prevent committing typical programming errors, like style violations, interface
7171

7272
* Set checks like `args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']`
7373
* Or set specify the path of .clang-tidy like `args: [--checks=path/to/.clang-tidy]`
74+
75+
76+
Output
77+
78+
```
79+
clang-tidy...............................................................Failed
80+
- hook id: clang-tidy
81+
- duration: 0.48s
82+
83+
418 warnings and 1 error generated.
84+
Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
85+
Suppressed 417 warnings (417 in non-user code).
86+
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
87+
Found compiler error(s).
88+
/home/ubuntu/cpp-linter-hooks/testing/main.c:3:11: warning: statement should be inside braces [readability-braces-around-statements]
89+
for (;;) break;
90+
^
91+
{
92+
/usr/include/stdio.h:33:10: error: 'stddef.h' file not found [clang-diagnostic-error]
93+
#include <stddef.h>
94+
^~~~~~~~~~
95+
```

cpp_linter_hooks/clang_tidy.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from cpp_linter_hooks import expect_version
55

66

7-
def run_clang_tidy(args) -> str:
7+
def run_clang_tidy(args) -> int:
88
if expect_version:
99
command = [f'clang-tidy-{expect_version}']
1010
else:
@@ -14,15 +14,18 @@ def run_clang_tidy(args) -> str:
1414
continue
1515
command.append(arg)
1616
try:
17-
output = subprocess.run(command, stdout=subprocess.PIPE).stdout.decode("utf-8")
17+
sp = subprocess.run(command, stdout=subprocess.PIPE)
18+
retval = sp.returncode
19+
output = sp.stdout.decode("utf-8")
20+
return retval, output
1821
except FileNotFoundError as e:
19-
output = e
20-
return output
22+
return 1, e
2123

2224

2325
def main():
24-
result = run_clang_tidy(args)
25-
print(result)
26+
retval, output = run_clang_tidy(args)
27+
if retval != 0:
28+
print(output)
2629

2730

2831
if __name__ == "__main__":

0 commit comments

Comments
 (0)