Browse Source

Meta: Print commit hook scripts via function

master
Riyyi 2 years ago
parent
commit
b5e55f13d3
  1. 22
      script/lint-clang-format.sh
  2. 19
      script/lint-shell-script.sh

22
script/lint-clang-format.sh

@ -5,13 +5,17 @@
# ------------------------------------------ # ------------------------------------------
b="$(tput bold)" error() {
red="$(tput setf 4)" b="$(tput bold)"
n="$(tput sgr0)" red="$(tput setf 4)"
n="$(tput sgr0)"
echo "${b}${red}Error:${n} $1" >&2
exit 1
}
if [ ! -d ".git" ]; then if [ ! -d ".git" ]; then
echo "${b}${red}Error:${n} please run this script from the project root" >&2 error "please run this script from the project root"
exit 1
fi fi
formatter=false formatter=false
@ -20,13 +24,11 @@ if command -v clang-format-11 >/dev/null 2>&1; then
elif command -v clang-format >/dev/null 2>&1; then elif command -v clang-format >/dev/null 2>&1; then
formatter="clang-format" formatter="clang-format"
if ! "$formatter" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 11) exit 1; }'; then if ! "$formatter" --version | awk '{ if (substr($NF, 1, index($NF, ".") - 1) < 11) exit 1; }'; then
echo "You are using '$("${CLANG_FORMAT}" --version)', which appears to not be clang-format 11 or later." error "you are using '$("${formatter}" --version)', which appears to not be clang-format 11 or later."
exit 1
fi fi
else else
echo "clang-format-11 is not available, but C++ files need linting!" error "clang-format-11 is not available, but C++ files need linting!
echo "Either skip this script, or install clang-format-11." Either skip this script, or install clang-format-11."
exit 1
fi fi
files="${1:-$(git --no-pager diff --cached --name-only)}" files="${1:-$(git --no-pager diff --cached --name-only)}"

19
script/lint-shell-script.sh

@ -5,19 +5,22 @@
# ------------------------------------------ # ------------------------------------------
b="$(tput bold)" error() {
red="$(tput setf 4)" b="$(tput bold)"
n="$(tput sgr0)" red="$(tput setf 4)"
n="$(tput sgr0)"
echo "${b}${red}Error:${n} $1" >&2
exit 1
}
if [ ! -d ".git" ]; then if [ ! -d ".git" ]; then
echo "${b}${red}Error:${n} please run this script from the project root" >&2 error "please run this script from the project root"
exit 1
fi fi
if ! command -v shellcheck > /dev/null 2>&1; then if ! command -v shellcheck > /dev/null 2>&1; then
echo "shellcheck is not available, but shell script files need linting!" error "shellcheck is not available, but shell-script files need linting!
echo "Either skip this script, or install shellcheck." Either skip this script, or install shellcheck."
exit 1
fi fi
files="${1:-$(git --no-pager diff --cached --name-only)}" files="${1:-$(git --no-pager diff --cached --name-only)}"

Loading…
Cancel
Save