github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/report/reporters/unixReporter.go (about)

     1  package reporters
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/yoheimuta/protolint/linter/report"
     8  )
     9  
    10  // UnixReporter prints failures as it respects Unix output conventions
    11  // those are frequently employed by preprocessors and compilers.
    12  //
    13  // The format is "FILENAME:LINE:COL: MESSAGE".
    14  type UnixReporter struct{}
    15  
    16  // Report writes failures to w.
    17  func (r UnixReporter) Report(w io.Writer, fs []report.Failure) error {
    18  	for _, failure := range fs {
    19  		unix := fmt.Sprintf(
    20  			"%s: %s",
    21  			failure.Pos(),
    22  			failure.Message(),
    23  		)
    24  		_, err := fmt.Fprintln(w, unix)
    25  		if err != nil {
    26  			return err
    27  		}
    28  	}
    29  	return nil
    30  }