Skip to content

Commit

Permalink
refactor: add logs inside PathPrettifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jan 12, 2025
1 parent b8dc1ca commit 14a3d25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
processors.NewInvalidIssue(log.Child(logutils.DebugKeyInvalidIssue)),

// Must be before diff, nolint and exclude autogenerated processor at least.
processors.NewPathPrettifier(),
processors.NewPathPrettifier(log),
skipFilesProcessor,
skipDirsProcessor, // must be after path prettifier

Expand All @@ -91,13 +91,15 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti

processors.NewExclude(&cfg.Issues),
processors.NewExcludeRules(log.Child(logutils.DebugKeyExcludeRules), files, &cfg.Issues),

processors.NewNolint(log.Child(logutils.DebugKeyNolint), dbManager, enabledLinters),

processors.NewUniqByLine(cfg),
processors.NewDiff(&cfg.Issues),
processors.NewMaxPerFileFromLinter(cfg),
processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child(logutils.DebugKeyMaxSameIssues), cfg),
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child(logutils.DebugKeyMaxFromLinter), cfg),

processors.NewSourceCode(lineCache, log.Child(logutils.DebugKeySourceCode)),
processors.NewPathShortener(),
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),
Expand Down
1 change: 1 addition & 0 deletions pkg/logutils/logutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
DebugKeyMaxFromLinter = "max_from_linter"
DebugKeyMaxSameIssues = "max_same_issues"
DebugKeyPathAbsoluter = "path_absoluter"
DebugKeyPathPrettifier = "path_prettifier"
DebugKeyPkgCache = "pkgcache"
DebugKeyRunner = "runner"
DebugKeySeverityRules = "severity_rules"
Expand Down
13 changes: 8 additions & 5 deletions pkg/result/processors/path_prettifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import (
"path/filepath"

"github.com/golangci/golangci-lint/pkg/fsutils"
"github.com/golangci/golangci-lint/pkg/logutils"
"github.com/golangci/golangci-lint/pkg/result"
)

var _ Processor = (*PathPrettifier)(nil)

type PathPrettifier struct {
log logutils.Log
}

func NewPathPrettifier() *PathPrettifier {
return &PathPrettifier{}
func NewPathPrettifier(log logutils.Log) *PathPrettifier {
return &PathPrettifier{log: log.Child(logutils.DebugKeyPathPrettifier)}
}

func (PathPrettifier) Name() string {
func (*PathPrettifier) Name() string {
return "path_prettifier"
}

func (PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
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
}

rel, err := fsutils.ShortestRelPath(issue.FilePath(), "")
if err != nil {
p.log.Warnf("shortest relative path: %v", err)
return issue
}

Expand All @@ -37,4 +40,4 @@ func (PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
}), nil
}

func (PathPrettifier) Finish() {}
func (*PathPrettifier) Finish() {}

0 comments on commit 14a3d25

Please sign in to comment.