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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user