openclaw/scripts/lib/grouped-findings.ts
Peter Steinberger 982f9f8bcf
refactor(scripts): reuse report grouping owner (#161672)
Reuse the existing scripts groupBy owner in the shared test-report renderer. Preserve first-seen order, finding order, complete counts, output caps and all CLI/guard contracts. Remove six production lines without changing tests or dependencies.

Validation: 19 existing focused cases, scoped lint, both zero-cycle checks and independent review. Release notes: internal tooling cleanup only.
2026-09-30 06:07:52 +00:00

32 lines
884 B
TypeScript

import { groupBy } from "./group-by.mts";
export function renderFindingGroups<T extends { file: string }>(
findings: T[],
limit: number,
renderFinding: (finding: T) => string,
): string[] {
// Group before applying the cap so counts stay complete and files keep first-seen order.
const grouped = groupBy(findings, (finding) => finding.file);
const lines: string[] = [];
let shown = 0;
for (const [file, fileFindings] of grouped) {
if (shown >= limit) {
break;
}
lines.push(`- ${file} (${fileFindings.length})`);
for (const finding of fileFindings) {
if (shown >= limit) {
break;
}
lines.push(renderFinding(finding));
shown += 1;
}
}
if (findings.length > shown) {
lines.push(
`... ${findings.length - shown} more finding(s) not shown; pass --limit 0 to show all.`,
);
}
return lines;
}