nolint

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 5 Imported by: 2

README

nolint

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

Go Report Card Coverage Status

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:             "nolint",
	Doc:              "make the go/analysis checkers be able to ignore diagnostics with \"Nolint\" comment",
	Run:              run,
	RunDespiteErrors: true,
	ResultType:       reflect.TypeOf(new(NoLinter)),
}

Functions

func Wrap

func Wrap(analyzer *analysis.Analyzer) *analysis.Analyzer

Wrap other Analyzer to ignore diagnostics marked by `//nolint`.

func WrapAll

func WrapAll(analyzer ...*analysis.Analyzer) []*analysis.Analyzer

WrapAll other Analyzers to ignore diagnostics marked by `//nolint`.

func WrapFunc

func WrapFunc(
	analyzer *analysis.Analyzer,
	ignore func(analysis.Diagnostic) bool,
) *analysis.Analyzer

WrapFunc will wrap an Analyzer to ignore diagnostics with a function.

Types

type NoLinter

type NoLinter struct {
	// contains filtered or unexported fields
}

func (*NoLinter) IgnoreDiagnostic

func (n *NoLinter) IgnoreDiagnostic(diagnostic analysis.Diagnostic) bool

func (*NoLinter) IgnoreNode

func (n *NoLinter) IgnoreNode(r analysis.Range, category string) bool

func (*NoLinter) Visit

func (n *NoLinter) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL