@@ -30,70 +30,92 @@ var OutFormats = []string{
3030}
3131
3232type ExcludePattern struct {
33+ ID string
3334 Pattern string
3435 Linter string
3536 Why string
3637}
3738
3839var DefaultExcludePatterns = []ExcludePattern {
3940 {
41+ ID : "EXC0001" ,
4042 Pattern : "Error return value of .((os\\ .)?std(out|err)\\ ..*|.*Close" +
4143 "|.*Flush|os\\ .Remove(All)?|.*printf?|os\\ .(Un)?Setenv). is not checked" ,
4244 Linter : "errcheck" ,
4345 Why : "Almost all programs ignore errors on these functions and in most cases it's ok" ,
4446 },
4547 {
48+ ID : "EXC0002" ,
4649 Pattern : "(comment on exported (method|function|type|const)|" +
4750 "should have( a package)? comment|comment should be of the form)" ,
4851 Linter : "golint" ,
4952 Why : "Annoying issue about not having a comment. The rare codebase has such comments" ,
5053 },
5154 {
55+ ID : "EXC0003" ,
5256 Pattern : "func name will be used as test\\ .Test.* by other packages, and that stutters; consider calling this" ,
5357 Linter : "golint" ,
5458 Why : "False positive when tests are defined in package 'test'" ,
5559 },
5660 {
61+ ID : "EXC0004" ,
5762 Pattern : "(possible misuse of unsafe.Pointer|should have signature)" ,
5863 Linter : "govet" ,
5964 Why : "Common false positives" ,
6065 },
6166 {
67+ ID : "EXC0005" ,
6268 Pattern : "ineffective break statement. Did you mean to break out of the outer loop" ,
6369 Linter : "staticcheck" ,
6470 Why : "Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore" ,
6571 },
6672 {
73+ ID : "EXC0006" ,
6774 Pattern : "Use of unsafe calls should be audited" ,
6875 Linter : "gosec" ,
6976 Why : "Too many false-positives on 'unsafe' usage" ,
7077 },
7178 {
79+ ID : "EXC0007" ,
7280 Pattern : "Subprocess launch(ed with variable|ing should be audited)" ,
7381 Linter : "gosec" ,
7482 Why : "Too many false-positives for parametrized shell calls" ,
7583 },
7684 {
85+ ID : "EXC0008" ,
7786 Pattern : "G104" ,
7887 Linter : "gosec" ,
7988 Why : "Duplicated errcheck checks" ,
8089 },
8190 {
91+ ID : "EXC0009" ,
8292 Pattern : "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)" ,
8393 Linter : "gosec" ,
8494 Why : "Too many issues in popular repos" ,
8595 },
8696 {
97+ ID : "EXC0010" ,
8798 Pattern : "Potential file inclusion via variable" ,
8899 Linter : "gosec" ,
89100 Why : "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'" ,
90101 },
91102}
92103
93104func 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+
94114 var ret []string
95115 for _ , p := range DefaultExcludePatterns {
96- ret = append (ret , p .Pattern )
116+ if ! includeMap [p .ID ] {
117+ ret = append (ret , p .Pattern )
118+ }
97119 }
98120
99121 return ret
@@ -411,10 +433,11 @@ func (e ExcludeRule) Validate() error {
411433}
412434
413435type 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"`
418441
419442 MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"`
420443 MaxSameIssues int `mapstructure:"max-same-issues"`
0 commit comments