-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.go
More file actions
95 lines (90 loc) · 2.35 KB
/
format.go
File metadata and controls
95 lines (90 loc) · 2.35 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package repogov
import (
"fmt"
"strings"
)
// Passed returns true when every [Result] has status [Pass], [Warn],
// or [Skip]. A single [Fail] makes the overall check fail.
func Passed(results []Result) bool {
for _, r := range results {
if r.Status == Fail {
return false
}
}
return true
}
// Summary returns a human-readable multi-line summary of the results.
// Each line shows the status, path, line count vs. limit, percentage,
// and an actionable hint for WARN/FAIL outcomes. The format is designed
// to be consumed by AI agents, LLMs, and MCP tools.
func Summary(results []Result) string {
if len(results) == 0 {
return "No files checked."
}
var b strings.Builder
pass, warn, fail, skip := 0, 0, 0, 0
for _, r := range results {
switch r.Status {
case Pass:
pass++
case Warn:
warn++
case Fail:
fail++
case Skip:
skip++
}
if r.Limit > 0 {
pct := 100 * r.Lines / r.Limit
if r.Action != "" {
fmt.Fprintf(&b, " [%s] %s (%d / %d, %d%%) -- %s\n",
r.Status, r.Path, r.Lines, r.Limit, pct, r.Action)
} else {
fmt.Fprintf(&b, " [%s] %s (%d / %d, %d%%)\n",
r.Status, r.Path, r.Lines, r.Limit, pct)
}
} else {
fmt.Fprintf(&b, " [%s] %s (%d / %d)\n",
r.Status, r.Path, r.Lines, r.Limit)
}
}
fmt.Fprintf(&b, "\nLimits: %d files | %d pass | %d warn | %d fail | %d skip\n\n",
len(results), pass, warn, fail, skip)
return b.String()
}
// LayoutPassed returns true when every [LayoutResult] has status [Pass],
// [Info], or [Skip].
func LayoutPassed(results []LayoutResult) bool {
for _, r := range results {
if r.Status == Fail {
return false
}
}
return true
}
// LayoutSummary returns a human-readable multi-line summary of layout
// check results. The format includes actionable messages for FAIL and
// WARN outcomes, designed for AI agents, LLMs, and MCP tools.
func LayoutSummary(results []LayoutResult) string {
if len(results) == 0 {
return "No layout checks performed."
}
var b strings.Builder
pass, warn, fail, info := 0, 0, 0, 0
for _, r := range results {
switch r.Status {
case Pass:
pass++
case Warn:
warn++
case Fail:
fail++
case Info:
info++
}
fmt.Fprintf(&b, " [%s] %s -- %s\n", r.Status, r.Path, r.Message)
}
fmt.Fprintf(&b, "\nLayout: %d checks | %d pass | %d warn | %d fail | %d info\n\n",
len(results), pass, warn, fail, info)
return b.String()
}