more excludes and pretty logs
This commit is contained in:
parent
07ddc548dc
commit
051922e5c8
@ -16,7 +16,7 @@ var OutFormats = []string{OutFormatColoredLineNumber, OutFormatLineNumber, OutFo
|
|||||||
|
|
||||||
var DefaultExcludePatterns = []string{
|
var DefaultExcludePatterns = []string{
|
||||||
// errcheck
|
// 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
|
// golint
|
||||||
"should have comment",
|
"should have comment",
|
||||||
@ -26,10 +26,16 @@ var DefaultExcludePatterns = []string{
|
|||||||
"G103:", // Use of unsafe calls should be audited
|
"G103:", // Use of unsafe calls should be audited
|
||||||
"G104:", // disable what errcheck does: it reports on Close etc
|
"G104:", // disable what errcheck does: it reports on Close etc
|
||||||
"G204:", // Subprocess launching should be audited: too lot false positives
|
"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)`
|
"G304:", // Potential file inclusion via variable: `src, err := ioutil.ReadFile(filename)`
|
||||||
|
|
||||||
// govet
|
// govet
|
||||||
"possible misuse of unsafe.Pointer",
|
"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 {
|
type Common struct {
|
||||||
|
@ -43,11 +43,11 @@ func (p Text) Print(issues chan result.Issue) (bool, error) {
|
|||||||
logrus.Infof("Extracting issued lines took %s", issuedLineExtractingDuration)
|
logrus.Infof("Extracting issued lines took %s", issuedLineExtractingDuration)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
gotAnyIssue := false
|
|
||||||
cache := filesCache{}
|
cache := filesCache{}
|
||||||
out := getOutWriter()
|
out := getOutWriter()
|
||||||
|
issuesN := 0
|
||||||
for i := range issues {
|
for i := range issues {
|
||||||
gotAnyIssue = true
|
issuesN++
|
||||||
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
text := p.SprintfColored(color.FgRed, "%s", i.Text)
|
||||||
if p.printLinterName {
|
if p.printLinterName {
|
||||||
text += fmt.Sprintf(" (%s)", i.FromLinter)
|
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.")
|
outStr := p.SprintfColored(color.FgGreen, "Congrats! No issues were found.")
|
||||||
fmt.Fprintln(out, outStr)
|
fmt.Fprintln(out, outStr)
|
||||||
|
} else {
|
||||||
|
logrus.Infof("Found %d issues", issuesN)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gotAnyIssue, nil
|
return issuesN != 0, nil
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ var _ Processor = Exclude{}
|
|||||||
func NewExclude(pattern string) *Exclude {
|
func NewExclude(pattern string) *Exclude {
|
||||||
var patternRe *regexp.Regexp
|
var patternRe *regexp.Regexp
|
||||||
if pattern != "" {
|
if pattern != "" {
|
||||||
patternRe = regexp.MustCompile(pattern)
|
patternRe = regexp.MustCompile("(?i)" + pattern)
|
||||||
}
|
}
|
||||||
return &Exclude{
|
return &Exclude{
|
||||||
pattern: patternRe,
|
pattern: patternRe,
|
||||||
|
@ -31,7 +31,7 @@ func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) {
|
|||||||
|
|
||||||
func TestExclude(t *testing.T) {
|
func TestExclude(t *testing.T) {
|
||||||
p := NewExclude("^exclude$")
|
p := NewExclude("^exclude$")
|
||||||
texts := []string{"exclude", "1", "", "exclud", "notexclude"}
|
texts := []string{"excLude", "1", "", "exclud", "notexclude"}
|
||||||
var issues []result.Issue
|
var issues []result.Issue
|
||||||
for _, t := range texts {
|
for _, t := range texts {
|
||||||
issues = append(issues, newTextIssue(t))
|
issues = append(issues, newTextIssue(t))
|
||||||
|
@ -35,10 +35,10 @@ func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p MaxFromLinter) Finish() {
|
func (p MaxFromLinter) Finish() {
|
||||||
for linter, count := range p.lc {
|
walkStringToIntMapSortedByValue(p.lc, func(linter string, count int) {
|
||||||
if count > p.limit {
|
if count > p.limit {
|
||||||
logrus.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter",
|
logrus.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter",
|
||||||
count-p.limit, count, linter)
|
count-p.limit, count, linter)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package processors
|
package processors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/result"
|
"github.com/golangci/golangci-lint/pkg/result"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -37,10 +39,30 @@ func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p MaxSameIssues) Finish() {
|
func (p MaxSameIssues) Finish() {
|
||||||
for text, count := range p.tc {
|
walkStringToIntMapSortedByValue(p.tc, func(text string, count int) {
|
||||||
if count > p.limit {
|
if count > p.limit {
|
||||||
logrus.Infof("%d/%d issues with text %q were hidden, use --max-same-issues",
|
logrus.Infof("%d/%d issues with text %q were hidden, use --max-same-issues",
|
||||||
count-p.limit, count, text)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user