diff --git a/pkg/config/config.go b/pkg/config/config.go index 8a1cd479..5e2ab703 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,7 +16,7 @@ var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFo var DefaultExcludePatterns = []string{ // errcheck - "Error return value of .(os\\.Std(out|err)\\.*|.*\\.Close|std(out|err)\\..*|os\\.Remove(All)?|.*[pP]rintf?). is not checked", + "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked", // golint "should have comment", @@ -26,10 +26,16 @@ var DefaultExcludePatterns = []string{ "G103:", // Use of unsafe calls should be audited "G104:", // disable what errcheck does: it reports on Close etc "G204:", // Subprocess launching should be audited: too lot false positives + "G301:", // Expect directory permissions to be 0750 or less + "G302:", // Expect file permissions to be 0600 or less "G304:", // Potential file inclusion via variable: `src, err := ioutil.ReadFile(filename)` // govet "possible misuse of unsafe.Pointer", + "should have signature", + + // megacheck + "ineffective break statement. Did you mean to break out of the outer loop", // developers tend to write in C-style with break in switch } type Common struct { diff --git a/pkg/printers/text.go b/pkg/printers/text.go index 35203b0c..0de15bde 100644 --- a/pkg/printers/text.go +++ b/pkg/printers/text.go @@ -43,11 +43,11 @@ func (p Text) Print(issues chan result.Issue) (bool, error) { logrus.Infof("Extracting issued lines took %s", issuedLineExtractingDuration) }() - gotAnyIssue := false cache := filesCache{} out := getOutWriter() + issuesN := 0 for i := range issues { - gotAnyIssue = true + issuesN++ text := p.SprintfColored(color.FgRed, "%s", i.Text) if p.printLinterName { text += fmt.Sprintf(" (%s)", i.FromLinter) @@ -89,10 +89,12 @@ func (p Text) Print(issues chan result.Issue) (bool, error) { } } - if !gotAnyIssue { + if issuesN == 0 { outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.") fmt.Fprintln(out, outStr) + } else { + logrus.Infof("Found %d issues", issuesN) } - return gotAnyIssue, nil + return issuesN != 0, nil } diff --git a/pkg/result/processors/exclude.go b/pkg/result/processors/exclude.go index ae841066..80c4b894 100644 --- a/pkg/result/processors/exclude.go +++ b/pkg/result/processors/exclude.go @@ -15,7 +15,7 @@ var _ Processor = Exclude{} func NewExclude(pattern string) *Exclude { var patternRe *regexp.Regexp if pattern != "" { - patternRe = regexp.MustCompile(pattern) + patternRe = regexp.MustCompile("(?i)" + pattern) } return &Exclude{ pattern: patternRe, diff --git a/pkg/result/processors/exclude_test.go b/pkg/result/processors/exclude_test.go index bee996ca..fa19a49d 100644 --- a/pkg/result/processors/exclude_test.go +++ b/pkg/result/processors/exclude_test.go @@ -31,7 +31,7 @@ func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) { func TestExclude(t *testing.T) { p := NewExclude("^exclude$") - texts := []string{"exclude", "1", "", "exclud", "notexclude"} + texts := []string{"excLude", "1", "", "exclud", "notexclude"} var issues []result.Issue for _, t := range texts { issues = append(issues, newTextIssue(t)) diff --git a/pkg/result/processors/max_from_linter.go b/pkg/result/processors/max_from_linter.go index 8c9eade4..67e9873f 100644 --- a/pkg/result/processors/max_from_linter.go +++ b/pkg/result/processors/max_from_linter.go @@ -35,10 +35,10 @@ func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) { } func (p MaxFromLinter) Finish() { - for linter, count := range p.lc { + walkStringToIntMapSortedByValue(p.lc, func(linter string, count int) { if count > p.limit { logrus.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter", count-p.limit, count, linter) } - } + }) } diff --git a/pkg/result/processors/max_same_issues.go b/pkg/result/processors/max_same_issues.go index ceab692b..48e98e30 100644 --- a/pkg/result/processors/max_same_issues.go +++ b/pkg/result/processors/max_same_issues.go @@ -1,6 +1,8 @@ package processors import ( + "sort" + "github.com/golangci/golangci-lint/pkg/result" "github.com/sirupsen/logrus" ) @@ -37,10 +39,30 @@ func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) { } func (p MaxSameIssues) Finish() { - for text, count := range p.tc { + walkStringToIntMapSortedByValue(p.tc, func(text string, count int) { if count > p.limit { logrus.Infof("%d/%d issues with text %q were hidden, use --max-same-issues", count-p.limit, count, text) } + }) +} + +type kv struct { + Key string + Value int +} + +func walkStringToIntMapSortedByValue(m map[string]int, walk func(k string, v int)) { + var ss []kv + for k, v := range m { + ss = append(ss, kv{k, v}) + } + + sort.Slice(ss, func(i, j int) bool { + return ss[i].Value > ss[j].Value + }) + + for _, kv := range ss { + walk(kv.Key, kv.Value) } }