@@ -3,7 +3,6 @@ title: False Positives
3
3
---
4
4
5
5
False 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 ) .
7
6
8
7
If a false positive occurred, you have the several choices.
9
8
@@ -17,106 +16,98 @@ Otherwise, some linters have dedicated configuration to exclude or disable rules
17
16
An example with ` staticcheck ` :
18
17
19
18
``` 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
26
26
` ` `
27
27
28
- ## Exclude or Skip
28
+ ## Exclude
29
29
30
30
### Exclude Issue by Text
31
31
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.
45
33
46
34
In the following example, all the reports from the linters (`linters`) that contains the text (`text`) are excluded :
47
35
48
36
` ` ` 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"
54
43
` ` `
55
44
56
45
In the following example, all the reports from the linters (`linters`) that originated from the source (`source`) are excluded :
57
46
58
47
` ` ` 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 "
64
54
` ` `
65
55
66
56
In the following example, all the reports that contains the text (`text`) in the path (`path`) are excluded :
67
57
68
58
` ` ` 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"
73
64
```
74
65
75
66
### Exclude Issues by Path
76
67
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.
82
69
83
70
In the following example, all the reports from the linters (` linters ` ) that concerns the path (` path ` ) are excluded:
84
71
85
72
``` 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
92
80
` ` `
93
81
94
82
The opposite, excluding reports **except** for specific paths, is also possible.
95
83
In the following example, only test files get checked:
96
84
97
85
` ` ` 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
104
93
` ` `
105
94
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:
107
96
108
97
` ` ` yaml
109
- issues:
110
- exclude-files:
111
- - path/to/a/file.go
98
+ linters:
99
+ exclusions:
100
+ paths:
101
+ - path/to/a/file.go
112
102
` ` `
113
103
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 :
115
105
116
106
` ` ` yaml
117
- issues:
118
- exclude-dirs:
119
- - path/to/a/dir/
107
+ linters:
108
+ exclusions:
109
+ paths:
110
+ - path/to/a/dir/
120
111
` ` `
121
112
122
113
# # Nolint Directive
0 commit comments