diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index f583121ed869..e8ba4ad4a46d 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -60,6 +60,11 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti return nil, fmt.Errorf("failed to get enabled linters: %w", err) } + pathShortenerProcessor, err := processors.NewPathShortener() + if err != nil { + return nil, err + } + return &Runner{ Processors: []processors.Processor{ processors.NewCgo(goenv), @@ -90,7 +95,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti 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(), + pathShortenerProcessor, processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity), // The fixer still needs to see paths for the issues that are relative to the current directory. diff --git a/pkg/result/processors/path_prettifier.go b/pkg/result/processors/path_prettifier.go index 3c97f06a65e1..c5c27357c60f 100644 --- a/pkg/result/processors/path_prettifier.go +++ b/pkg/result/processors/path_prettifier.go @@ -1,7 +1,6 @@ package processors import ( - "fmt" "path/filepath" "github.com/golangci/golangci-lint/pkg/fsutils" @@ -11,16 +10,10 @@ import ( var _ Processor = (*PathPrettifier)(nil) type PathPrettifier struct { - root string } func NewPathPrettifier() *PathPrettifier { - root, err := fsutils.Getwd() - if err != nil { - panic(fmt.Sprintf("Can't get working dir: %s", err)) - } - - return &PathPrettifier{root: root} + return &PathPrettifier{} } func (PathPrettifier) Name() string { diff --git a/pkg/result/processors/path_shortener.go b/pkg/result/processors/path_shortener.go index b161e86c2f46..ebd70eeb780d 100644 --- a/pkg/result/processors/path_shortener.go +++ b/pkg/result/processors/path_shortener.go @@ -14,13 +14,13 @@ type PathShortener struct { wd string } -func NewPathShortener() *PathShortener { +func NewPathShortener() (*PathShortener, error) { wd, err := fsutils.Getwd() if err != nil { - panic(fmt.Sprintf("Can't get working dir: %s", err)) + return nil, fmt.Errorf("failed to get working dir: %w", err) } - return &PathShortener{wd: wd} + return &PathShortener{wd: wd}, nil } func (PathShortener) Name() string {