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/README.md b/README.md index 213ba9a..21cfb5a 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 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 @@ -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)$ ``` @@ -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 diff --git a/cpp_linter_hooks/util.py b/cpp_linter_hooks/util.py index 13a7efc..ec24431 100644 --- a/cpp_linter_hooks/util.py +++ b/cpp_linter_hooks/util.py @@ -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 = [ 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 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/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..16573f4 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=20] # clang-tidy does not support version 21 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 "==============================" 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