
Use go/packages instead of x/tools/loader: it allows to work with go modules and speedups loading of packages with the help of build cache. A lot of linters became "fast": they are enabled by --fast now and work in 1-2 seconds. Only unparam, interfacer and megacheck are "slow" linters now. Average project is analyzed 20-40% faster than before if all linters are enabled! If we enable all linters except unparam, interfacer and megacheck analysis is 10-20x faster!
41 lines
813 B
Go
41 lines
813 B
Go
package processors
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/fsutils"
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
)
|
|
|
|
type PathShortener struct {
|
|
wd string
|
|
}
|
|
|
|
var _ Processor = PathShortener{}
|
|
|
|
func NewPathShortener() *PathShortener {
|
|
wd, err := fsutils.Getwd()
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Can't get working dir: %s", err))
|
|
}
|
|
return &PathShortener{
|
|
wd: wd,
|
|
}
|
|
}
|
|
|
|
func (p PathShortener) Name() string {
|
|
return "path_shortener"
|
|
}
|
|
|
|
func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error) {
|
|
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
|
newI := i
|
|
newI.Text = strings.Replace(newI.Text, p.wd+"/", "", -1)
|
|
newI.Text = strings.Replace(newI.Text, p.wd, "", -1)
|
|
return newI
|
|
}), nil
|
|
}
|
|
|
|
func (p PathShortener) Finish() {}
|