mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
- Created cli/groupers/ViolationGrouper.ts for severity filtering - Created cli/formatters/OutputFormatter.ts for violation formatting - Created cli/formatters/StatisticsFormatter.ts for metrics display - Reduced cli/index.ts from 484 to 260 lines (46% reduction) - All 345 tests pass, CLI output identical to before - No breaking changes
30 lines
889 B
TypeScript
30 lines
889 B
TypeScript
import { SEVERITY_ORDER, type SeverityLevel } from "../../shared/constants"
|
|
|
|
export class ViolationGrouper {
|
|
groupBySeverity<T extends { severity: SeverityLevel }>(
|
|
violations: T[],
|
|
): Map<SeverityLevel, T[]> {
|
|
const grouped = new Map<SeverityLevel, T[]>()
|
|
|
|
for (const violation of violations) {
|
|
const existing = grouped.get(violation.severity) ?? []
|
|
existing.push(violation)
|
|
grouped.set(violation.severity, existing)
|
|
}
|
|
|
|
return grouped
|
|
}
|
|
|
|
filterBySeverity<T extends { severity: SeverityLevel }>(
|
|
violations: T[],
|
|
minSeverity?: SeverityLevel,
|
|
): T[] {
|
|
if (!minSeverity) {
|
|
return violations
|
|
}
|
|
|
|
const minSeverityOrder = SEVERITY_ORDER[minSeverity]
|
|
return violations.filter((v) => SEVERITY_ORDER[v.severity] <= minSeverityOrder)
|
|
}
|
|
}
|