You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ndjson.go 733B

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