Skip to content

Commit fcbf65a

Browse files
committed
update README.md
1 parent a2b664c commit fcbf65a

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55
[![codecov](https://codecov.io/gh/cpp-linter/cpp-linter-hooks/branch/main/graph/badge.svg?token=L74Z3HZ4Y5)](https://codecov.io/gh/cpp-linter/cpp-linter-hooks)
66
[![Test](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml)
77
[![CodeQL](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml)
8-
<!-- [![PyPI - Downloads](https://img.shields.io/pypi/dw/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) -->
98

10-
cpp-linter-hooks is a [pre-commit](https://pre-commit.com/) hook that uses `clang-format` and `clang-tidy` to format C/C++ code.
9+
A powerful [pre-commit](https://pre-commit.com/) hook that automatically formats and lints your C/C++ code using `clang-format` and `clang-tidy`.
1110

12-
> [!NOTE]
13-
> This hook automatically downloads specific versions of `clang-format` or `clang-tidy` [static-binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs them on your system.
11+
## Table of Contents
1412

15-
## Usage
13+
- [Quick Start](#quick-start)
14+
- [Custom Configuration Files](#custom-configuration-files)
15+
- [Custom Clang Tool Version](#custom-clang-tool-version)
16+
- [Troubleshooting](#troubleshooting)
17+
- [Debugging `clang-format` hook](#debugging-clang-format-hook)
18+
- [Output](#output)
19+
- [clang-format Output](#clang-format-output)
20+
- [clang-tidy Output](#clang-tidy-output)
21+
- [Contributing](#contributing)
22+
- [License](#license)
1623

17-
To use cpp-linter-hooks, add the following configuration to your `.pre-commit-config.yaml`:
24+
## Quick Start
1825

19-
### Basic Configuration
26+
Add this configuration to your `.pre-commit-config.yaml` file:
2027

2128
```yaml
2229
repos:
@@ -29,7 +36,7 @@ repos:
2936
args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']
3037
```
3138
32-
### Custom Configuration
39+
### Custom Configuration Files
3340
3441
To use custom configurations like `.clang-format` and `.clang-tidy`:
3542

@@ -44,6 +51,8 @@ repos:
4451
args: [--checks=.clang-tidy] # Loads checks from .clang-tidy file
4552
```
4653

54+
### Custom Clang Tool Version
55+
4756
To use specific versions of [clang-tools](https://github.com/cpp-linter/clang-tools-pip?tab=readme-ov-file#supported-versions):
4857

4958
```yaml
@@ -57,6 +66,8 @@ repos:
5766
args: [--checks=.clang-tidy, --version=18] # Specifies version
5867
```
5968

69+
### Troubleshooting
70+
6071
> [!IMPORTANT]
6172
> If your `pre-commit` runs longer than expected, it is highly recommended to add `files` in `.pre-commit-config.yaml` to limit the scope of the hook. This helps improve performance by reducing the number of files being checked and avoids unnecessary processing. Here's an example configuration:
6273

@@ -81,9 +92,22 @@ pre-commit run --files $(git diff --name-only)
8192

8293
This approach ensures that only modified files are checked, further speeding up the linting process during development.
8394

95+
### Debugging `clang-format` hook
96+
97+
If you encounter issues with the clang-format hook (such as exit code 247 or other errors), you can enable verbose output to show the list of processed files by passing the `-v` or `--verbose` argument in the `args` section.
98+
99+
```yaml
100+
repos:
101+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
102+
rev: v0.8.1
103+
hooks:
104+
- id: clang-format
105+
args: [--style=file, --version=18, --verbose] # Add -v or --verbose for detailed output
106+
```
107+
84108
## Output
85109

86-
### clang-format Example
110+
### clang-format Output
87111

88112
```bash
89113
clang-format.............................................................Failed
@@ -106,8 +130,8 @@ Here’s a sample diff showing the formatting applied:
106130
+ return 0;
107131
+}
108132
```
109-
110-
Use `--dry-run` in `args` of `clang-format` to print instead of changing the format, e.g.:
133+
> [!NOTE]
134+
> Use `--dry-run` in `args` of `clang-format` to print instead of changing the format, e.g.:
111135

112136
```bash
113137
clang-format.............................................................Failed
@@ -134,7 +158,7 @@ int main() {for (;;) break; printf("Hello world!\n");return 0;}
134158
^
135159
```
136160

137-
### clang-tidy Example
161+
### clang-tidy Output
138162

139163
```bash
140164
clang-tidy...............................................................Failed
@@ -151,25 +175,10 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
151175
152176
```
153177

154-
## Troubleshooting
155-
156-
### Debugging `clang-format` hook
157-
158-
If you encounter issues with the clang-format hook (such as exit code 247 or other errors), you can enable verbose output to show the list of processed files by passing the `-v` or `--verbose` argument in the `args` section.
159-
160-
```yaml
161-
repos:
162-
- repo: https://github.com/cpp-linter/cpp-linter-hooks
163-
rev: v0.8.1
164-
hooks:
165-
- id: clang-format
166-
args: [--style=file, --version=18, --verbose] # Add --verbose for detailed output
167-
```
168-
169178
## Contributing
170179

171180
We welcome contributions! Whether it's fixing issues, suggesting improvements, or submitting pull requests, your support is greatly appreciated.
172181

173182
## License
174183

175-
cpp-linter-hooks is licensed under the [MIT License](LICENSE)
184+
This project is licensed under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)