UNPKG

smells-code-analyzer

Version:

CLI tool powered by LSP and tree-sitter for finding dead and smells code from your project

33 lines 1.25 kB
export function buildReport(fullNodesInfo, showAll = false, includeFileName = true, tabs = 0, blockSeparator = '\n' + '-'.repeat(80)) { if (!fullNodesInfo?.length) { return ''; } const reports = fullNodesInfo .filter((n) => showAll || hasErrors(n)) .map((n) => { const reasons = []; if (n.references === 0) { reasons.push('dead code'); } if (n.parentNamePrefix) { reasons.push(`useless prefix`); } const baseInfo = `${'\t'.repeat(tabs)}[${reasons.length === 0 ? '✅' : '💩'}] ${n.name}:${n.startPos.row}:${n.startPos.column} :: (${reasons.join(', ')})`; const childrenInfo = buildReport(n.children, showAll, false, tabs + 1, ''); if (!childrenInfo?.length) { return baseInfo; } return baseInfo + '\n' + childrenInfo; }); if (reports.length) { const prefix = includeFileName ? fullNodesInfo[0].filePath + '\n' : ''; return prefix + reports.join('\n') + blockSeparator + '\n'; } return ''; } function hasErrors(n) { return (n.references === 0 || n.parentNamePrefix || n.children?.some((nc) => hasErrors(nc))); } //# sourceMappingURL=report.js.map