@@ -3,7 +3,6 @@ title: False Positives
33---
44
55False positives are inevitable, but we did our best to reduce their count.
6- For example, we have a default enabled set of [ exclude patterns] ( /usage/configuration#command-line-options ) .
76
87If a false positive occurred, you have the several choices.
98
@@ -17,106 +16,98 @@ Otherwise, some linters have dedicated configuration to exclude or disable rules
1716An example with ` staticcheck ` :
1817
1918``` yaml
20- linters-settings :
21- staticcheck :
22- checks :
23- - all
24- - ' -SA1000' # disable the rule SA1000
25- - ' -SA1004' # disable the rule SA1004
19+ linters :
20+ settings :
21+ staticcheck :
22+ checks :
23+ - all
24+ - ' -SA1000' # disable the rule SA1000
25+ - ' -SA1004' # disable the rule SA1004
2626` ` `
2727
28- ## Exclude or Skip
28+ ## Exclude
2929
3030### Exclude Issue by Text
3131
32- Exclude issue by text using command-line option ` -e` or config option `issues.exclude`.
33- It's helpful when you decided to ignore all issues of this type.
34- Also, you can use `issues.exclude-rules` config option for per-path or per-linter configuration.
35-
36- In the following example, all the reports that contains the sentences defined in `exclude` are excluded :
37-
38- ` ` ` yaml
39- issues:
40- exclude:
41- - "Error return value of .((os\\ .)?std(out|err)\\ ..*|.*Close|.*Flush|os\\ .Remove(All)?|.*printf?|os\\ .(Un)?Setenv). is not checked"
42- - "exported (type|method|function) (.+) should have comment or be unexported"
43- - "ST1000: at least one file in a package should have a package comment"
44- ` ` `
32+ You can use ` linters.exclusions.rules` config option for per-path or per-linter configuration.
4533
4634In the following example, all the reports from the linters (`linters`) that contains the text (`text`) are excluded :
4735
4836` ` ` yaml
49- issues:
50- exclude-rules:
51- - linters:
52- - mnd
53- text: "Magic number: 9"
37+ linters:
38+ exclusions:
39+ rules:
40+ - linters:
41+ - mnd
42+ text: "Magic number: 9"
5443` ` `
5544
5645In the following example, all the reports from the linters (`linters`) that originated from the source (`source`) are excluded :
5746
5847` ` ` yaml
59- issues:
60- exclude-rules:
61- - linters:
62- - lll
63- source: "^//go:generate "
48+ linters:
49+ exclusions:
50+ rules:
51+ - linters:
52+ - lll
53+ source: "^//go:generate "
6454` ` `
6555
6656In the following example, all the reports that contains the text (`text`) in the path (`path`) are excluded :
6757
6858` ` ` yaml
69- issues:
70- exclude-rules:
71- - path: path/to/a/file.go
72- text: "string ` example` has (\\d+) occurrences, make it a constant"
59+ linters:
60+ exclusions:
61+ rules:
62+ - path: path/to/a/file.go
63+ text: "string ` example` has (\\d+) occurrences, make it a constant"
7364```
7465
7566### Exclude Issues by Path
7667
77- Exclude issues in path by ` issues.exclude-dirs ` , ` issues.exclude-files ` or ` issues.exclude-rules ` config options.
78-
79- Beware that the paths that get matched here are relative to the current working directory.
80- When the configuration contains path patterns that check for specific directories,
81- the ` --path-prefix ` parameter can be used to extend the paths before matching.
68+ Exclude issues in path by ` linters.exclusions.paths ` or ` linters.exclusions.rules ` config options.
8269
8370In the following example, all the reports from the linters (` linters ` ) that concerns the path (` path ` ) are excluded:
8471
8572``` yaml
86- issues :
87- exclude-rules :
88- - path : ' (.+)_test\.go'
89- linters :
90- - funlen
91- - goconst
73+ linters :
74+ exclusions :
75+ rules :
76+ - path : ' (.+)_test\.go'
77+ linters :
78+ - funlen
79+ - goconst
9280` ` `
9381
9482The opposite, excluding reports **except** for specific paths, is also possible.
9583In the following example, only test files get checked:
9684
9785` ` ` yaml
98- issues :
99- exclude-rules :
100- - path-except : ' (.+)_test\.go'
101- linters :
102- - funlen
103- - goconst
86+ linters :
87+ exclusions :
88+ rules :
89+ - path-except : ' (.+)_test\.go'
90+ linters :
91+ - funlen
92+ - goconst
10493` ` `
10594
106- In the following example, all the reports related to the files (` exclude-files `) are excluded:
95+ In the following example, all the reports related to the files (` paths `) are excluded:
10796
10897` ` ` yaml
109- issues:
110- exclude-files:
111- - path/to/a/file.go
98+ linters:
99+ exclusions:
100+ paths:
101+ - path/to/a/file.go
112102` ` `
113103
114- In the following example, all the reports related to the directories (`exclude-dirs `) are excluded :
104+ In the following example, all the reports related to the directories (`paths `) are excluded :
115105
116106` ` ` yaml
117- issues:
118- exclude-dirs:
119- - path/to/a/dir/
107+ linters:
108+ exclusions:
109+ paths:
110+ - path/to/a/dir/
120111` ` `
121112
122113# # Nolint Directive
0 commit comments