Skip to content

Commit 6cc1f68

Browse files
refactor: remove default formatter template
1 parent 6bf09ee commit 6cc1f68

File tree

4 files changed

+43
-188
lines changed

4 files changed

+43
-188
lines changed

formatter/default.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package formatter
33

44
import (
5+
"fmt"
6+
"strconv"
57
"strings"
68

79
"github.com/conventionalcommit/commitlint/lint"
@@ -15,6 +17,37 @@ func (f *DefaultFormatter) Name() string { return "default" }
1517

1618
// Format formats the lint.Result
1719
func (f *DefaultFormatter) Format(res *lint.Result) (string, error) {
18-
msg := formatResult(res)
19-
return strings.Trim(msg, "\n"), nil
20+
return formatResult(res), nil
21+
}
22+
23+
func formatResult(res *lint.Result) string {
24+
if res.IsOK() {
25+
return " ✔ commit message"
26+
}
27+
return writeResult(res)
28+
}
29+
30+
func writeResult(res *lint.Result) string {
31+
str := &strings.Builder{}
32+
33+
str.WriteString("commitlint")
34+
fmt.Fprintf(str, "\n\n→ input: %s", strconv.Quote(truncate(25, res.Input())))
35+
36+
if res.HasErrors() {
37+
writeLintResult(str, "Errors", res.Errors(), "❌")
38+
}
39+
40+
if res.HasWarns() {
41+
writeLintResult(str, "Warnings", res.Warns(), "!")
42+
}
43+
44+
fmt.Fprintf(str, "\n\nTotal %d errors, %d warnings", len(res.Errors()), len(res.Warns()))
45+
return str.String()
46+
}
47+
48+
func writeLintResult(w *strings.Builder, title string, resArr []lint.RuleResult, sign string) {
49+
fmt.Fprint(w, "\n\n"+title+":")
50+
for _, msg := range resArr {
51+
fmt.Fprintf(w, "\n %s %s: %s", sign, msg.Name, msg.Message)
52+
}
2053
}

formatter/default.qtpl

Lines changed: 0 additions & 52 deletions
This file was deleted.

formatter/default.qtpl.go

Lines changed: 0 additions & 134 deletions
This file was deleted.

formatter/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package formatter
2+
3+
func truncate(maxSize int, input string) string {
4+
if len(input) < maxSize {
5+
return input
6+
}
7+
return input[:maxSize-3] + "..."
8+
}

0 commit comments

Comments
 (0)