Skip to content

Commit 3215445

Browse files
committed
refactor: add logs inside PathPrettifier
1 parent 2e7b3af commit 3215445

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

pkg/lint/runner.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
8080
processors.NewInvalidIssue(log.Child(logutils.DebugKeyInvalidIssue)),
8181

8282
// Must be before diff, nolint and exclude autogenerated processor at least.
83-
processors.NewPathPrettifier(),
83+
processors.NewPathPrettifier(log),
8484
skipFilesProcessor,
8585
skipDirsProcessor, // must be after path prettifier
8686

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

9292
processors.NewExclude(&cfg.Issues),
9393
processors.NewExcludeRules(log.Child(logutils.DebugKeyExcludeRules), files, &cfg.Issues),
94+
9495
processors.NewNolint(log.Child(logutils.DebugKeyNolint), dbManager, enabledLinters),
9596

9697
processors.NewUniqByLine(cfg),
9798
processors.NewDiff(&cfg.Issues),
9899
processors.NewMaxPerFileFromLinter(cfg),
99100
processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child(logutils.DebugKeyMaxSameIssues), cfg),
100101
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child(logutils.DebugKeyMaxFromLinter), cfg),
102+
101103
processors.NewSourceCode(lineCache, log.Child(logutils.DebugKeySourceCode)),
102104
processors.NewPathShortener(),
103105
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),

pkg/logutils/logutils.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
DebugKeyMaxFromLinter = "max_from_linter"
3838
DebugKeyMaxSameIssues = "max_same_issues"
3939
DebugKeyPathAbsoluter = "path_absoluter"
40+
DebugKeyPathPrettifier = "path_prettifier"
4041
DebugKeyPkgCache = "pkgcache"
4142
DebugKeyRunner = "runner"
4243
DebugKeySeverityRules = "severity_rules"

pkg/result/processors/path_prettifier.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@ import (
44
"path/filepath"
55

66
"github.com/golangci/golangci-lint/pkg/fsutils"
7+
"github.com/golangci/golangci-lint/pkg/logutils"
78
"github.com/golangci/golangci-lint/pkg/result"
89
)
910

1011
var _ Processor = (*PathPrettifier)(nil)
1112

1213
type PathPrettifier struct {
14+
log logutils.Log
1315
}
1416

15-
func NewPathPrettifier() *PathPrettifier {
16-
return &PathPrettifier{}
17+
func NewPathPrettifier(log logutils.Log) *PathPrettifier {
18+
return &PathPrettifier{log: log.Child(logutils.DebugKeyPathPrettifier)}
1719
}
1820

19-
func (PathPrettifier) Name() string {
21+
func (*PathPrettifier) Name() string {
2022
return "path_prettifier"
2123
}
2224

23-
func (PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
25+
func (p *PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) {
2426
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
2527
if !filepath.IsAbs(issue.FilePath()) {
2628
return issue
2729
}
2830

2931
rel, err := fsutils.ShortestRelPath(issue.FilePath(), "")
3032
if err != nil {
33+
p.log.Warnf("shortest relative path: %v", err)
3134
return issue
3235
}
3336

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

40-
func (PathPrettifier) Finish() {}
43+
func (*PathPrettifier) Finish() {}

0 commit comments

Comments
 (0)