golangci-lint

False Positives

Table of Contents

False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of exclude patterns. If a false positive occurred you have the following choices:

  1. Exclude issue by text using command-line option -e or config option issues.exclude. It's helpful when you decided to ignore all issues of this type. Also, you can use issues.exclude-rules config option for per-path or per-linter configuration.
  2. Exclude this one issue by using special comment //nolint (see the section below).
  3. Exclude issues in path by run.skip-dirs, run.skip-files or issues.exclude-rules config options.

Please create GitHub Issues here if you find any false positives. We will add it to the default exclude list if it's common or we will fix underlying linter.

Nolint

To exclude issues from all linters use //nolint. For example, if it's used inline (not from the beginning of the line) it excludes issues only for this line.

var bad_name int //nolint

To exclude issues from specific linters only:

var bad_name int //nolint:golint,unused

To exclude issues for the block of code use this directive on the beginning of a line:

//nolint
func allIssuesInThisFunctionAreExcluded() *string {
// ...
}
//nolint:govet
var (
a int
b int
)

Also, you can exclude all issues in a file by:

//nolint:unparam
package pkg

You may add a comment explaining or justifying why //nolint is being used on the same line as the flag itself:

//nolint:gocyclo // This legacy function is complex but the team too busy to simplify it
func someLegacyFunction() *string {
// ...
}

You can see more examples of using //nolint in our tests for it.

Use //nolint instead of // nolint because machine-readable comments should have no space by Go convention.

Edit this page on GitHub