1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

formatters return output (#921)

Some of the formatters were writing directly to stdout instead of returning the output. That made them more difficult to use them with revivelib. This PR updates those formatters to write to a buffer and return the resulting string.
This commit is contained in:
WillAbides
2023-10-29 02:05:08 -05:00
committed by GitHub
parent 25ae73a67a
commit cb72bd880d
6 changed files with 207 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
package formatter
import (
"bytes"
"fmt"
"github.com/mgechev/revive/lint"
@@ -19,8 +20,9 @@ func (*Plain) Name() string {
// Format formats the failures gotten from the lint.
func (*Plain) Format(failures <-chan lint.Failure, _ lint.Config) (string, error) {
var buf bytes.Buffer
for failure := range failures {
fmt.Printf("%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
fmt.Fprintf(&buf, "%v: %s %s\n", failure.Position.Start, failure.Failure, "https://revive.run/r#"+failure.RuleName)
}
return "", nil
return buf.String(), nil
}