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