1

I want to setup a CI system that it fails when code is not properly formatted according to goimports.

How I list my dirs:

go list -f {{.Dir}} ./...
/Users/felix/gocode/src/github.com/XXXX/YYY
/Users/felix/gocode/src/github.com/XXXX/YYY/cmd/foo
/Users/felix/gocode/src/github.com/XXXX/YYY/cmd/dev
/Users/felix/gocode/src/github.com/XXXX/YYY/pkg/monitoring/top

How I run goimports in the end:

goimports -l $(go list -f {{.Dir}} ./...)
/Users/felix/gocode/src/github.com/XXX/YYY/config.go
/Users/felix/gocode/src/github.com/XXX/YYY/raid_test.go
/Users/felix/gocode/src/github.com/XXX/YYY/vendor/github.com/shirou/gopsutil/disk/disk_freebsd.go
/Users/felix/gocode/src/github.com/XXX/YYY/vendor/github.com/shirou/gopsutil/disk/disk_linux.go
/Users/felix/gocode/src/github.com/XXX/YYY/vendor/golang.org/x/crypto/ssh/terminal/util_solaris.go

As you can see it also lists files within vendor. The execution also takes quite some time so I guess it's really checking all the files. I really just care about the files outside vendor.

soupdiver
  • 3,504
  • 9
  • 40
  • 68
  • 2
    Already answered here: https://stackoverflow.com/questions/47529611/goimports-needs-to-ignore-vendor-package Good luck! – Eelco Oct 26 '18 at 14:02

1 Answers1

0

I think you use <1.9 Go version. Since 1.9 ./... shouldn't match vendor directory. See https://golang.org/doc/go1.9#vendor-dotdotdot.

kopiczko
  • 3,018
  • 1
  • 17
  • 24