Files
skillshare/internal/audit/display.go
T
Willieandsim 9c916df663 fix(audit): keep clean resources visible under a display floor (#785)
With --min-severity set, the TUI dropped every result without visible
findings, so clean skills disappeared from the list and the tab count
shrank, while text and Markdown output kept them. The rule now lives in
audit.HiddenByFloor and both the TUI and text output use it: a floor
hides only a result whose findings all fall below it and that is not
blocked.

The dashboard severity buttons label themselves with the English
severity, matching the badge they show, so the six translated label
keys added for them are gone. AuditPage.test.tsx again asserts the
exact coverage line and count instead of any three digits, and drops a
rendered test that only checked translated labels. The audit-engine
paragraph about --min-severity now appears in all four translations.

Co-authored-by: sim <sim@example.invalid>
2026-11-06 14:21:21 +08:00

35 lines
1.2 KiB
Go

package audit
// DisplayFindings selects findings at or above a normalized display floor.
// An empty floor preserves all findings. Callers must retain the original
// results for scoring, blocking, machine output and completeness reporting.
func DisplayFindings(findings []Finding, minSeverity string) []Finding {
if minSeverity == "" {
return findings
}
visible := make([]Finding, 0, len(findings))
for _, f := range findings {
if SeverityRank(f.Severity) <= SeverityRank(minSeverity) {
visible = append(visible, f)
}
}
return visible
}
// HiddenByFloor reports whether a display floor hides r entirely: it has
// findings, all below the floor, and is not blocked. Clean and blocked
// results stay visible.
func HiddenByFloor(r *Result, minSeverity string) bool {
return minSeverity != "" && !r.IsBlocked && len(r.Findings) > 0 && len(DisplayFindings(r.Findings, minSeverity)) == 0
}
// DisplayCounts reports finding counts before and after applying a display floor.
func DisplayCounts(results []*Result, minSeverity string) (visible, hidden int) {
for _, r := range results {
n := len(DisplayFindings(r.Findings, minSeverity))
visible += n
hidden += len(r.Findings) - n
}
return visible, hidden
}