github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/linter/report/reporters/tscReporter.go (about) 1 package reporters 2 3 import ( 4 "fmt" 5 "io" 6 "strings" 7 8 "github.com/yoheimuta/protolint/linter/report" 9 ) 10 11 // TscRport prints failures as string compatible to Type script compiler 12 // 13 // The format is "FILENAME(LINE,COL): SEVERITY RULE_ID: MESSAGE". 14 type TscReporter struct{} 15 16 func getTscSeverity(s string) string { 17 if s == "note" { 18 return "info" 19 } 20 21 return s 22 } 23 24 // Report writes failures to w. 25 func (r TscReporter) Report(w io.Writer, fs []report.Failure) error { 26 for _, failure := range fs { 27 tsc_output := fmt.Sprintf( 28 "%s(%d,%d): %s %s: '%s'", 29 failure.Pos().Filename, 30 failure.Pos().Line, 31 failure.Pos().Column, 32 getTscSeverity(failure.Severity()), 33 failure.RuleID(), 34 strings.Trim(failure.Message(), `"`), 35 ) 36 _, err := fmt.Fprintln(w, tsc_output) 37 if err != nil { 38 return err 39 } 40 } 41 return nil 42 }