How to make go linters ignore the / provider?

How to make go vet, gofmtand other tools Go linter ignore files in third-party vendor/, preferably with a precise, total output status?

For example, if it find . -name vendor -prune -o -name '*.go' -exec gofmt -s -w {} \;displayed a significant exit status?

+4
source share
6 answers

I usually do

go fmt $(go list ./... | grep -v /vendor/)
go test $(go list ./... | grep -v /vendor/)

But since I started using govendor, I found that I can do the same with govendor with less input

govendor fmt +l // +l is shorthand for local
+4
source

Usually go listmore useful than findhere:

$ 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..]

, . vendor, grep:

$ go list ./... | grep -v /vendor/
arp242.net/trackwall
arp242.net/trackwall/cmdline

, 0 , :

#!/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

- :

==> 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

, , , , , . gometalinter, , , . --vendor , :

$ 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..]
+2

(, internal lib). :

go vet ./... | grep -v vendor/ && exit 1 || exit 0
0

- philea -s "666 go vet %s" "666 go-fmt-fail %s"

,

$ ls -alh | grep ven
drwxr-xr-x  5 mh-cbon mh-cbon 4,0K 14 juin  20:43 vendor
$ philea -s "666 go vet %s" "666 go-fmt-fail %s"
go-fmt-fail ./local/local.go
 โœ” Success
go-fmt-fail ./dl/index.go
 โœ” Success
go vet ./local/local.go
 โœ” Success
go-fmt-fail ./gh/gh.go
 โœ” Success
go vet ./main.go
 โœ” Success
go vet ./gh/gh.go
 โœ” Success
go vet ./dl/index.go
 โœ” Success
go-fmt-fail ./main.go
 โœ” Success
0

Go 1.10 (Q1 2018), , OP mcandre :

go list ./... | grep -v vendor | xargs go vet -v

carpetsmoker answer, go vet ( -) :

==> arp242.net/trackwall
http.go:71: database/sql.NullString composite literal uses unkeyed fields

, go issue 16086 !

. :

Go vet

"go vet" , . : cgo, , , - , vet .

. go vet vet , .a (CL 74355 CL 74750).
"go vet" , .
.a , .

Only " go vet" has this guarantee. Do not use " go tool vet", which is essentially only useful for people working with vet(just like you usually don't run " go tool compile").
Previously, you had to use " go tool vet" if you needed control over the veterinary flags, but " go vet" now accepts all the flags that the " go tool vet" executes . (See " go help vet".)

0
source

Source: https://habr.com/ru/post/1660419/


All Articles