Skip to content

Commit

Permalink
check clang-format version (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed Jun 24, 2024
1 parent 401b5db commit a31348b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
15 changes: 12 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
exclude: '.*\.(pcap|pcapng|dat|txt)'
fail_fast: false
repos:
- repo: local
hooks:
- id: check-clang-format-version
name: Check clang-format version
entry: ./ci/check-clang-format-version.sh
language: script
- id: clang-format
name: Clang format
entry: clang-format
language: system
args: ["--style=file"] # Use the .clang-format file for configuration
files: ^Common\+\+/.*\.(cpp|h)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand All @@ -16,9 +28,6 @@ repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: ["--style=file"] # Use the .clang-format file for configuration
files: ^Common\+\+/.*\.(cpp|h)$
- id: cppcheck
args: ["--std=c++11", "--language=c++", "--suppressions-list=cppcheckSuppressions.txt", "--inline-suppr", "--force"]
- repo: https://github.com/codespell-project/codespell
Expand Down
12 changes: 12 additions & 0 deletions ci/check-clang-format-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
EXPECTED_VERSION="18.1.6"

# Get the installed clang-format version
INSTALLED_VERSION=$(clang-format --version | grep -oE '[0-9]+(\.[0-9]+)+')

if [ "$INSTALLED_VERSION" != "$EXPECTED_VERSION" ]; then
echo "Error: clang-format version $INSTALLED_VERSION found, but $EXPECTED_VERSION is required."
exit 1
fi

exit 0

0 comments on commit a31348b

Please sign in to comment.