forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath_prettifier.go
44 lines (34 loc) · 1 KB
/
path_prettifier.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
41
42
43
44
package processors
import (
"path/filepath"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*PathPrettifier)(nil)
// PathPrettifier modifies report file path to be relative to the base path.
// Also handles the `output.path-prefix` option.
type PathPrettifier struct {
prefix string
log logutils.Log
}
func NewPathPrettifier(log logutils.Log, prefix string) *PathPrettifier {
return &PathPrettifier{
prefix: prefix,
log: log.Child(logutils.DebugKeyPathPrettifier),
}
}
func (*PathPrettifier) Name() string {
return "path_prettifier"
}
func (p *PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
newIssue := issue
if p.prefix == "" {
newIssue.Pos.Filename = issue.RelativePath
} else {
newIssue.Pos.Filename = filepath.Join(p.prefix, issue.RelativePath)
}
return newIssue
}), nil
}
func (*PathPrettifier) Finish() {}