From 778d6babad28b33d59027ad23229f2a491438602 Mon Sep 17 00:00:00 2001 From: Robsdedude Date: Fri, 16 Aug 2024 12:11:11 +0200 Subject: [PATCH] Pre-commit hook: fix staticcheck version selection by go version (#595) Co-authored-by: Stephen Cathcart --- hooks/pre-commit | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index e9b6326d..c4ff1126 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -4,10 +4,22 @@ set -Eeuo pipefail grep_not(){ ! grep "${@}"; return $?;} -go_version=$(go version) +verlte() { + [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] +} + +verlt() { + [ "$1" = "$2" ] && return 1 || verlte $1 $2 +} + +go_version=$(go version | grep -o "go\([0-9.]\)\+" | grep -o "\([0-9.]\)\+") staticcheck_version="latest" -if [[ "${go_version}" == *"go1.18"* ]]; then +if verlt $go_version "1.19"; then # go 1.18 and below staticcheck_version="v0.3.3" +elif verlt $go_version "1.20"; then # go 1.19 and below + staticcheck_version="v0.4.7" +elif verlt $go_version "1.22.1"; then + staticcheck_version="v0.4.7" fi echo "# pre-commit hook"