From d3d697966399e3b2f2fb1bfc6535481555b0c30b Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 17:52:49 +0300 Subject: [PATCH 1/7] feat: support clang v21 --- .pre-commit-config.yaml | 4 ++-- cpp_linter_hooks/util.py | 3 ++- pyproject.toml | 2 +- tests/test_clang_format.py | 2 ++ tests/test_clang_tidy.py | 2 ++ tests/test_util.py | 4 ++-- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b5a3cb..9f3f80d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 13a7efc..6ceb73c 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -102,7 +102,8 @@ def get_version_from_dependency(tool: str) -> Optional[str]: "20.1.4", "20.1.5", "20.1.6", - "20.1.7", + "20.1.8", + "21.1.0", ] CLANG_TIDY_VERSIONS = [ diff --git a/pyproject.toml b/pyproject.toml index 816601f..1d8162a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/tests/test_clang_format.py b/tests/test_clang_format.py index 314e87f..84ddd57 100644 --- a/tests/test_clang_format.py +++ b/tests/test_clang_format.py @@ -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): @@ -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): diff --git a/tests/test_clang_tidy.py b/tests/test_clang_tidy.py index 887fd00..1ef35ee 100644 --- a/tests/test_clang_tidy.py +++ b/tests/test_clang_tidy.py @@ -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): @@ -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): diff --git a/tests/test_util.py b/tests/test_util.py index 48cc448..6b3d806 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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 From e2f84c910338cdc9ba12e48e04ea50fa3bf1f71e Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 17:56:03 +0300 Subject: [PATCH 2/7] feat: bump version to 1.1.0 --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 213ba9a..07594df 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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 @@ -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 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). ## Output @@ -147,11 +147,11 @@ 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] @@ -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 From e9d84fd3e5d5034f5234847aba48751997d6428e Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 18:01:25 +0300 Subject: [PATCH 3/7] fix: add version 20.1.7 back --- cpp_linter_hooks/util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 6ceb73c..ec24431 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -102,6 +102,7 @@ def get_version_from_dependency(tool: str) -> Optional[str]: "20.1.4", "20.1.5", "20.1.6", + "20.1.7", "20.1.8", "21.1.0", ] From 0b8f9ab2af977214357b9d3b1699c7a696901451 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 18:11:59 +0300 Subject: [PATCH 4/7] docs: update readme and migration notes --- README.md | 2 +- MIGRATION.md => docs/migration-notes.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename MIGRATION.md => docs/migration-notes.md (97%) diff --git a/README.md b/README.md index 07594df..7a0e717 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ repos: ``` > [!NOTE] -> Starting from version v1.0.0, this pre-commit hook 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 diff --git a/MIGRATION.md b/docs/migration-notes.md similarity index 97% rename from MIGRATION.md rename to docs/migration-notes.md index 95b5f94..df08aa7 100644 --- a/MIGRATION.md +++ b/docs/migration-notes.md @@ -1,4 +1,4 @@ -# Migration: From Clang Tools Binaries to Python Wheels +# Migration from Clang Tools Binaries to Python Wheels ## Overview From cd08d501b29d375010a62b2d11e180c5fc24df6d Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 18:45:39 +0300 Subject: [PATCH 5/7] docs: update defacult version --- README.md | 4 ++-- testing/pre-commit-config-verbose.yaml | 4 ++-- testing/pre-commit-config-version.yaml | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a0e717..21cfb5a 100644 --- a/README.md +++ b/README.md @@ -154,10 +154,10 @@ Use -header-filter=.* to display errors from all non-system headers. Use -system 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)$ ``` diff --git a/testing/pre-commit-config-verbose.yaml b/testing/pre-commit-config-verbose.yaml index adac182..54852f8 100644 --- a/testing/pre-commit-config-verbose.yaml +++ b/testing/pre-commit-config-verbose.yaml @@ -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 diff --git a/testing/pre-commit-config-version.yaml b/testing/pre-commit-config-version.yaml index dbb8f55..f00095d 100644 --- a/testing/pre-commit-config-version.yaml +++ b/testing/pre-commit-config-version.yaml @@ -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=21] From 4975283ef860cd8cb8f113878f11922b307143ed Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 21:32:37 +0300 Subject: [PATCH 6/7] fix: clang-tidy does not support v21 --- testing/pre-commit-config-version.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/pre-commit-config-version.yaml b/testing/pre-commit-config-version.yaml index f00095d..16573f4 100644 --- a/testing/pre-commit-config-version.yaml +++ b/testing/pre-commit-config-version.yaml @@ -40,4 +40,4 @@ repos: - id: clang-format args: [--style=file, --version=21] - id: clang-tidy - args: [--checks=.clang-tidy, --version=21] + args: [--checks=.clang-tidy, --version=20] # clang-tidy does not support version 21 From 008459bc89c35f880c5b16e9ec2f45b158abb43c Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Sat, 30 Aug 2025 21:40:28 +0300 Subject: [PATCH 7/7] chore: update failed case number --- testing/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/run.sh b/testing/run.sh index 3407656..b176b06 100644 --- a/testing/run.sh +++ b/testing/run.sh @@ -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 "=============================="