cpp-linter-hooks


Namecpp-linter-hooks JSON
Version 0.5.1 PyPI version JSON
download
home_pageNone
SummaryAutomatically check c/c++ with clang-format and clang-tidy
upload_time2024-08-16 14:43:05
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT License
keywords clang clang-format clang-tidy pre-commit pre-commit-hooks
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cpp-linter-hooks

[![PyPI](https://img.shields.io/pypi/v/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` integrates `clang-format` and `clang-tidy` hooks with [pre-commit](https://pre-commit.com/) to lint your C/C++ code efficiently.

> [!NOTE]
> This hook automatically downloads a specific version of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs it on the system.

## Usage

Add the following configuration to your `.pre-commit-config.yaml`:

```yaml
repos:
  - repo: https://github.com/cpp-linter/cpp-linter-hooks
    rev: v0.5.1  # 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-*']
```

To use custom configurations like `.clang-format` and `.clang-tidy`:

```yaml
repos:
  - repo: https://github.com/cpp-linter/cpp-linter-hooks
    rev: v0.5.1
    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.5.1
    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 output

```bash
clang-format.............................................................Failed
- hook id: clang-format
- files were modified by this hook
```

The diff between the modified file is as follows:

```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 output

```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

Contributions are very welcome, including submitting issues, PRs, etc.

## License

[MIT](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": "Peter 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)](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\n\n`cpp-linter-hooks` integrates `clang-format` and `clang-tidy` hooks with [pre-commit](https://pre-commit.com/) to lint your C/C++ code efficiently.\n\n> [!NOTE]\n> This hook automatically downloads a specific version of `clang-format` or `clang-tidy` [binaries](https://github.com/cpp-linter/clang-tools-static-binaries) and installs it on the system.\n\n## Usage\n\nAdd the following configuration to your `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n  - repo: https://github.com/cpp-linter/cpp-linter-hooks\n    rev: v0.5.1  # 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\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.5.1\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.5.1\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 output\n\n```bash\nclang-format.............................................................Failed\n- hook id: clang-format\n- files were modified by this hook\n```\n\nThe diff between the modified file is as follows:\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 output\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\nContributions are very welcome, including submitting issues, PRs, etc.\n\n## License\n\n[MIT](LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Automatically check c/c++ with clang-format and clang-tidy",
    "version": "0.5.1",
    "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": "4832c26f3cc19bc8462a44d670e0c693c177c214e3dbf2c36f5467b6c7597815",
                "md5": "504e62d0ac5d3c835d922e46dd0a734f",
                "sha256": "de5da00a62029c50e844f694807e25fff23aff0589938666d39692cd478b43ff"
            },
            "downloads": -1,
            "filename": "cpp_linter_hooks-0.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "504e62d0ac5d3c835d922e46dd0a734f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6317,
            "upload_time": "2024-08-16T14:43:05",
            "upload_time_iso_8601": "2024-08-16T14:43:05.978293Z",
            "url": "https://files.pythonhosted.org/packages/48/32/c26f3cc19bc8462a44d670e0c693c177c214e3dbf2c36f5467b6c7597815/cpp_linter_hooks-0.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-16 14:43:05",
    "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"
}
        
Elapsed time: 0.42306s