github.com/ldez/golangci-lint@v1.10.1/pkg/result/processors/max_per_file_from_linter.go (about)

     1  package processors
     2  
     3  import (
     4  	"github.com/golangci/golangci-lint/pkg/result"
     5  )
     6  
     7  type linterToCountMap map[string]int
     8  type fileToLinterToCountMap map[string]linterToCountMap
     9  
    10  type MaxPerFileFromLinter struct {
    11  	flc fileToLinterToCountMap
    12  }
    13  
    14  var _ Processor = &MaxPerFileFromLinter{}
    15  
    16  func NewMaxPerFileFromLinter() *MaxPerFileFromLinter {
    17  	return &MaxPerFileFromLinter{
    18  		flc: fileToLinterToCountMap{},
    19  	}
    20  }
    21  
    22  func (p MaxPerFileFromLinter) Name() string {
    23  	return "max_per_file_from_linter"
    24  }
    25  
    26  var maxPerFileFromLinterConfig = map[string]int{
    27  	"gofmt":     1,
    28  	"goimports": 1,
    29  	"typecheck": 3,
    30  }
    31  
    32  func (p *MaxPerFileFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
    33  	return filterIssues(issues, func(i *result.Issue) bool {
    34  		limit := maxPerFileFromLinterConfig[i.FromLinter]
    35  		if limit == 0 {
    36  			return true
    37  		}
    38  
    39  		lm := p.flc[i.FilePath()]
    40  		if lm == nil {
    41  			p.flc[i.FilePath()] = linterToCountMap{}
    42  		}
    43  		count := p.flc[i.FilePath()][i.FromLinter]
    44  		if count >= limit {
    45  			return false
    46  		}
    47  
    48  		p.flc[i.FilePath()][i.FromLinter]++
    49  		return true
    50  	}), nil
    51  }
    52  
    53  func (p MaxPerFileFromLinter) Finish() {}