forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath_prefixer.go
40 lines (31 loc) · 1.01 KB
/
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
37
38
39
40
package processors
import (
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*PathPrefixer)(nil)
// PathPrefixer adds a customizable path prefix to report file paths for user facing.
// It uses the shortest relative paths and `path-prefix` option.
type PathPrefixer struct {
prefix string
}
// 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 == "" {
return issues, nil
}
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() {}