nolint
Nolint will make the go/analysis linters
be able to ignore diagnostics with //nolint comment
Install
go get github.com/kyoh86/nolint
Usage
For linter users
If you are using the linters which using the nolint,
you can ignore (like below) diagnostics that they reported.
for _, p := []int{10, 11, 12} {
t.Run("dummy", func(t *testing.T) {
foo.Bar(&p) // nolint
})
}// nolint will be ignore all diagnostics in the line.
And you can specify categories which you want to ignore.
// nolint:someCategory,anotherCategoryFor custom linter users
If you are using the linters with go/analysis/xxxxchecker,
linters can be wrapped like below.
multichecker.Main(
nolint.WrapAll(
exportloopref.Analyzer,
bodyclose.Analyzer,
// ...
),
)
Then, diagnostics will be able to be ignored with a comment.
// nolintFor linter creators
If you are creator of go/analysis linters,
use the nolint.Analyzer like below.
var Analyzer = &analysis.Analyzer{
Run: run,
Requires: []*analysis.Analyzer{nolint.Analyzer},
// ...
}
func run(pass *analysis.Pass) (interface{}, error) {
noLinter := pass.ResultOf[nolint.Analyzer].(*nolint.NoLinter)
// ...
if !noLinter.IgnoreNode(node, "someCategory") {
pass.Report(analysis.Diagnostic{
Category: "someCategory",
// ...
})
}
// ...
}NOTE: Category will be used to specify which diagnostic should be ignored.
// nolint:someCategory,anotherCategoryLICENSE
This is distributed under the MIT License.