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.03 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/fsutils"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*PathPrettifier)(nil)
// PathPrettifier modifies report file path with the shortest relative path.
type PathPrettifier struct {
log logutils.Log
}
func NewPathPrettifier(log logutils.Log) *PathPrettifier {
return &PathPrettifier{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 {
if !filepath.IsAbs(issue.FilePath()) {
return issue
}
rel, err := fsutils.ShortestRelPath(issue.FilePath(), "")
if err != nil {
p.log.Warnf("shortest relative path: %v", err)
return issue
}
newIssue := issue
newIssue.Pos.Filename = rel
return newIssue
}), nil
}
func (*PathPrettifier) Finish() {}