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

     1  package processors
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/golangci/golangci-lint/pkg/result"
     7  )
     8  
     9  func filterIssues(issues []result.Issue, filter func(i *result.Issue) bool) []result.Issue {
    10  	retIssues := make([]result.Issue, 0, len(issues))
    11  	for _, i := range issues {
    12  		if filter(&i) {
    13  			retIssues = append(retIssues, i)
    14  		}
    15  	}
    16  
    17  	return retIssues
    18  }
    19  
    20  func filterIssuesErr(issues []result.Issue, filter func(i *result.Issue) (bool, error)) ([]result.Issue, error) {
    21  	retIssues := make([]result.Issue, 0, len(issues))
    22  	for _, i := range issues {
    23  		ok, err := filter(&i)
    24  		if err != nil {
    25  			return nil, fmt.Errorf("can't filter issue %#v: %s", i, err)
    26  		}
    27  
    28  		if ok {
    29  			retIssues = append(retIssues, i)
    30  		}
    31  	}
    32  
    33  	return retIssues, nil
    34  }
    35  
    36  func transformIssues(issues []result.Issue, transform func(i *result.Issue) *result.Issue) []result.Issue {
    37  	retIssues := make([]result.Issue, 0, len(issues))
    38  	for _, i := range issues {
    39  		newI := transform(&i)
    40  		if newI != nil {
    41  			retIssues = append(retIssues, *newI)
    42  		}
    43  	}
    44  
    45  	return retIssues
    46  }