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