move source code lines extraction to processor and store source lines in output json

This commit is contained in:
Denis Isaev 2018-08-18 15:41:17 +03:00 committed by Isaev Denis
parent f81283f38d
commit e58c27e463
9 changed files with 127 additions and 91 deletions

View file

@ -273,6 +273,26 @@ func (e *Executor) setOutputToDevNull() (savedStdout, savedStderr *os.File) {
return
}
func (e *Executor) setExitCodeIfIssuesFound(issues <-chan result.Issue) <-chan result.Issue {
resCh := make(chan result.Issue, 1024)
go func() {
issuesFound := false
for i := range issues {
issuesFound = true
resCh <- i
}
if issuesFound {
e.exitCode = e.cfg.Run.ExitCodeIfIssuesFound
}
close(resCh)
}()
return resCh
}
func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
if !logutils.HaveDebugTag("linters_output") {
// Don't allow linters and loader to print anything
@ -293,14 +313,10 @@ func (e *Executor) runAndPrint(ctx context.Context, args []string) error {
return err
}
gotAnyIssues, err := p.Print(ctx, issues)
if err != nil {
return fmt.Errorf("can't print %d issues: %s", len(issues), err)
}
issues = e.setExitCodeIfIssuesFound(issues)
if gotAnyIssues {
e.exitCode = e.cfg.Run.ExitCodeIfIssuesFound
return nil
if err = p.Print(ctx, issues); err != nil {
return fmt.Errorf("can't print %d issues: %s", len(issues), err)
}
return nil