github.com/alecthomas/golangci-lint@v1.4.2-0.20180609094924-581a3564ff68/pkg/result/processors/max_from_linter.go (about)

     1  package processors
     2  
     3  import (
     4  	"github.com/golangci/golangci-lint/pkg/result"
     5  	"github.com/sirupsen/logrus"
     6  )
     7  
     8  type MaxFromLinter struct {
     9  	lc    linterToCountMap
    10  	limit int
    11  }
    12  
    13  var _ Processor = &MaxFromLinter{}
    14  
    15  func NewMaxFromLinter(limit int) *MaxFromLinter {
    16  	return &MaxFromLinter{
    17  		lc:    linterToCountMap{},
    18  		limit: limit,
    19  	}
    20  }
    21  
    22  func (p MaxFromLinter) Name() string {
    23  	return "max_from_linter"
    24  }
    25  
    26  func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
    27  	if p.limit <= 0 { // no limit
    28  		return issues, nil
    29  	}
    30  
    31  	return filterIssues(issues, func(i *result.Issue) bool {
    32  		p.lc[i.FromLinter]++ // always inc for stat
    33  		return p.lc[i.FromLinter] <= p.limit
    34  	}), nil
    35  }
    36  
    37  func (p MaxFromLinter) Finish() {
    38  	walkStringToIntMapSortedByValue(p.lc, func(linter string, count int) {
    39  		if count > p.limit {
    40  			logrus.Infof("%d/%d issues from linter %s were hidden, use --max-issues-per-linter",
    41  				count-p.limit, count, linter)
    42  		}
    43  	})
    44  }