Skip to content

Commit

Permalink
update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
shenxianpeng committed Jul 12, 2022
1 parent d3fc88c commit 267f544
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 46 deletions.
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ repos:
description: Run all tests
language: system
types: [python]

# Start: for development testing
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
rev: dd98f398f2bc72869a39a9c56d97940408f6d3b4
rev: d3fc88c84b93708b4e5eb12c72cdbf421599cd40
hooks:
- id: clang-format
args: [--style=Google, --version=13]
- id: clang-tidy
args: [--checks=testing/.clang-tidy, --version=13]
# or specify the path of .clang-tidy
# args: [--config-file=."]
# End: for development testing
79 changes: 39 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Using `clang-format` and `clang-tidy` hooks with [pre-commit](https://pre-commit.com/) to lint your C/C++ code.

Highlight✨: automatically install `clang-format` and `clang-tidy` when they do not exist.
Highlight✨: automatically install `clang-format` and `clang-tidy` when they do not exist.

## Usage

Expand All @@ -17,69 +17,48 @@ repos:
rev: v0.1.0 # Use the ref you want to point at
hooks:
- id: clang-format
args: [--style=Google]
args: [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
- id: clang-tidy
args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']
```
Use specific version. for example `clang-format` is version 13, `clang-tidy` is version 12.
The example of using custom config: `.clang-format` and `.clang-tidy`

```yaml
repos:
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
rev: v0.1.0 # Use the ref you want to point at
hooks:
- id: clang-format
args: [--style=Google, --version=13]
args: [--style=.clang-format] # path/to/.clang-format
- id: clang-tidy
args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*', --version=12]
args: [--checks=.clang-tidy] # path/to/.clang-tidy
```

## Support hooks

### `clang-format`
The example of using any version of [clang-tools](https://github.com/shenxianpeng/clang-tools-pip).

Prevent committing unformatted C/C++ code.
```yaml
repos:
- repo: https://github.com/shenxianpeng/cpp-linter-hooks
rev: v0.1.0 # Use the ref you want to point at
hooks:
- id: clang-format
args: [--style=Google, --version=13]
- id: clang-tidy
args: [--checks=.clang-tidy, --version=12]
```

* Set coding style: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit with `args: [--style=LLVM]`
* Load coding style configuration file `.clang-format` with `args: [--style=file]`
## Output

output
The output when catching unformatted and error code.

```
clang-format.............................................................Failed
- hook id: clang-format
- files were modified by this hook
```
modified file
```diff
--- a/testing/main.c
+++ b/testing/main.c
@@ -1,3 +1,6 @@
#include <stdio.h>
-int main() {for (;;) break; printf("Hello world!\n");return 0;}
-
+int main() {
+ for (;;) break;
+ printf("Hello world!\n");
+ return 0;
+}
```

### `clang-tidy`

Prevent committing typical programming errors, like style violations, interface misuse, or bugs that can be deduced.

* Set checks like `args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']`
* Or set specify the path of .clang-tidy like `args: [--checks=path/to/.clang-tidy]`


Output

```
clang-tidy...............................................................Failed
- hook id: clang-tidy
- duration: 0.48s
- exit code: 1

418 warnings and 1 error generated.
Error while processing /home/ubuntu/cpp-linter-hooks/testing/main.c.
Expand All @@ -94,3 +73,23 @@ Found compiler error(s).
#include <stddef.h>
^~~~~~~~~~
```
The diff of the modified file.
```diff
--- a/testing/main.c
+++ b/testing/main.c
@@ -1,3 +1,6 @@
#include <stdio.h>
-int main() {for (;;) break; printf("Hello world!\n");return 0;}
-
+int main() {
+ for (;;) break;
+ printf("Hello world!\n");
+ return 0;
+}
```

## License

This project is licensed under the terms of the MIT license.

0 comments on commit 267f544

Please sign in to comment.