golangci-lint/pkg/result/processors/path_prettifier.go

48 lines
926 B
Go
Raw Normal View History

2018-05-05 19:43:18 +03:00
package processors
import (
2018-05-07 21:44:40 +03:00
"fmt"
"path/filepath"
2018-05-05 19:43:18 +03:00
2018-07-29 21:45:19 +03:00
"github.com/golangci/golangci-lint/pkg/fsutils"
2018-05-05 19:43:18 +03:00
"github.com/golangci/golangci-lint/pkg/result"
)
var _ Processor = (*PathPrettifier)(nil)
2018-05-07 21:44:40 +03:00
type PathPrettifier struct {
root string
2018-05-05 19:43:18 +03:00
}
2018-05-07 21:44:40 +03:00
func NewPathPrettifier() *PathPrettifier {
2018-07-29 21:45:19 +03:00
root, err := fsutils.Getwd()
2018-05-07 21:44:40 +03:00
if err != nil {
panic(fmt.Sprintf("Can't get working dir: %s", err))
2018-05-07 21:44:40 +03:00
}
return &PathPrettifier{root: root}
2018-05-05 19:43:18 +03:00
}
func (PathPrettifier) Name() string {
2018-05-07 21:44:40 +03:00
return "path_prettifier"
2018-05-05 19:43:18 +03:00
}
2018-05-07 21:44:40 +03:00
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
2018-05-05 19:43:18 +03:00
}
rel, err := fsutils.ShortestRelPath(issue.FilePath(), "")
2018-05-07 21:44:40 +03:00
if err != nil {
return issue
2018-05-07 21:44:40 +03:00
}
2018-05-05 19:43:18 +03:00
newIssue := issue
newIssue.Pos.Filename = rel
return newIssue
2018-05-07 21:44:40 +03:00
}), nil
2018-05-05 19:43:18 +03:00
}
func (PathPrettifier) Finish() {}