1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-30 08:57:07 +02:00

Update formatters

This commit is contained in:
mgechev 2018-01-23 18:19:06 -08:00
parent 5c6de19f89
commit 25cfe541d2
6 changed files with 13 additions and 8 deletions

View File

@ -37,6 +37,7 @@ func (f *CLIFormatter) Format(failures <-chan linter.Failure) (string, error) {
var result [][]string var result [][]string
var totalErrors = 0 var totalErrors = 0
var total = 0 var total = 0
for f := range failures { for f := range failures {
result = append(result, formatFailure(f)) result = append(result, formatFailure(f))
total++ total++

View File

@ -14,9 +14,13 @@ type JSONFormatter struct {
// Format formats the failures gotten from the linter. // Format formats the failures gotten from the linter.
func (f *JSONFormatter) Format(failures <-chan linter.Failure) (string, error) { func (f *JSONFormatter) Format(failures <-chan linter.Failure) (string, error) {
result, error := json.Marshal(failures) var slice []linter.Failure
if error != nil { for failure := range failures {
return "", error slice = append(slice, failure)
} }
return string(result), nil result, err := json.Marshal(slice)
if err != nil {
return "", err
}
return string(result), err
} }

View File

@ -4,4 +4,4 @@ import:
- package: github.com/mattn/go-runewidth - package: github.com/mattn/go-runewidth
version: ~0.0.2 version: ~0.0.2
- package: github.com/fatih/color - package: github.com/fatih/color
version: ~1.5.0 version: ~1.5.0

View File

@ -9,5 +9,5 @@ type FormatterMetadata struct {
// Formatter defines an interface for failure formatters // Formatter defines an interface for failure formatters
type Formatter interface { type Formatter interface {
Format(<-chan Failure) string Format(<-chan Failure, <-chan string, int) string
} }

View File

@ -28,7 +28,7 @@ type Failure struct {
Category string Category string
Type FailureType Type FailureType
Position FailurePosition Position FailurePosition
Node ast.Node Node ast.Node `json:"-"`
Confidence float64 Confidence float64
} }

View File

@ -40,7 +40,7 @@ func main() {
panic(err) panic(err)
} }
var formatter formatter.CLIFormatter var formatter formatter.JSONFormatter
output, err := formatter.Format(failures) output, err := formatter.Format(failures)
if err != nil { if err != nil {
panic(err) panic(err)