# cpp-linter-hooks
[![PyPI](https://img.shields.io/pypi/v/cpp-linter-hooks?color=blue)](https://pypi.org/project/cpp-linter-hooks/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/)
[![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)
[![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)
[![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)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
<!-- [![PyPI - Downloads](https://img.shields.io/pypi/dw/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) -->
cpp-linter-hooks is a [pre-commit](https://pre-commit.com/) hook that uses `clang-format` and `clang-tidy` to format C/C++ code.
> [!NOTE]
> This hook automatically downloads specific versions of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs them on your system.
## Usage
To use cpp-linter-hooks, add the following configuration to your `.pre-commit-config.yaml`:
### Basic Configuration
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.6.0 # Use the ref you want to point at
hooks:
- id: clang-format
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-*']
```
### Custom Configuration
To use custom configurations like `.clang-format` and `.clang-tidy`:
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.6.0
hooks:
- id: clang-format
args: [--style=file] # to load .clang-format
- id: clang-tidy
args: [--checks=.clang-tidy] # path/to/.clang-tidy
```
To use specific versions of [clang-tools](https://github.com/cpp-linter/clang-tools-pip?tab=readme-ov-file#supported-versions):
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.6.0
hooks:
- id: clang-format
args: [--style=file, --version=16] # Specifies version
- id: clang-tidy
args: [--checks=.clang-tidy, --version=16] # Specifies version
```
## Output
### clang-format Example
```bash
clang-format.............................................................Failed
- hook id: clang-format
- files were modified by this hook
```
Here’s a sample diff showing the formatting applied:
```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;
+}
```
Use `--dry-run` in `args` of `clang-format` to print instead of changing the format, e.g.:
```bash
clang-format.............................................................Failed
- hook id: clang-format
- exit code: 255
main.c:2:11: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:13: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:21: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:28: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:54: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
main.c:2:63: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {for (;;) break; printf("Hello world!\n");return 0;}
^
```
### clang-tidy Example
```bash
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1
522 warnings generated.
Suppressed 521 warnings (521 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]
for (;;)
^
{
```
## Contributing
We welcome contributions! Whether it's fixing issues, suggesting improvements, or submitting pull requests, your support is greatly appreciated.
## License
cpp-linter-hooks is licensed under the [MIT License](LICENSE)
Raw data
{
"_id": null,
"home_page": null,
"name": "cpp-linter-hooks",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "clang, clang-format, clang-tidy, pre-commit, pre-commit-hooks",
"author": null,
"author_email": "Xianpeng Shen <xianpeng.shen@gmail.com>",
"download_url": null,
"platform": null,
"description": "# cpp-linter-hooks\n\n[![PyPI](https://img.shields.io/pypi/v/cpp-linter-hooks?color=blue)](https://pypi.org/project/cpp-linter-hooks/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/)\n[![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)\n[![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)\n[![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)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n<!-- [![PyPI - Downloads](https://img.shields.io/pypi/dw/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) -->\n\ncpp-linter-hooks is a [pre-commit](https://pre-commit.com/) hook that uses `clang-format` and `clang-tidy` to format C/C++ code.\n\n> [!NOTE]\n> This hook automatically downloads specific versions of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs them on your system.\n\n## Usage\n\nTo use cpp-linter-hooks, add the following configuration to your `.pre-commit-config.yaml`:\n\n### Basic Configuration\n\n```yaml\nrepos:\n - repo: https://github.com/cpp-linter/cpp-linter-hooks\n rev: v0.6.0 # Use the ref you want to point at\n hooks:\n - id: clang-format\n args: [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.\n - id: clang-tidy\n args: [--checks='boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-*']\n```\n\n### Custom Configuration\n\nTo use custom configurations like `.clang-format` and `.clang-tidy`:\n\n```yaml\nrepos:\n - repo: https://github.com/cpp-linter/cpp-linter-hooks\n rev: v0.6.0\n hooks:\n - id: clang-format\n args: [--style=file] # to load .clang-format\n - id: clang-tidy\n args: [--checks=.clang-tidy] # path/to/.clang-tidy\n```\n\nTo use specific versions of [clang-tools](https://github.com/cpp-linter/clang-tools-pip?tab=readme-ov-file#supported-versions):\n\n```yaml\nrepos:\n - repo: https://github.com/cpp-linter/cpp-linter-hooks\n rev: v0.6.0\n hooks:\n - id: clang-format\n args: [--style=file, --version=16] # Specifies version\n - id: clang-tidy\n args: [--checks=.clang-tidy, --version=16] # Specifies version\n```\n\n## Output\n\n### clang-format Example\n\n```bash\nclang-format.............................................................Failed\n- hook id: clang-format\n- files were modified by this hook\n```\n\nHere\u2019s a sample diff showing the formatting applied:\n\n```diff\n--- a/testing/main.c\n+++ b/testing/main.c\n@@ -1,3 +1,6 @@\n #include <stdio.h>\n-int main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n-\n+int main() {\n+ for (;;) break;\n+ printf(\"Hello world!\\n\");\n+ return 0;\n+}\n```\n\nUse `--dry-run` in `args` of `clang-format` to print instead of changing the format, e.g.:\n\n```bash\nclang-format.............................................................Failed\n- hook id: clang-format\n- exit code: 255\n\nmain.c:2:11: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\nmain.c:2:13: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\nmain.c:2:21: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\nmain.c:2:28: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\nmain.c:2:54: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\nmain.c:2:63: warning: code should be clang-formatted [-Wclang-format-violations]\nint main() {for (;;) break; printf(\"Hello world!\\n\");return 0;}\n ^\n```\n\n### clang-tidy Example\n\n```bash\nclang-tidy...............................................................Failed\n- hook id: clang-tidy\n- exit code: 1\n\n522 warnings generated.\nSuppressed 521 warnings (521 in non-user code).\nUse -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.\n/home/runner/work/cpp-linter-hooks/cpp-linter-hooks/testing/main.c:4:13: warning: statement should be inside braces [readability-braces-around-statements]\n for (;;)\n ^\n {\n\n```\n\n## Contributing\n\nWe welcome contributions! Whether it's fixing issues, suggesting improvements, or submitting pull requests, your support is greatly appreciated.\n\n## License\n\ncpp-linter-hooks is licensed under the [MIT License](LICENSE)\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Automatically check c/c++ code with clang-format and clang-tidy",
"version": "0.6.0",
"project_urls": {
"source": "https://github.com/cpp-linter/cpp-linter-hooks",
"tracker": "https://github.com/cpp-linter/cpp-linter-hooks/issues"
},
"split_keywords": [
"clang",
" clang-format",
" clang-tidy",
" pre-commit",
" pre-commit-hooks"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3c738fdd841f218945e0b32cc374bbb741bbf187600f452298cd72c2faddbd2b",
"md5": "1102fb6e28e600c883054ea2be0dabeb",
"sha256": "8978041faf79c4c847ab994f1401706434d2abfa9fb61c8962edf54a15aa358e"
},
"downloads": -1,
"filename": "cpp_linter_hooks-0.6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1102fb6e28e600c883054ea2be0dabeb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6446,
"upload_time": "2024-12-17T07:35:02",
"upload_time_iso_8601": "2024-12-17T07:35:02.040225Z",
"url": "https://files.pythonhosted.org/packages/3c/73/8fdd841f218945e0b32cc374bbb741bbf187600f452298cd72c2faddbd2b/cpp_linter_hooks-0.6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 07:35:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cpp-linter",
"github_project": "cpp-linter-hooks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cpp-linter-hooks"
}