Skip to content

Commit

Permalink
Add stdout report output
Browse files Browse the repository at this point in the history
Review fixes

Fix output error
  • Loading branch information
Danil42Russia committed Apr 19, 2022
1 parent 4047494 commit d8f6a2d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/cmd/linter_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,11 @@ func (l *LinterRunner) Init(ruleSets []*rules.Set, flags *ParsedFlags) error {
return fmt.Errorf("collect gitignore files: %v", err)
}

l.outputFp = os.Stderr
if flags.Output != "" {
outputFp, err := os.OpenFile(flags.Output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return fmt.Errorf("-output=%s: %v", flags.Output, err)
}
l.outputFp = outputFp
w, err := createWriter(flags.Output)
if err != nil {
return fmt.Errorf("--output=%s: %v", flags.Output, err)
}
l.outputFp = w

if !flags.IgnoreVendor {
flags.IndexOnlyFiles = l.addVendorFolderToFlag(flags.IndexOnlyFiles, false)
Expand Down Expand Up @@ -305,3 +302,19 @@ func LoadMisspellDicts(config *linter.Config, dicts []string) error {
config.TypoFixer.Compile()
return nil
}

func createWriter(output string) (io.Writer, error) {
if output == "" || output == "stderr" {
return os.Stderr, nil
}
if output == "stdout" {
return os.Stdout, nil
}

outputFp, err := os.OpenFile(output, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return nil, err
}

return outputFp, nil
}

0 comments on commit d8f6a2d

Please sign in to comment.