Skip to content

Commit

Permalink
fix: support GO111MODULE packages without go files in root
Browse files Browse the repository at this point in the history
Some packages don't have any go files in the root directory, for
example, those following https://github.com/golang-standards/project-layout

In the case of a GO111MODULE package with go.mod in place, we can just
use "go list -m" and this will return the package name even without
any go files in the project root.

I've also updated the script to report all files that fail "go vet" in
a single run instead of exiting after finding the first error.

This is a fix for issue dnephin#30.
  • Loading branch information
wwade committed Feb 1, 2022
1 parent ff05dff commit 503834f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions run-go-vet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env bash
set -e
pkg=$(go list)
for dir in $(echo $@|xargs -n1 dirname|sort -u); do
go vet $pkg/$dir
set -eu
if [[ -f "go.mod" ]]; then
pkg=$(go list -m)
else
pkg=$(go list)
fi
ret=0
for dir in $(echo "$@"|xargs -n1 dirname|sort -u); do
go vet "$pkg/$dir" || ret=$?
done
exit $ret

0 comments on commit 503834f

Please sign in to comment.