diff --git a/filebuildtag.go b/filebuildtag.go index 60cf010..8cdf4c2 100644 --- a/filebuildtag.go +++ b/filebuildtag.go @@ -14,12 +14,20 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -// Doc of the linter. -const Doc = `check that Go files have the expected build tags in the "// +build" instruction +const ( + // Doc of the linter. + Doc = `check that Go files have the expected build tags in the "// +build" instruction Bind file patterns to build tags, for instance: File named "bar.go" must have the "baz" build tag Files matching "*_integration_test.go" must have the "integration" build tag` + // FlagFiletagsName is the name of the default filetags flag. It is exported to be reused from linters runners. + FlagFiletagsName = "filetags" + // FlagFiletagsDoc is the usage doc of the default filetags flag. It is exported to be reused from linters runners. + FlagFiletagsDoc = `Comma separated list of file names and build tags using the form "pattern:tag". For example: +- Single file: "*foo.go:tag1" +- Multiple files: "*foo.go:tag1,*foo2.go:tag2"` +) var Analyzer = &analysis.Analyzer{ Name: "filebuildtag", @@ -29,15 +37,9 @@ var Analyzer = &analysis.Analyzer{ Requires: []*analysis.Analyzer{inspect.Analyzer}, } -const flagFiletagsDoc = `Comma separated list of file names and build tags using the form "pattern:tag". For example: -- Single file: "*foo.go:tag1" -- Multiple files: "*foo.go:tag1,*foo2.go:tag2"` - -const flagFiletagsName = "filetags" - func flags() flag.FlagSet { fs := flag.NewFlagSet("", flag.ExitOnError) - fs.String(flagFiletagsName, "", flagFiletagsDoc) + fs.String(FlagFiletagsName, "", FlagFiletagsDoc) return *fs } @@ -79,7 +81,7 @@ func run(pass *analysis.Pass) (interface{}, error) { func parseFlags(flags flag.FlagSet) (map[string]string, error) { filetags := make(map[string]string) - f := flags.Lookup(flagFiletagsName) + f := flags.Lookup(FlagFiletagsName) if f == nil { return filetags, nil } diff --git a/filebuildtag_test.go b/filebuildtag_test.go index 5520984..9e40871 100644 --- a/filebuildtag_test.go +++ b/filebuildtag_test.go @@ -102,7 +102,7 @@ func Test_parseFlags(t *testing.T) { func newFlagSet(t *testing.T, args string) flag.FlagSet { fs := flags() - err := fs.Set(flagFiletagsName, args) + err := fs.Set(FlagFiletagsName, args) require.NoError(t, err) return fs }