Skip to content

Instantly share code, notes, and snippets.

View zgordan-vv's full-sized avatar

Vyacheslav Zgordan zgordan-vv

View GitHub Profile
@bgentry
bgentry / gist:fd1ffef7dbde01857f66
Last active March 25, 2020 17:56
Using gofmt or goimports on only my own Go files (excluding vendored deps)

In Travis CI, I want to check that my Go files are formatted properly via gofmt and goimports. During my CI builds, I only care about formatting issues in my own code, not in third-party repos.

Unfortunately, running a simple gofmt -l . in the root of my project does not work because I'm using Godep, which checks in all of my external dependencies at ./Godep/_workspace. While running go fmt ./... ignores underscore-prefixed subdirectories, the plain gofmt . does not. Neither gofmt nor goimports take the ./... arg:

➜  goimports -l ./...      
stat ./...: no such file or directory

Since I can use go list ./... to get a list of all subpackages in my project (exluding vendored imports in an underscore-prefixed directory), I'm using the following to run gofmt and goimports on each of my own Go files (including _test.go files):