55
66Using ` clang-format ` and ` clang-tidy ` hooks with [ pre-commit] ( https://pre-commit.com/ ) to lint your C/C++ code.
77
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.
99
1010## Usage
1111
@@ -17,69 +17,48 @@ repos:
1717 rev : v0.1.0 # Use the ref you want to point at
1818 hooks :
1919 - id : clang-format
20- args : [--style=Google]
20+ args : [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
2121 - id : clang-tidy
2222 args : [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']
2323` ` `
2424
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`
2626
2727` ` ` yaml
2828repos:
2929 - repo: https://github.com/shenxianpeng/cpp-linter-hooks
3030 rev: v0.1.0 # Use the ref you want to point at
3131 hooks:
3232 - id: clang-format
33- args: [--style=Google, --version=13]
33+ args: [--style=.clang-format] # path/to/.clang-format
3434 - 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
3636` ` `
3737
38- # # Support hooks
39-
40- # ## `clang-format`
38+ The example of using any version of [clang-tools](https://github.com/shenxianpeng/clang-tools-pip).
4139
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+ ` ` `
4350
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
4652
47- output
53+ The output when catching unformatted and error code.
4854
4955```
5056clang-format.............................................................Failed
5157- hook id: clang-format
5258- 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- ```
8059clang-tidy...............................................................Failed
8160- hook id: clang-tidy
82- - duration: 0.48s
61+ - exit code: 1
8362
8463418 warnings and 1 error generated.
8564Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
@@ -94,3 +73,23 @@ Found compiler error(s).
9473#include <stddef.h>
9574 ^~~~~~~~~~
9675```
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