Skip to content

Commit 051922e

Browse files
committed
more excludes and pretty logs
1 parent 07ddc54 commit 051922e

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

pkg/config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFo
1616

1717
var DefaultExcludePatterns = []string{
1818
// errcheck
19-
"Error return value of .(os\\.Std(out|err)\\.*|.*\\.Close|std(out|err)\\..*|os\\.Remove(All)?|.*[pP]rintf?). is not checked",
19+
"Error return value of .((os\\.)?std(out|err)\\..*|.*Close|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked",
2020

2121
// golint
2222
"should have comment",
@@ -26,10 +26,16 @@ var DefaultExcludePatterns = []string{
2626
"G103:", // Use of unsafe calls should be audited
2727
"G104:", // disable what errcheck does: it reports on Close etc
2828
"G204:", // Subprocess launching should be audited: too lot false positives
29+
"G301:", // Expect directory permissions to be 0750 or less
30+
"G302:", // Expect file permissions to be 0600 or less
2931
"G304:", // Potential file inclusion via variable: `src, err := ioutil.ReadFile(filename)`
3032

3133
// govet
3234
"possible misuse of unsafe.Pointer",
35+
"should have signature",
36+
37+
// megacheck
38+
"ineffective break statement. Did you mean to break out of the outer loop", // developers tend to write in C-style with break in switch
3339
}
3440

3541
type Common struct {

pkg/printers/text.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ func (p Text) Print(issues chan result.Issue) (bool, error) {
4343
logrus.Infof("Extracting issued lines took %s", issuedLineExtractingDuration)
4444
}()
4545

46-
gotAnyIssue := false
4746
cache := filesCache{}
4847
out := getOutWriter()
48+
issuesN := 0
4949
for i := range issues {
50-
gotAnyIssue = true
50+
issuesN++
5151
text := p.SprintfColored(color.FgRed, "%s", i.Text)
5252
if p.printLinterName {
5353
text += fmt.Sprintf(" (%s)", i.FromLinter)
@@ -89,10 +89,12 @@ func (p Text) Print(issues chan result.Issue) (bool, error) {
8989
}
9090
}
9191

92-
if !gotAnyIssue {
92+
if issuesN == 0 {
9393
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
9494
fmt.Fprintln(out, outStr)
95+
} else {
96+
logrus.Infof("Found %d issues", issuesN)
9597
}
9698

97-
return gotAnyIssue, nil
99+
return issuesN != 0, nil
98100
}

pkg/result/processors/exclude.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var _ Processor = Exclude{}
1515
func NewExclude(pattern string) *Exclude {
1616
var patternRe *regexp.Regexp
1717
if pattern != "" {
18-
patternRe = regexp.MustCompile(pattern)
18+
patternRe = regexp.MustCompile("(?i)" + pattern)
1919
}
2020
return &Exclude{
2121
pattern: patternRe,

pkg/result/processors/exclude_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
3131

3232
func TestExclude(t *testing.T) {
3333
p := NewExclude("^exclude$")
34-
texts := []string{"exclude", "1", "", "exclud", "notexclude"}
34+
texts := []string{"excLude", "1", "", "exclud", "notexclude"}
3535
var issues []result.Issue
3636
for _, t := range texts {
3737
issues = append(issues, newTextIssue(t))

pkg/result/processors/max_from_linter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
3535
}
3636

3737
func (p MaxFromLinter) Finish() {
38-
for linter, count := range p.lc {
38+
walkStringToIntMapSortedByValue(p.lc, func(linter string, count int) {
3939
if count > p.limit {
4040
logrus.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter",
4141
count-p.limit, count, linter)
4242
}
43-
}
43+
})
4444
}

pkg/result/processors/max_same_issues.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package processors
22

33
import (
4+
"sort"
5+
46
"github.com/golangci/golangci-lint/pkg/result"
57
"github.com/sirupsen/logrus"
68
)
@@ -37,10 +39,30 @@ func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) {
3739
}
3840

3941
func (p MaxSameIssues) Finish() {
40-
for text, count := range p.tc {
42+
walkStringToIntMapSortedByValue(p.tc, func(text string, count int) {
4143
if count > p.limit {
4244
logrus.Infof("%d/%d issues with text %q were hidden, use --max-same-issues",
4345
count-p.limit, count, text)
4446
}
47+
})
48+
}
49+
50+
type kv struct {
51+
Key string
52+
Value int
53+
}
54+
55+
func walkStringToIntMapSortedByValue(m map[string]int, walk func(k string, v int)) {
56+
var ss []kv
57+
for k, v := range m {
58+
ss = append(ss, kv{k, v})
59+
}
60+
61+
sort.Slice(ss, func(i, j int) bool {
62+
return ss[i].Value > ss[j].Value
63+
})
64+
65+
for _, kv := range ss {
66+
walk(kv.Key, kv.Value)
4567
}
4668
}

0 commit comments

Comments
 (0)