import type { Priority } from '@repo/types' import type { OutputFormat } from './args' /** One finding, normalized across `review` (per file) and `audit` (per URL). */ export interface Finding { target: string rule: string title: string priority: Priority issue: string fix?: string } /** * Write a JSON document to stdout (machine-readable contract). * * @param value - Serializable value. */ export function writeJson(value: unknown): void { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`) } /** * Write plain lines to stdout. * * @param lines - Lines to print. */ export function writeLines(lines: string[]): void { process.stdout.write(`${lines.join('\n')}\n`) } /** * Escape text for HTML output. * * @param text - Raw text. * @returns Escaped text. */ function escapeHtml(text: string): string { return text .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') } /** * Render findings as Markdown. * * @param title - Report heading. * @param findings - Findings to list. * @returns Markdown text. */ function findingsMarkdown(title: string, findings: Finding[]): string { const rows = findings.map( f => `| ${f.priority} | \`${f.rule}\` | ${f.target} | ${f.issue.replace(/\|/g, '\\|')} |` ) return [ `# ${title}`, '', `${findings.length} issue(s).`, '', '| Priority | Rule | Target | Issue |', '| --- | --- | --- | --- |', ...rows ].join('\n') } /** * Render findings as a standalone HTML page. * * @param title - Report heading. * @param findings - Findings to list. * @returns HTML document. */ function findingsHtml(title: string, findings: Finding[]): string { const rows = findings .map( f => `
${escapeHtml(f.rule)}| Priority | Rule | Target | Issue |
|---|