From e3cdbff78d5233e423e3fcb1209f72ffe40ab7a9 Mon Sep 17 00:00:00 2001 From: "anchi.liu" Date: Fri, 21 Jun 2024 16:51:22 +0900 Subject: [PATCH] check clang-format version --- .pre-commit-config.yaml | 15 ++++++++++++--- ci/check-clang-format-version.sh | 12 ++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 ci/check-clang-format-version.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13192b809c..0e8764b05e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: @@ -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 diff --git a/ci/check-clang-format-version.sh b/ci/check-clang-format-version.sh new file mode 100755 index 0000000000..ddb6aba2db --- /dev/null +++ b/ci/check-clang-format-version.sh @@ -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