diff --git a/.clang-format b/.clang-format index a105b7df33..4c628b3465 100644 --- a/.clang-format +++ b/.clang-format @@ -1,10 +1,5 @@ # Clang-format configuration for Zeek. This configuration requires # at least clang-format 12.0.1 to format correctly. -# -# The easiest way to run this from the command-line is using the -# python script in auxil/run-clang-format: -# -# python3 auxil/run-clang-format/run-clang-format.py --clang-format-executable /path/to/clang-format -r src -i Language: Cpp Standard: c++17 @@ -102,4 +97,4 @@ IncludeCategories: - Regex: '^"zeek/' Priority: 4 - Regex: '.*' - Priority: 5 \ No newline at end of file + Priority: 5 diff --git a/.clang-format-ignore b/.clang-format-ignore deleted file mode 100644 index bb01885b01..0000000000 --- a/.clang-format-ignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore everything 3rdparty -src/3rdparty/* diff --git a/.gitmodules b/.gitmodules index e3b149e9f9..4318212fe0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -49,6 +49,3 @@ [submodule "auxil/zeek-client"] path = auxil/zeek-client url = https://github.com/zeek/zeek-client -[submodule "auxil/run-clang-format"] - path = auxil/run-clang-format - url = https://github.com/Sarcasm/run-clang-format diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..f3f52012a1 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +# +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: 'v13.0.0' + hooks: + - id: clang-format diff --git a/auxil/run-clang-format b/auxil/run-clang-format deleted file mode 160000 index 39081c9c42..0000000000 --- a/auxil/run-clang-format +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 39081c9c42768ab5e8321127a7494ad1647c6a2f diff --git a/ci/run-clang-format.sh b/ci/run-clang-format.sh deleted file mode 100755 index 3bd6d5d898..0000000000 --- a/ci/run-clang-format.sh +++ /dev/null @@ -1,65 +0,0 @@ -#! /bin/sh -# -# Copyright (c) 2020 by the Zeek Project. See LICENSE for details. - -base=$(git rev-parse --show-toplevel) -fix=0 -pre_commit_hook=0 - -# Directories to run on by default. When changing, adapt .pre-commit-config.yam -# as well. -files="src" - -error() { - test "${pre_commit_hook}" = 0 && echo "$@" >&2 && exit 1 - exit 0 -} - -if [ $# != 0 ]; then - case "$1" in - --fixit) - shift - fix=1 - ;; - - --pre-commit-hook) - shift - fix=1 - pre_commit_hook=1 - ;; - - -*) - echo "usage: $(basename $0) [--fixit | --pre-commit-hook] []" - exit 1 - esac -fi - -test $# != 0 && files="$@" - -if [ -z "${CLANG_FORMAT}" ]; then - CLANG_FORMAT=$(which clang-format 2>/dev/null) -fi - -if [ -z "${CLANG_FORMAT}" -o ! -x "${CLANG_FORMAT}" ]; then - error "Cannot find clang-format. If not in PATH, set CLANG_FORMAT." -fi - -if ! (cd / && ${CLANG_FORMAT} -dump-config | grep -q SpacesInConditionalStatement); then - error "${CLANG_FORMAT} does not support SpacesInConditionalStatement. Install custom version and put it into PATH, or point CLANG_FORMAT to it." -fi - -if [ ! -e .clang-format ]; then - error "Must execute in top-level directory." -fi - -cmd="${base}/auxil/run-clang-format/run-clang-format.py -r --clang-format-executable ${CLANG_FORMAT} --exclude '*/3rdparty/*' ${files}" -tmp=/tmp/$(basename $0).$$.tmp -trap "rm -f ${tmp}" EXIT -eval "${cmd}" >"${tmp}" - -if [ "${fix}" = 1 ]; then - test -s "${tmp}" && cat "${tmp}" | git apply -p0 - true -else - cat "${tmp}" -fi