@@ -30,70 +30,92 @@ var OutFormats = []string{
30
30
}
31
31
32
32
type ExcludePattern struct {
33
+ ID string
33
34
Pattern string
34
35
Linter string
35
36
Why string
36
37
}
37
38
38
39
var DefaultExcludePatterns = []ExcludePattern {
39
40
{
41
+ ID : "EXC0001" ,
40
42
Pattern : "Error return value of .((os\\ .)?std(out|err)\\ ..*|.*Close" +
41
43
"|.*Flush|os\\ .Remove(All)?|.*printf?|os\\ .(Un)?Setenv). is not checked" ,
42
44
Linter : "errcheck" ,
43
45
Why : "Almost all programs ignore errors on these functions and in most cases it's ok" ,
44
46
},
45
47
{
48
+ ID : "EXC0002" ,
46
49
Pattern : "(comment on exported (method|function|type|const)|" +
47
50
"should have( a package)? comment|comment should be of the form)" ,
48
51
Linter : "golint" ,
49
52
Why : "Annoying issue about not having a comment. The rare codebase has such comments" ,
50
53
},
51
54
{
55
+ ID : "EXC0003" ,
52
56
Pattern : "func name will be used as test\\ .Test.* by other packages, and that stutters; consider calling this" ,
53
57
Linter : "golint" ,
54
58
Why : "False positive when tests are defined in package 'test'" ,
55
59
},
56
60
{
61
+ ID : "EXC0004" ,
57
62
Pattern : "(possible misuse of unsafe.Pointer|should have signature)" ,
58
63
Linter : "govet" ,
59
64
Why : "Common false positives" ,
60
65
},
61
66
{
67
+ ID : "EXC0005" ,
62
68
Pattern : "ineffective break statement. Did you mean to break out of the outer loop" ,
63
69
Linter : "staticcheck" ,
64
70
Why : "Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore" ,
65
71
},
66
72
{
73
+ ID : "EXC0006" ,
67
74
Pattern : "Use of unsafe calls should be audited" ,
68
75
Linter : "gosec" ,
69
76
Why : "Too many false-positives on 'unsafe' usage" ,
70
77
},
71
78
{
79
+ ID : "EXC0007" ,
72
80
Pattern : "Subprocess launch(ed with variable|ing should be audited)" ,
73
81
Linter : "gosec" ,
74
82
Why : "Too many false-positives for parametrized shell calls" ,
75
83
},
76
84
{
85
+ ID : "EXC0008" ,
77
86
Pattern : "G104" ,
78
87
Linter : "gosec" ,
79
88
Why : "Duplicated errcheck checks" ,
80
89
},
81
90
{
91
+ ID : "EXC0009" ,
82
92
Pattern : "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)" ,
83
93
Linter : "gosec" ,
84
94
Why : "Too many issues in popular repos" ,
85
95
},
86
96
{
97
+ ID : "EXC0010" ,
87
98
Pattern : "Potential file inclusion via variable" ,
88
99
Linter : "gosec" ,
89
100
Why : "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'" ,
90
101
},
91
102
}
92
103
93
104
func GetDefaultExcludePatternsStrings () []string {
105
+ return GetExcludePatternsStrings (nil )
106
+ }
107
+
108
+ func GetExcludePatternsStrings (include []string ) []string {
109
+ includeMap := make (map [string ]bool , len (include ))
110
+ for _ , inc := range include {
111
+ includeMap [inc ] = true
112
+ }
113
+
94
114
var ret []string
95
115
for _ , p := range DefaultExcludePatterns {
96
- ret = append (ret , p .Pattern )
116
+ if ! includeMap [p .ID ] {
117
+ ret = append (ret , p .Pattern )
118
+ }
97
119
}
98
120
99
121
return ret
@@ -411,10 +433,11 @@ func (e ExcludeRule) Validate() error {
411
433
}
412
434
413
435
type Issues struct {
414
- ExcludeCaseSensitive bool `mapstructure:"exclude-case-sensitive"`
415
- ExcludePatterns []string `mapstructure:"exclude"`
416
- ExcludeRules []ExcludeRule `mapstructure:"exclude-rules"`
417
- UseDefaultExcludes bool `mapstructure:"exclude-use-default"`
436
+ IncludeDefaultExcludes []string `mapstructure:"include"`
437
+ ExcludeCaseSensitive bool `mapstructure:"exclude-case-sensitive"`
438
+ ExcludePatterns []string `mapstructure:"exclude"`
439
+ ExcludeRules []ExcludeRule `mapstructure:"exclude-rules"`
440
+ UseDefaultExcludes bool `mapstructure:"exclude-use-default"`
418
441
419
442
MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"`
420
443
MaxSameIssues int `mapstructure:"max-same-issues"`
0 commit comments