|
| 1 | +import EasyTable from 'easy-table'; |
| 2 | +import type { Entries } from 'type-fest'; |
| 3 | +import type { Issue, ReporterOptions } from '../types/issues.js'; |
| 4 | +import { relative, toRelative } from '../util/path.js'; |
| 5 | +import { getTitle } from './util.js'; |
| 6 | + |
| 7 | +const printHeader = (size: number, title?: string) => |
| 8 | + console.log(`<details>${title ? `<summary>${title} (${size})</summary>` : ''}\n\n\`\`\``); |
| 9 | + |
| 10 | +const printFooter = () => console.log('```\n\n</details>\n'); |
| 11 | + |
| 12 | +const logIssueRecord = (issues: Issue[]) => { |
| 13 | + const table = new EasyTable(); |
| 14 | + for (const issue of issues) { |
| 15 | + table.cell('symbol', issue.symbols ? issue.symbols.map(s => s.symbol).join(', ') : issue.symbol); |
| 16 | + issue.parentSymbol && table.cell('parentSymbol', issue.parentSymbol); |
| 17 | + issue.symbolType && table.cell('symbolType', issue.symbolType); |
| 18 | + const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`; |
| 19 | + const cell = `${relative(issue.filePath)}${pos}`; |
| 20 | + table.cell('filePath', cell); |
| 21 | + table.newRow(); |
| 22 | + } |
| 23 | + console.log(table.sort(['filePath', 'parentSymbol', 'symbol']).print().trim()); |
| 24 | +}; |
| 25 | + |
| 26 | +export default ({ report, issues }: ReporterOptions) => { |
| 27 | + const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1; |
| 28 | + let totalIssues = 0; |
| 29 | + |
| 30 | + for (const [reportType, isReportType] of Object.entries(report) as Entries<typeof report>) { |
| 31 | + if (reportType === '_files') continue; |
| 32 | + |
| 33 | + if (isReportType) { |
| 34 | + const title = reportMultipleGroups ? getTitle(reportType) : undefined; |
| 35 | + |
| 36 | + if (reportType === 'files') { |
| 37 | + const issuesForType = Array.from(issues._files); |
| 38 | + if (issuesForType.length > 0) { |
| 39 | + printHeader(issuesForType.length, title); |
| 40 | + const sortedIssues = issuesForType.sort((a, b) => a.filePath.localeCompare(b.filePath)); |
| 41 | + for (const issue of sortedIssues) console.log(toRelative(issue.filePath)); |
| 42 | + totalIssues = totalIssues + issuesForType.length; |
| 43 | + printFooter(); |
| 44 | + } |
| 45 | + } else { |
| 46 | + const issuesForType = Object.values(issues[reportType]).flatMap(Object.values); |
| 47 | + if (issuesForType.length > 0) { |
| 48 | + printHeader(issuesForType.length, title); |
| 49 | + logIssueRecord(issuesForType); |
| 50 | + totalIssues = totalIssues + issuesForType.length; |
| 51 | + printFooter(); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +}; |
0 commit comments