forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter_pretty.go
61 lines (46 loc) · 1.13 KB
/
formatter_pretty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package lint
import (
"fmt"
"strings"
)
const (
lintIndentation = " "
)
type formatterPretty struct{}
const (
escape = "\x1b"
noFormat = 0
underline = "4"
fgRed = "31"
fgGreen = "32"
)
func withAttribute(s, color string) string {
return fmt.Sprintf("%s[%sm%s%s[%dm", escape, color, s, escape, noFormat)
}
func (f formatterPretty) Format(l *LintResults) string {
if l.Success {
return fmt.Sprintf("%s no linting errors found!\n", withAttribute("✔", fgGreen))
}
if !l.anythingLinted {
return fmt.Sprintf("%s\n", withAttribute("✖ found nothing to lint in the specified paths, failing...", fgRed))
}
sb := &strings.Builder{}
totErr := 0
for _, r := range l.Results {
if !r.Linted {
continue
}
nErr := len(r.Errs)
if nErr == 0 {
continue
}
fmt.Fprintf(sb, "%s:\n", withAttribute(r.File, underline)) // print source name
totErr += nErr
for _, e := range r.Errs {
fmt.Fprintf(sb, "%s%s %s\n", lintIndentation, withAttribute("✖", fgRed), e)
}
fmt.Fprintln(sb)
}
fmt.Fprintf(sb, "%s\n", withAttribute(fmt.Sprintf("✖ %d linting errors found!", totErr), fgRed))
return sb.String()
}