github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/result/processors/path_shortener.go (about)

     1  package processors
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/elek/golangci-lint/pkg/fsutils"
     8  	"github.com/elek/golangci-lint/pkg/result"
     9  )
    10  
    11  type PathShortener struct {
    12  	wd string
    13  }
    14  
    15  var _ Processor = PathShortener{}
    16  
    17  func NewPathShortener() *PathShortener {
    18  	wd, err := fsutils.Getwd()
    19  	if err != nil {
    20  		panic(fmt.Sprintf("Can't get working dir: %s", err))
    21  	}
    22  	return &PathShortener{
    23  		wd: wd,
    24  	}
    25  }
    26  
    27  func (p PathShortener) Name() string {
    28  	return "path_shortener"
    29  }
    30  
    31  func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error) {
    32  	return transformIssues(issues, func(i *result.Issue) *result.Issue {
    33  		newI := i
    34  		newI.Text = strings.Replace(newI.Text, p.wd+"/", "", -1)
    35  		newI.Text = strings.Replace(newI.Text, p.wd, "", -1)
    36  		return newI
    37  	}), nil
    38  }
    39  
    40  func (p PathShortener) Finish() {}