Skip to content

Commit

Permalink
go-lint pre-commit fix the fix command and show issues (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Apr 30, 2024
1 parent df7962a commit b1b4b32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .githooks/go-lint
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions .githooks/go-mod-tidy
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b1b4b32

Please sign in to comment.