Skip to content

kyoh86/nolint

Repository files navigation

nolint

Nolint will make the go/analysis linters be able to ignore diagnostics with //nolint comment

PkgGoDev Go Report Card Coverage Status Release

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,anotherCategory

For 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.

// nolint

For 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,anotherCategory

LICENSE

MIT License

This is distributed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •