Skip to content
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -14,7 +14,7 @@ repos:
hooks:
- id: pyupgrade
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2
rev: v0.12.11
hooks:
- id: ruff
- id: ruff-format
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add this configuration to your `.pre-commit-config.yaml` file:
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.0.1 # Use the tag or commit you want
rev: v1.1.0 # Use the tag or commit you want
hooks:
- id: clang-format
args: [--style=Google] # Other coding style: LLVM, GNU, Chromium, Microsoft, Mozilla, WebKit.
Expand All @@ -46,7 +46,7 @@ To use custom configurations like `.clang-format` and `.clang-tidy`:
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.0.1
rev: v1.1.0
hooks:
- id: clang-format
args: [--style=file] # Loads style from .clang-format file
Expand All @@ -61,7 +61,7 @@ To use specific versions of clang-format and clang-tidy (using Python wheel pack
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.0.1
rev: v1.1.0
hooks:
- id: clang-format
args: [--style=file, --version=18] # Specifies version
Expand All @@ -70,7 +70,7 @@ repos:
```

> [!NOTE]
> Starting from version v1.0.0, this package uses Python wheel packages ([clang-format](https://pypi.org/project/clang-format/) and [clang-tidy](https://pypi.org/project/clang-tidy/)) instead of the previous clang-tools binaries. The wheel packages provide better cross-platform compatibility and easier installation. For more details, see the [Migration Guide](MIGRATION.md).
> Starting from version **v1.0.0**, this pre-commit hook now relies on Python wheel packages [clang-format](https://pypi.org/project/clang-format/) and [clang-tidy](https://pypi.org/project/clang-tidy/)instead of the [clang-tools binaries](https://github.com/cpp-linter/clang-tools-static-binaries). The wheel packages are lighter, easier to install, and offer better cross-platform compatibility. For more information, see the [detailed migration notes](docs/migration-notes.md).

## Output

Expand Down Expand Up @@ -147,17 +147,17 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system
### Performance Optimization

> [!TIP]
> 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:
> For large codebases, 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:

```yaml
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.0.1
rev: v1.1.0
hooks:
- id: clang-format
args: [--style=file, --version=18]
args: [--style=file, --version=20]
files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$ # Limits to specific dirs and file types
- id: clang-tidy
args: [--checks=.clang-tidy, --version=18]
args: [--checks=.clang-tidy, --version=20]
files: ^(src|include)/.*\.(cpp|cc|cxx|h|hpp)$
```

Expand All @@ -177,7 +177,7 @@ This approach ensures that only modified files are checked, further speeding up
```yaml
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.0.1
rev: v1.1.0
hooks:
- id: clang-format
args: [--style=file, --version=18, --verbose] # Add -v or --verbose for detailed output
Expand Down
2 changes: 2 additions & 0 deletions cpp_linter_hooks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
"20.1.5",
"20.1.6",
"20.1.7",
"20.1.8",
"21.1.0",
]

CLANG_TIDY_VERSIONS = [
Expand Down
2 changes: 1 addition & 1 deletion MIGRATION.md → docs/migration-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Migration: From Clang Tools Binaries to Python Wheels
# Migration from Clang Tools Binaries to Python Wheels

## Overview

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tracker = "https://github.com/cpp-linter/cpp-linter-hooks/issues"
[project.optional-dependencies]
# only clang tools can added to this section to make hooks work
tools = [
"clang-format==20.1.7",
"clang-format==21.1.0",
"clang-tidy==20.1.0",
]

Expand Down
4 changes: 2 additions & 2 deletions testing/pre-commit-config-verbose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ repos:
rev: HEAD
hooks:
- id: clang-format
args: [--style=file, --version=16, --verbose] # test with verbose output
args: [--style=file, --version=21, --verbose] # test with verbose output
- repo: .
rev: HEAD
hooks:
- id: clang-format
args: [--style=file, --version=16, -v] # test with verbose output
args: [--style=file, --version=21, -v] # test with verbose output
7 changes: 7 additions & 0 deletions testing/pre-commit-config-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ repos:
args: [--style=file, --version=20]
- id: clang-tidy
args: [--checks=.clang-tidy, --version=20]
- repo: .
rev: HEAD
hooks:
- id: clang-format
args: [--style=file, --version=21]
- id: clang-tidy
args: [--checks=.clang-tidy, --version=20] # clang-tidy does not support version 21
2 changes: 1 addition & 1 deletion testing/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ failed_cases=`grep -c "Failed" result.txt`

echo $failed_cases " cases failed."

if [ $failed_cases -eq 9 ]; then
if [ $failed_cases -eq 10 ]; then
echo "=============================="
echo "Test cpp-linter-hooks success."
echo "=============================="
Expand Down
2 changes: 2 additions & 0 deletions tests/test_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
(["--style=Google", "--version=18"], (0, "")),
(["--style=Google", "--version=19"], (0, "")),
(["--style=Google", "--version=20"], (0, "")),
(["--style=Google", "--version=21"], (0, "")),
),
)
def test_run_clang_format_valid(args, expected_retval, tmp_path):
Expand All @@ -40,6 +41,7 @@ def test_run_clang_format_valid(args, expected_retval, tmp_path):
(["--style=Google", "--version=18"], 1),
(["--style=Google", "--version=19"], 1),
(["--style=Google", "--version=20"], 1),
(["--style=Google", "--version=21"], 1),
),
)
def test_run_clang_format_invalid(args, expected_retval, tmp_path):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_clang_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def generate_compilation_database():
(['--checks="boost-*"', "--version=18"], 1),
(['--checks="boost-*"', "--version=19"], 1),
(['--checks="boost-*"', "--version=20"], 1),
(['--checks="boost-*"', "--version=21"], 1),
),
)
def test_run_clang_tidy_valid(args, expected_retval):
Expand All @@ -43,6 +44,7 @@ def test_run_clang_tidy_valid(args, expected_retval):
(['--checks="boost-*"', "--version=18"], 1),
(['--checks="boost-*"', "--version=19"], 1),
(['--checks="boost-*"', "--version=20"], 1),
(['--checks="boost-*"', "--version=21"], 1),
),
)
def test_run_clang_tidy_invalid(args, expected_retval, tmp_path):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def test_get_version_from_dependency_malformed_toml():
"user_input,expected",
[
(None, None),
("20", "20.1.7"), # Should find latest 20.x
("20.1", "20.1.7"), # Should find latest 20.1.x
("20", "20.1.8"), # Should find latest 20.x
("20.1", "20.1.8"), # Should find latest 20.1.x
("20.1.7", "20.1.7"), # Exact match
("18", "18.1.8"), # Should find latest 18.x
("18.1", "18.1.8"), # Should find latest 18.1.x
Expand Down
Loading