Go Tools as DepsBack
Scenario: I want to run golangci-lint
occasionally or in CI to make sure I'm not doing bad things. BUT since it's not in my code
I can't add it to the
Solution!!!! Create a file called
tools.go with the following content:
//go:build tools // +build tools package tools import ( _ "github.com/golangci/golangci-lint/cmd/golangci-lint" )
Now we can run
and it'll stay in the mod file since it's in the code, but will never actually be built.
go get github.com/golangci/golangci-lint/cmd/golangci-lint
And now when we test it out:
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --color always -v -c ./.golangci.yml INFO [config_reader] Used config file .golangci.yml INFO [lintersdb] Active 9 linters: [errcheck gofmt gosimple govet ineffassign nestif staticcheck typecheck unused] ... ...