@@ -15,40 +15,42 @@ type DefaultFormatter struct{}
1515// Name returns name of formatter
1616func (f * DefaultFormatter ) Name () string { return "default" }
1717
18- // Format formats the lint.Result
19- func (f * DefaultFormatter ) Format (res * lint.Result ) (string , error ) {
20- return formatResult (res ), nil
18+ // Format formats the lint.Failure
19+ func (f * DefaultFormatter ) Format (res * lint.Failure ) (string , error ) {
20+ return formatFailure (res ), nil
2121}
2222
23- func formatResult (res * lint.Result ) string {
23+ func formatFailure (res * lint.Failure ) string {
2424 if res .IsOK () {
2525 return " ✔ commit message"
2626 }
27- return writeResult (res )
27+ return writeFailure (res )
2828}
2929
30- func writeResult (res * lint.Result ) string {
30+ func writeFailure (res * lint.Failure ) string {
3131 str := & strings.Builder {}
3232
3333 str .WriteString ("commitlint" )
3434 fmt .Fprintf (str , "\n \n → input: %s" , strconv .Quote (truncate (25 , res .Input ())))
3535
36- if res .HasErrors () {
37- writeLintResult (str , "Errors" , res .Errors (), "❌" )
38- }
36+ errs , warns , others := bySeverity (res )
3937
40- if res . HasWarns () {
41- writeLintResult (str , "Warnings" , res . Warns () , "!" )
42- }
38+ writeRuleFailure ( str , "Errors" , errs , "❌" )
39+ writeRuleFailure (str , "Warnings" , warns , "!" )
40+ writeRuleFailure ( str , "Other Severities" , others , "?" )
4341
44- fmt .Fprintf (str , "\n \n Total %d errors, %d warnings" , len (res . Errors ()) , len (res . Warns () ))
42+ fmt .Fprintf (str , "\n \n Total %d errors, %d warnings, %d other severities " , len (errs ) , len (warns ), len ( others ))
4543 return str .String ()
4644}
4745
48- func writeLintResult (w * strings.Builder , title string , resArr []lint.RuleResult , sign string ) {
46+ func writeRuleFailure (w * strings.Builder , title string , resArr []* lint.RuleFailure , sign string ) {
47+ if len (resArr ) == 0 {
48+ return
49+ }
50+
4951 fmt .Fprint (w , "\n \n " + title + ":" )
5052 for _ , msg := range resArr {
51- fmt .Fprintf (w , "\n %s %s: %s" , sign , msg .Name , msg .Message )
53+ fmt .Fprintf (w , "\n %s %s: %s" , sign , msg .RuleName () , msg .Message () )
5254 }
5355}
5456
0 commit comments