dnephin/pre-commit-golang

[BUG] goimports: command not found

viniciussousazup opened this issue · 2 comments

our team is using the master version of pre-commit-golang but we had to rollback to version 0.4.0 because the pipeline return error:

Check JSON...............................................................Passed
Check for merge conflicts................................................Passed
Check Yaml...............................................................Passed
Detect Private Key.......................................................Passed
Pretty format JSON.......................................................Passed
Trim Trailing Whitespace.................................................Passed
Detect Private Key.......................................................Passed
Flake8 (deprecated, use gitlab.com/pycqa/flake8).....(no files to check)Skipped
Check python ast.....................................(no files to check)Skipped
Fix End of Files.........................................................Passed
markdownlint.............................................................Passed
go fmt...................................................................Passed
go imports...............................................................Failed
- hook id: go-imports
- exit code: 127

/home/runner/.cache/pre-commit/repomiw2ezxk/run-go-imports.sh: line 8: goimports: command not found
/home/runner/.cache/pre-commit/repomiw2ezxk/run-go-imports.sh: line 8: goimports: command not found

hmm, this does not seem like a bug to me. The reason #69 was done was to catch exactly this problem. Previously you were not actually running goimports, but it was failing silently. Now it fails loudly when it can't run, which seems like the right behaviour.

I think you want to either install goimports, or remove that hook from your list of hooks to run.

I think you want to either install goimports, or remove that hook from your list of hooks to run.

@dnephin what is the reasoning to not add a condition like the one below to all the Shell scripts?

--- run-go-imports.sh
+++ run-go-imports.sh
@@ -4,6 +4,10 @@
 #
 set -e -o pipefail

+if ! command -v goimports &>/dev/null ; then
+	go get golang.org/x/tools/cmd/goimports
+fi
+
 exec 5>&1
 output="$(goimports -l -w "$@" | tee /dev/fd/5)"
 [[ -z "$output" ]]