From b1b4b32ca6f93155a82f891ec6686c2abdfd226c Mon Sep 17 00:00:00 2001 From: Tate Date: Tue, 30 Apr 2024 13:01:21 -0600 Subject: [PATCH] go-lint pre-commit fix the fix command and show issues (#935) --- .githooks/go-lint | 6 ++++-- .githooks/go-mod-tidy | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.githooks/go-lint b/.githooks/go-lint index dd01d8df3..f2f2c4879 100755 --- a/.githooks/go-lint +++ b/.githooks/go-lint @@ -6,13 +6,15 @@ find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do cd "$directory" || exit 1 # Run linter and capture exit status - golangci-lint run > /dev/null + set +e + golangci-lint run linting_result=$? + set -e # Check linting result if [[ $linting_result -ne 0 ]]; then echo -e "Executing linters in $directory... \e[31mNOK!\e[0m\n" - echo -e "Run \`cd $directory && golangci-lint run -fix -v\` and fix the issues\n" + echo -e "Run \`cd $directory && golangci-lint run --fix -v\` and fix the issues\n" exit 1 else echo -e "Executing linters in $directory... \e[32mOK!\e[0m\n" diff --git a/.githooks/go-mod-tidy b/.githooks/go-mod-tidy index 0a5f019c2..ef29270a7 100755 --- a/.githooks/go-mod-tidy +++ b/.githooks/go-mod-tidy @@ -1,14 +1,14 @@ #!/bin/bash -set -e +set +e # Find all 'go.mod' files, get their directories, and run 'go mod tidy' find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do dir=$(dirname "$file") echo "Executing cd \"$dir\" && go mod tidy" - cd "$dir" + cd "$dir" || exit 1 go mod tidy - cd - + cd - || exit 1 done # pre-commit stashes changes before running the hooks so we can use git to check for changes here # Run git diff and capture output