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: 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"`