github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/path_prefixer.go (about)

     1  package processors
     2  
     3  import (
     4  	"path"
     5  
     6  	"github.com/elek/golangci-lint/pkg/result"
     7  )
     8  
     9  // PathPrefixer adds a customizable prefix to every output path
    10  type PathPrefixer struct {
    11  	prefix string
    12  }
    13  
    14  var _ Processor = new(PathPrefixer)
    15  
    16  // NewPathPrefixer returns a new path prefixer for the provided string
    17  func NewPathPrefixer(prefix string) *PathPrefixer {
    18  	return &PathPrefixer{prefix: prefix}
    19  }
    20  
    21  // Name returns the name of this processor
    22  func (*PathPrefixer) Name() string {
    23  	return "path_prefixer"
    24  }
    25  
    26  // Process adds the prefix to each path
    27  func (p *PathPrefixer) Process(issues []result.Issue) ([]result.Issue, error) {
    28  	if p.prefix != "" {
    29  		for i := range issues {
    30  			issues[i].Pos.Filename = path.Join(p.prefix, issues[i].Pos.Filename)
    31  		}
    32  	}
    33  	return issues, nil
    34  }
    35  
    36  // Finish is implemented to satisfy the Processor interface
    37  func (*PathPrefixer) Finish() {}