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:
- Exclude issue by text using command-line option
-e
or config optionissues.exclude
. It's helpful when you decided to ignore all issues of this type. Also, you can useissues.exclude-rules
config option for per-path or per-linter configuration. - Exclude this one issue by using special comment
//nolint
(see the section below). - Exclude issues in path by
run.skip-dirs
,run.skip-files
orissues.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:
//nolintfunc allIssuesInThisFunctionAreExcluded() *string {// ...}//nolint:govetvar (a intb int)
Also, you can exclude all issues in a file by:
//nolint:unparampackage 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 itfunc 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.