Skip to content

Commit 8b2b307

Browse files
authored
feat: support clang-format v21 (#97)
* feat: support clang v21 * feat: bump version to 1.1.0 * fix: add version 20.1.7 back * docs: update readme and migration notes * docs: update defacult version * fix: clang-tidy does not support v21 * chore: update failed case number
1 parent 924f4de commit 8b2b307

File tree

11 files changed

+31
-18
lines changed

11 files changed

+31
-18
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
@@ -14,7 +14,7 @@ repos:
1414
hooks:
1515
- id: pyupgrade
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.12.2
17+
rev: v0.12.11
1818
hooks:
1919
- id: ruff
2020
- id: ruff-format

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Add this configuration to your `.pre-commit-config.yaml` file:
3131
```yaml
3232
repos:
3333
- repo: https://github.com/cpp-linter/cpp-linter-hooks
34-
rev: v1.0.1 # Use the tag or commit you want
34+
rev: v1.1.0 # Use the tag or commit you want
3535
hooks:
3636
- id: clang-format
3737
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`:
4646
```yaml
4747
repos:
4848
- repo: https://github.com/cpp-linter/cpp-linter-hooks
49-
rev: v1.0.1
49+
rev: v1.1.0
5050
hooks:
5151
- id: clang-format
5252
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
6161
```yaml
6262
repos:
6363
- repo: https://github.com/cpp-linter/cpp-linter-hooks
64-
rev: v1.0.1
64+
rev: v1.1.0
6565
hooks:
6666
- id: clang-format
6767
args: [--style=file, --version=18] # Specifies version
@@ -70,7 +70,7 @@ repos:
7070
```
7171

7272
> [!NOTE]
73-
> 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).
73+
> 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).
7474

7575
## Output
7676

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

149149
> [!TIP]
150-
> 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:
150+
> 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:
151151

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

@@ -177,7 +177,7 @@ This approach ensures that only modified files are checked, further speeding up
177177
```yaml
178178
repos:
179179
- repo: https://github.com/cpp-linter/cpp-linter-hooks
180-
rev: v1.0.1
180+
rev: v1.1.0
181181
hooks:
182182
- id: clang-format
183183
args: [--style=file, --version=18, --verbose] # Add -v or --verbose for detailed output

cpp_linter_hooks/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def get_version_from_dependency(tool: str) -> Optional[str]:
103103
"20.1.5",
104104
"20.1.6",
105105
"20.1.7",
106+
"20.1.8",
107+
"21.1.0",
106108
]
107109

108110
CLANG_TIDY_VERSIONS = [

MIGRATION.md renamed to docs/migration-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Migration: From Clang Tools Binaries to Python Wheels
1+
# Migration from Clang Tools Binaries to Python Wheels
22

33
## Overview
44

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tracker = "https://github.com/cpp-linter/cpp-linter-hooks/issues"
4848
[project.optional-dependencies]
4949
# only clang tools can added to this section to make hooks work
5050
tools = [
51-
"clang-format==20.1.7",
51+
"clang-format==21.1.0",
5252
"clang-tidy==20.1.0",
5353
]
5454

testing/pre-commit-config-verbose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ repos:
33
rev: HEAD
44
hooks:
55
- id: clang-format
6-
args: [--style=file, --version=16, --verbose] # test with verbose output
6+
args: [--style=file, --version=21, --verbose] # test with verbose output
77
- repo: .
88
rev: HEAD
99
hooks:
1010
- id: clang-format
11-
args: [--style=file, --version=16, -v] # test with verbose output
11+
args: [--style=file, --version=21, -v] # test with verbose output

testing/pre-commit-config-version.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ repos:
3434
args: [--style=file, --version=20]
3535
- id: clang-tidy
3636
args: [--checks=.clang-tidy, --version=20]
37+
- repo: .
38+
rev: HEAD
39+
hooks:
40+
- id: clang-format
41+
args: [--style=file, --version=21]
42+
- id: clang-tidy
43+
args: [--checks=.clang-tidy, --version=20] # clang-tidy does not support version 21

testing/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ failed_cases=`grep -c "Failed" result.txt`
2929

3030
echo $failed_cases " cases failed."
3131

32-
if [ $failed_cases -eq 9 ]; then
32+
if [ $failed_cases -eq 10 ]; then
3333
echo "=============================="
3434
echo "Test cpp-linter-hooks success."
3535
echo "=============================="

tests/test_clang_format.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
(["--style=Google", "--version=18"], (0, "")),
1515
(["--style=Google", "--version=19"], (0, "")),
1616
(["--style=Google", "--version=20"], (0, "")),
17+
(["--style=Google", "--version=21"], (0, "")),
1718
),
1819
)
1920
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):
4041
(["--style=Google", "--version=18"], 1),
4142
(["--style=Google", "--version=19"], 1),
4243
(["--style=Google", "--version=20"], 1),
44+
(["--style=Google", "--version=21"], 1),
4345
),
4446
)
4547
def test_run_clang_format_invalid(args, expected_retval, tmp_path):

tests/test_clang_tidy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def generate_compilation_database():
2222
(['--checks="boost-*"', "--version=18"], 1),
2323
(['--checks="boost-*"', "--version=19"], 1),
2424
(['--checks="boost-*"', "--version=20"], 1),
25+
(['--checks="boost-*"', "--version=21"], 1),
2526
),
2627
)
2728
def test_run_clang_tidy_valid(args, expected_retval):
@@ -43,6 +44,7 @@ def test_run_clang_tidy_valid(args, expected_retval):
4344
(['--checks="boost-*"', "--version=18"], 1),
4445
(['--checks="boost-*"', "--version=19"], 1),
4546
(['--checks="boost-*"', "--version=20"], 1),
47+
(['--checks="boost-*"', "--version=21"], 1),
4648
),
4749
)
4850
def test_run_clang_tidy_invalid(args, expected_retval, tmp_path):

0 commit comments

Comments
 (0)