Usually go list
is more helpful than find
here:
$ go list ./...
arp242.net/trackwall
arp242.net/trackwall/cmdline
arp242.net/trackwall/vendor/arp242.net/sconfig
arp242.net/trackwall/vendor/bitbucket.org/pkg/inflect
[..trim..]
As you see, this will list all the package names in the current directory. To filter the vendor
directory we can use grep
:
$ go list ./... | grep -v /vendor/
arp242.net/trackwall
arp242.net/trackwall/cmdline
If you want to run several linters, report all errors, and return 0
only if there is a success, you could use a loop and a status variable:
#!/bin/sh
st=0
for pkg in $(go list ./... | grep -v /vendor/); do
echo "==> $pkg"
go vet "$pkg"
[ $? -ne 0 ] && st=1
golint "$pkg"
[ $? -ne 0 ] && st=1
# gofmt works on files, not packages
gofmt -d "${f#arp242.net/trackwall}"*.go
[ $? -ne 0 ] && st=1
done
exit $st
Which will output something like:
==> arp242.net/trackwall
http.go:71: database/sql.NullString composite literal uses unkeyed fields
exit status 1
/home/martin/gocode/src/arp242.net/trackwall/http.go:70:2: don't use ALL_CAPS in Go names; use CamelCase
/home/martin/gocode/src/arp242.net/trackwall/http.go:75:9: if block ends with a return statement, so drop this else and outdent its block
==> arp242.net/trackwall/cmdline
Exit 1
Of course, you're not the first one with this problem, and there are tools which basically do the same as above, except better. gometalinter is probably the best known and I recommend you use this. It helpfully includes a --vendor
switch to ignore the vendor directory:
$ go get -u github.com/alecthomas/gometalinter
$ gometalinter --vendor ./...
helpers.go:25:1:warning: realpath is unused (deadcode)
http.go:32:1:warning: _list is unused (deadcode)
[..trim..]