From 0a3af49856f062879b0284ff055e564f1eef8b0c Mon Sep 17 00:00:00 2001 From: Joe Wilner Date: Thu, 9 Jul 2020 21:35:28 -0400 Subject: [PATCH 1/2] Add ability to specify path prefix in output. --- pkg/commands/run.go | 12 ++++++++++++ pkg/config/config.go | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index e4887d587a50..a3b9757f2804 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "path" "runtime" "strings" "time" @@ -81,6 +82,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is fs.BoolVar(&oc.PrintLinterName, "print-linter-name", true, wh("Print linter name in issue line")) fs.BoolVar(&oc.UniqByLine, "uniq-by-line", true, wh("Make issues output unique by line")) fs.BoolVar(&oc.PrintWelcomeMessage, "print-welcome", false, wh("Print welcome message")) + fs.StringVar(&oc.PathPrefix, "path-prefix", "", wh("Path prefix to add to output")) hideFlag("print-welcome") // no longer used // Run config @@ -377,6 +379,8 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error { e.setExitCodeIfIssuesFound(issues) + e.postProcess(issues) + if err = p.Print(ctx, issues); err != nil { return fmt.Errorf("can't print %d issues: %s", len(issues), err) } @@ -413,6 +417,14 @@ func (e *Executor) createPrinter() (printers.Printer, error) { return p, nil } +func (e *Executor) postProcess(issues []result.Issue) { + if e.cfg.Output.PathPrefix != "" { + for i := range issues { + issues[i].Pos.Filename = path.Join(e.cfg.Output.PathPrefix, issues[i].FilePath()) + } + } +} + func (e *Executor) executeRun(_ *cobra.Command, args []string) { needTrackResources := e.cfg.Run.IsVerbose || e.cfg.Run.PrintResourcesUsage trackResourcesEndCh := make(chan struct{}) diff --git a/pkg/config/config.go b/pkg/config/config.go index 3afd40406b08..5717bb669d3f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -516,10 +516,11 @@ type Config struct { Output struct { Format string Color string - PrintIssuedLine bool `mapstructure:"print-issued-lines"` - PrintLinterName bool `mapstructure:"print-linter-name"` - UniqByLine bool `mapstructure:"uniq-by-line"` - PrintWelcomeMessage bool `mapstructure:"print-welcome"` + PrintIssuedLine bool `mapstructure:"print-issued-lines"` + PrintLinterName bool `mapstructure:"print-linter-name"` + UniqByLine bool `mapstructure:"uniq-by-line"` + PrintWelcomeMessage bool `mapstructure:"print-welcome"` + PathPrefix string `mapstructure:"path-prefix"` } LintersSettings LintersSettings `mapstructure:"linters-settings"` From 5648db39aae99ddcd337909a091292daf6ec6683 Mon Sep 17 00:00:00 2001 From: Joe Wilner Date: Thu, 9 Jul 2020 21:39:01 -0400 Subject: [PATCH 2/2] Update docs --- .golangci.example.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.golangci.example.yml b/.golangci.example.yml index 28e2715d897f..be5b865cf21e 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -72,6 +72,9 @@ output: # make issues output unique by line, default is true uniq-by-line: true + # add a prefix to the output file references; default is no prefix + path-prefix: "" + # all available settings of specific linters linters-settings: