import type { LintResult } from './diagnostic.js' export type LintReportFormat = 'json' | 'stylish' export function formatLintResult(result: LintResult, format: LintReportFormat = 'stylish'): string { if (format === 'json') return `${JSON.stringify(result, null, 2)}\n` const lines: string[] = [] for (const diagnostic of result.diagnostics) { const location = diagnostic.location ? `${diagnostic.location.path}:${diagnostic.location.line}:${diagnostic.location.column}` : result.root lines.push(`${location} ${diagnostic.severity} ${diagnostic.id} ${diagnostic.message}`) if (diagnostic.help) lines.push(` ${diagnostic.help}`) } const errors = result.diagnostics.filter((diagnostic) => diagnostic.severity === 'error').length const warnings = result.diagnostics.length - errors if (lines.length > 0) lines.push('') lines.push( errors === 0 ? `\u2713 ${result.files} files linted in ${result.durationMs}ms${warnings ? ` (${warnings} warnings)` : ''}` : `\u2717 ${errors} ${errors === 1 ? 'error' : 'errors'}, ${warnings} ${warnings === 1 ? 'warning' : 'warnings'} in ${result.durationMs}ms`, ) return `${lines.join('\n')}\n` }