Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #40

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Peter Shen
Copyright (c) 2022 Xianpeng Shen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@
<!-- [![PyPI - Downloads](https://img.shields.io/pypi/dw/cpp-linter-hooks)](https://pypi.org/project/cpp-linter-hooks/) -->


Using `clang-format` and `clang-tidy` hooks with [pre-commit](https://pre-commit.com/) to lint your C/C++ code.
`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]
> 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.
> 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 this to your `.pre-commit-config.yaml`
Add the following configuration to your `.pre-commit-config.yaml`:

```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.3.0 # Use the ref you want to point at
rev: v0.3.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-*']
```

The example of using custom config: `.clang-format` and `.clang-tidy`
To use custom configurations like `.clang-format` and `.clang-tidy`:

```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v0.3.0
rev: v0.3.1
hooks:
- id: clang-format
args: [--style=file] # to load .clang-format
- id: clang-tidy
args: [--checks=.clang-tidy] # path/to/.clang-tidy
```

The example of using any version of [clang-tools](https://github.com/cpp-linter/clang-tools-pip?tab=readme-ov-file#supported-versions).
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.3.0
rev: v0.3.1
hooks:
- id: clang-format
args: [--style=file, --version=16]
args: [--style=file, --version=16] # Specifies version
- id: clang-tidy
args: [--checks=.clang-tidy, --version=16]
args: [--checks=.clang-tidy, --version=16] # Specifies version
```

## Output
Expand All @@ -64,7 +64,7 @@ clang-format.............................................................Failed
- files were modified by this hook
```

Here is the diff between the modified file.
The diff between the modified file is as follows:

```diff
--- a/testing/main.c
Expand All @@ -80,9 +80,7 @@ Here is the diff between the modified file.
+}
```

Pass `--dry-run` to the `args` of `clang-format`(can also pass other arg which clang-format supports)

Then it will just print instead of changing the format. E.g:
Use `--dry-run` in `args` of `clang-format` to print instead of changing the format, e.g.:

```bash
clang-format.............................................................Failed
Expand Down Expand Up @@ -128,8 +126,8 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system

## Contributing

Any contribution is very welcome, including submitting issues, PRs, etc.
Contributions are very welcome, including submitting issues, PRs, etc.

## License

This project is licensed under the terms of the MIT license.
[MIT](LICENSE)
Loading