github.com/Johnny2210/revive@v1.0.8-0.20210625134200-febf37ccd0f5/formatter/ndjson.go (about) 1 package formatter 2 3 import ( 4 "encoding/json" 5 "os" 6 7 "github.com/mgechev/revive/lint" 8 ) 9 10 // NDJSON is an implementation of the Formatter interface 11 // which formats the errors to NDJSON stream. 12 type NDJSON struct { 13 Metadata lint.FormatterMetadata 14 } 15 16 // Name returns the name of the formatter 17 func (f *NDJSON) Name() string { 18 return "ndjson" 19 } 20 21 // Format formats the failures gotten from the lint. 22 func (f *NDJSON) Format(failures <-chan lint.Failure, config lint.Config) (string, error) { 23 enc := json.NewEncoder(os.Stdout) 24 for failure := range failures { 25 obj := jsonObject{} 26 obj.Severity = severity(config, failure) 27 obj.Failure = failure 28 err := enc.Encode(obj) 29 if err != nil { 30 return "", err 31 } 32 } 33 return "", nil 34 }