-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
path_prettifier.go
47 lines (36 loc) · 924 Bytes
/
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
45
46
47
package processors
import (
"fmt"
"path/filepath"
"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*PathPrettifier)(nil)
type PathPrettifier struct {
root string
}
func NewPathPrettifier() *PathPrettifier {
root, err := fsutils.Getwd()
if err != nil {
panic(fmt.Sprintf("Can't get working dir: %s", err))
}
return &PathPrettifier{root: root}
}
func (PathPrettifier) Name() string {
return "path_prettifier"
}
func (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 {
return issue
}
newIssue := issue
newIssue.Pos.Filename = rel
return newIssue
}), nil
}
func (PathPrettifier) Finish() {}