summaryrefslogtreecommitdiff
path: root/Meta/lint-clang-format.sh
diff options
context:
space:
mode:
authorAndrew Kaster <andrewdkaster@gmail.com>2021-01-10 00:20:21 -0700
committerAndreas Kling <kling@serenityos.org>2021-01-10 16:39:21 +0100
commit9e5aa6f794ef9ab5828d5874c2e40de9a4fa8349 (patch)
treebb2918d12e19ff08f123e286f5b90d7c9bbe8e77 /Meta/lint-clang-format.sh
parent190e0e155130e09dc9c9b7a0989cdb0ef8c55a7d (diff)
downloadserenity-9e5aa6f794ef9ab5828d5874c2e40de9a4fa8349.zip
Meta: Only complain about linter tools if relevant files have changed
Diffstat (limited to 'Meta/lint-clang-format.sh')
-rwxr-xr-xMeta/lint-clang-format.sh52
1 files changed, 26 insertions, 26 deletions
diff --git a/Meta/lint-clang-format.sh b/Meta/lint-clang-format.sh
index 00a34c228e..b99112061a 100755
--- a/Meta/lint-clang-format.sh
+++ b/Meta/lint-clang-format.sh
@@ -5,32 +5,6 @@ set -e
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
cd "${script_path}/.." || exit 1
-CLANG_FORMAT=false
-if command -v clang-format-11 >/dev/null 2>&1 ; then
- CLANG_FORMAT=clang-format-11
-elif command -v clang-format >/dev/null 2>&1 ; then
- CLANG_FORMAT=clang-format
- if ! "${CLANG_FORMAT}" --version | grep -qF ' 11.' ; then
- echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 11."
- echo "It is very likely that the resulting changes are not what you wanted."
- fi
-else
- echo "clang-format-10 is not available. Either skip this script, or install clang-format-11."
- echo "(If you install a package 'clang-format', please make sure it's version 11.)"
- exit 1
-fi
-
-if [ "$#" -gt "0" ] && [ "x--overwrite-inplace" = "x$1" ] ; then
- true # The only way to run this script.
-else
- # Note that this branch also covers --help, -h, -help, -?, etc.
- echo "USAGE: $0 --overwrite-inplace"
- echo "The argument is necessary to make you aware that this *will* overwrite your local files."
- exit 1
-fi
-
-echo "Using ${CLANG_FORMAT}"
-
if [ "$#" -eq "1" ]; then
mapfile -t files < <(
git ls-files -- \
@@ -55,6 +29,32 @@ else
fi
if (( ${#files[@]} )); then
+ CLANG_FORMAT=false
+ if command -v clang-format-11 >/dev/null 2>&1 ; then
+ CLANG_FORMAT=clang-format-11
+ elif command -v clang-format >/dev/null 2>&1 ; then
+ CLANG_FORMAT=clang-format
+ if ! "${CLANG_FORMAT}" --version | grep -qF ' 11.' ; then
+ echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 11."
+ echo "It is very likely that the resulting changes are not what you wanted."
+ fi
+ else
+ echo "clang-format-11 is not available, but C or C++ files need linting! Either skip this script, or install clang-format-11."
+ echo "(If you install a package 'clang-format', please make sure it's version 11.)"
+ exit 1
+ fi
+
+ if [ "$#" -gt "0" ] && [ "x--overwrite-inplace" = "x$1" ] ; then
+ true # The only way to run this script.
+ else
+ # Note that this branch also covers --help, -h, -help, -?, etc.
+ echo "USAGE: $0 --overwrite-inplace"
+ echo "The argument is necessary to make you aware that this *will* overwrite your local files."
+ exit 1
+ fi
+
+ echo "Using ${CLANG_FORMAT}"
+
"${CLANG_FORMAT}" -style=file -i "${files[@]}"
echo "Maybe some files have changed. Sorry, but clang-format doesn't indicate what happened."
else