Linter that matches Go file naming patterns to their expected build tags.
Jump to Installation and usage
Match file naming patterns to build tags and make sure these files always have the expected build tags in the // +build
instruction.
Example: files named foo.go
must include the bar
build tag.
File: foo.go
// +build bar
package foo
Example: files ending with _suffix.go
must include the bar
build tag.
File: a_suffix.go
// +build bar
package foo
File: b_suffix.go
// +build bar
package foo
Built on top of the buildtag
linter, it supports its Go files features.
- Run it as a standalone command
- Integrate it as a part of a runner using the provided
analysis.Analyzer
Let's say you name your integration tests *_integration_test.go
and you run them as part of your CI pipeline.
You might forget to add the // +build integration
instruction on a newly created file, or you might remove it inadvertently,
and it can have some consequences, such as never running during your pipeline.
As a consequence, you think your code works when it doesn't, because it is not tested (but you believe it is).
This linter can help with such issues and let you know when you forgot to add the expected build tags.
Install with Go install
GO111MODULE=on go get github.com/aziule/filebuildtag/cmd/filebuildtag
Install and build from source
- Clone the repo
- Build the executable
make build
Usage
// All files named "foo.go" must have the "bar" tag
filebuildtag --filetags foo.go:bar ./...
// All files ending with "_integration_test.go" must have the "integration" tag
filebuildtag --filetags *_integration_test.go:integration ./...
// Both of the above
filebuildtag --filetags foo.go:bar,*_integration_test.go:integration ./...
// Only check that the `// +build` instructions are correct (no args to pass)
filebuildtag ./...
Note: files naming patterns are matched using Go's filepath.Match
method. Therefore, you can use any of its supported patterns.
See File patterns for more information and examples.
This linter exposes an Analyzer
(accessible via filebuildtag.Analyzer
), which is defined as
a golang.org/x/tools/go/analysis/analysis.Analyzer
struct.
Most of the linters runners expect linters to be defined like so, therefore you should not have much trouble integrating it following the linters runner's doc.