github.com/ldez/golangci-lint@v1.10.1/pkg/result/processors/path_prettifier.go (about)

     1  package processors
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/golangci/golangci-lint/pkg/fsutils"
     8  	"github.com/golangci/golangci-lint/pkg/result"
     9  )
    10  
    11  type PathPrettifier struct {
    12  	root string
    13  }
    14  
    15  var _ Processor = PathPrettifier{}
    16  
    17  func NewPathPrettifier() *PathPrettifier {
    18  	root, err := fsutils.Getwd()
    19  	if err != nil {
    20  		panic(fmt.Sprintf("Can't get working dir: %s", err))
    21  	}
    22  	return &PathPrettifier{
    23  		root: root,
    24  	}
    25  }
    26  
    27  func (p PathPrettifier) Name() string {
    28  	return "path_prettifier"
    29  }
    30  
    31  func (p PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
    32  	return transformIssues(issues, func(i *result.Issue) *result.Issue {
    33  		if !filepath.IsAbs(i.FilePath()) {
    34  			return i
    35  		}
    36  
    37  		rel, err := fsutils.ShortestRelPath(i.FilePath(), "")
    38  		if err != nil {
    39  			return i
    40  		}
    41  
    42  		newI := i
    43  		newI.Pos.Filename = rel
    44  		return newI
    45  	}), nil
    46  }
    47  
    48  func (p PathPrettifier) Finish() {}