Skip to content

Commit c55e761

Browse files
committed
Re-enable default excludes by ID
1 parent c25bf85 commit c55e761

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

pkg/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func getDefaultIssueExcludeHelp() string {
3030
parts := []string{"Use or not use default excludes:"}
3131
for _, ep := range config.DefaultExcludePatterns {
3232
parts = append(parts,
33-
fmt.Sprintf(" # %s: %s", ep.Linter, ep.Why),
33+
fmt.Sprintf(" # %s %s: %s", ep.ID, ep.Linter, ep.Why),
3434
fmt.Sprintf(" - %s", color.YellowString(ep.Pattern)),
3535
"",
3636
)

pkg/config/config.go

+25-6
Original file line numberDiff line numberDiff line change
@@ -30,70 +30,88 @@ var OutFormats = []string{
3030
}
3131

3232
type ExcludePattern struct {
33+
ID string
3334
Pattern string
3435
Linter string
3536
Why string
3637
}
3738

3839
var 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

93-
func GetDefaultExcludePatternsStrings() []string {
104+
func GetDefaultExcludePatternsStrings(include []string) []string {
105+
includeMap := make(map[string]bool, len(include))
106+
for _, inc := range include {
107+
includeMap[inc] = true
108+
}
109+
94110
var ret []string
95111
for _, p := range DefaultExcludePatterns {
96-
ret = append(ret, p.Pattern)
112+
if !includeMap[p.ID] {
113+
ret = append(ret, p.Pattern)
114+
}
97115
}
98116

99117
return ret
@@ -411,10 +429,11 @@ func (e ExcludeRule) Validate() error {
411429
}
412430

413431
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"`
432+
IncludeDefaultExcludes []string `mapstructure:"include"`
433+
ExcludeCaseSensitive bool `mapstructure:"exclude-case-sensitive"`
434+
ExcludePatterns []string `mapstructure:"exclude"`
435+
ExcludeRules []ExcludeRule `mapstructure:"exclude-rules"`
436+
UseDefaultExcludes bool `mapstructure:"exclude-use-default"`
418437

419438
MaxIssuesPerLinter int `mapstructure:"max-issues-per-linter"`
420439
MaxSameIssues int `mapstructure:"max-same-issues"`

pkg/lint/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewRunner(cfg *config.Config, log logutils.Log, goenv *goutil.Env,
3232
icfg := cfg.Issues
3333
excludePatterns := icfg.ExcludePatterns
3434
if icfg.UseDefaultExcludes {
35-
excludePatterns = append(excludePatterns, config.GetDefaultExcludePatternsStrings()...)
35+
excludePatterns = append(excludePatterns, config.GetDefaultExcludePatternsStrings(icfg.IncludeDefaultExcludes)...)
3636
}
3737

3838
var excludeTotalPattern string

test/bench/bench_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func getGometalinterCommonArgs() []string {
7777
"--vendor",
7878
"--cyclo-over=30",
7979
"--dupl-threshold=150",
80-
"--exclude", fmt.Sprintf("(%s)", strings.Join(config.GetDefaultExcludePatternsStrings(), "|")),
80+
"--exclude", fmt.Sprintf("(%s)", strings.Join(config.GetDefaultExcludePatternsStrings(nil), "|")),
8181
"--disable-all",
8282
"--enable=vet",
8383
"--enable=vetshadow",

0 commit comments

Comments
 (0)