Skip to content

Commit

Permalink
Pre-commit hook: fix staticcheck version selection by go version (#595)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Cathcart <stephen.cathcart@neo4j.com>
  • Loading branch information
robsdedude and StephenCathcart authored Aug 16, 2024
1 parent 6ecad42 commit 778d6ba
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 778d6ba

Please sign in to comment.