All files / src/sdk report-files.ts

85.71% Statements 6/7
100% Branches 4/4
80% Functions 4/5
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                        4x 2x             9x   4x          
import type { FileReport, Finding, UsageStats } from '../types/index.js';
 
export interface FileReportInput {
  filename: string;
  durationMs?: number;
  usage?: UsageStats;
}
 
/**
 * Return whether a final finding should be counted against a file.
 */
export function findingAppliesToFile(finding: Finding, filename: string): boolean {
  if (finding.location?.path === filename) return true;
  return finding.additionalLocations?.some((location) => location.path === filename) ?? false;
}
 
/**
 * Count final findings per file while preserving timing and usage metadata.
 */
export function buildFileReports(files: FileReportInput[], findings: Finding[]): FileReport[] {
  return files.map((file) => ({
    filename: file.filename,
    findings: findings.filter((finding) => findingAppliesToFile(finding, file.filename)).length,
    durationMs: file.durationMs,
    usage: file.usage,
  }));
}