5
5
6
6
Using ` clang-format ` and ` clang-tidy ` hooks with [ pre-commit] ( https://pre-commit.com/ ) to lint your C/C++ code.
7
7
8
- ✨ Highlight✨: automatically install ` clang-format ` and ` clang-tidy ` when they do not exist.
8
+ Highlight✨: automatically install ` clang-format ` and ` clang-tidy ` when they do not exist.
9
9
10
10
## Usage
11
11
@@ -17,69 +17,48 @@ repos:
17
17
rev : v0.1.0 # Use the ref you want to point at
18
18
hooks :
19
19
- id : clang-format
20
- args : [--style=Google]
20
+ args : [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
21
21
- id : clang-tidy
22
22
args : [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']
23
23
` ` `
24
24
25
- Use specific version. for example ` clang-format` is version 13, ` clang-tidy` is version 12.
25
+ The example of using custom config: ` . clang-format` and `. clang-tidy`
26
26
27
27
` ` ` yaml
28
28
repos:
29
29
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
30
30
rev: v0.1.0 # Use the ref you want to point at
31
31
hooks:
32
32
- id: clang-format
33
- args: [--style=Google, --version=13]
33
+ args: [--style=.clang-format] # path/to/.clang-format
34
34
- id: clang-tidy
35
- args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*, clang-analyzer-*,cppcoreguidelines-*', --version=12]
35
+ args: [--checks=. clang-tidy] # path/to/.clang-tidy
36
36
` ` `
37
37
38
- # # Support hooks
39
-
40
- # ## `clang-format`
38
+ The example of using any version of [clang-tools](https://github.com/shenxianpeng/clang-tools-pip).
41
39
42
- Prevent committing unformatted C/C++ code.
40
+ ` ` ` yaml
41
+ repos:
42
+ - repo: https://github.com/shenxianpeng/cpp-linter-hooks
43
+ rev: v0.1.0 # Use the ref you want to point at
44
+ hooks:
45
+ - id: clang-format
46
+ args: [--style=Google, --version=13]
47
+ - id: clang-tidy
48
+ args: [--checks=.clang-tidy, --version=12]
49
+ ` ` `
43
50
44
- * Set coding style: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit with `args: [--style=LLVM]`
45
- * Load coding style configuration file `.clang-format` with `args: [--style=file]`
51
+ # # Output
46
52
47
- output
53
+ The output when catching unformatted and error code.
48
54
49
55
```
50
56
clang-format.............................................................Failed
51
57
- hook id: clang-format
52
58
- files were modified by this hook
53
- ```
54
- modified file
55
- ```diff
56
- --- a/testing/main.c
57
- +++ b/testing/main.c
58
- @@ -1,3 +1,6 @@
59
- #include <stdio.h>
60
- -int main() {for (;;) break; printf("Hello world!\n");return 0;}
61
- -
62
- +int main() {
63
- + for (;;) break;
64
- + printf("Hello world!\n");
65
- + return 0;
66
- +}
67
- ```
68
-
69
- ### ` clang-tidy `
70
-
71
- Prevent committing typical programming errors, like style violations, interface misuse, or bugs that can be deduced.
72
-
73
- * Set checks like ` args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*'] `
74
- * Or set specify the path of .clang-tidy like ` args: [--checks=path/to/.clang-tidy] `
75
-
76
-
77
- Output
78
-
79
- ```
80
59
clang-tidy...............................................................Failed
81
60
- hook id: clang-tidy
82
- - duration: 0.48s
61
+ - exit code: 1
83
62
84
63
418 warnings and 1 error generated.
85
64
Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
@@ -94,3 +73,23 @@ Found compiler error(s).
94
73
#include <stddef.h>
95
74
^~~~~~~~~~
96
75
```
76
+
77
+ The diff of the modified file.
78
+
79
+ ```diff
80
+ --- a/testing/main.c
81
+ +++ b/testing/main.c
82
+ @@ -1,3 +1,6 @@
83
+ #include <stdio.h>
84
+ -int main() {for (;;) break; printf("Hello world!\n");return 0;}
85
+ -
86
+ +int main() {
87
+ + for (;;) break;
88
+ + printf("Hello world!\n");
89
+ + return 0;
90
+ +}
91
+ ```
92
+
93
+ ## License
94
+
95
+ This project is licensed under the terms of the MIT license.
0 commit comments