Skip to content

Commit a6b2b9e

Browse files
committed
Truncate start of lengthy symbols
1 parent daf92ce commit a6b2b9e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/knip/src/reporters/symbols.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ const bright = picocolors.whiteBright;
1111

1212
const TRUNCATE_WIDTH = 40;
1313
const truncate = (text: string) => (text.length > TRUNCATE_WIDTH ? `${text.slice(0, TRUNCATE_WIDTH - 3)}...` : text);
14+
const truncateStart = (text: string, width: number) => (text.length > width ? `...${text.slice(-(width - 3))}` : text);
1415

1516
const hl = (issue: Issue) => {
1617
if (issue.specifier && issue.specifier !== issue.symbol && issue.specifier.includes(issue.symbol)) {
1718
const parts = issue.specifier.split(issue.symbol);
18-
const rest = parts.slice(1).join('');
19-
return [dim(parts[0]), bright(issue.symbol), dim(rest)].join('');
19+
const right = parts.slice(1).join('');
20+
const max = TRUNCATE_WIDTH - issue.symbol.length - right.length;
21+
const part = parts[0];
22+
const left = part.length > 3 ? (max <= 3 ? `...${part.slice(-3)}` : truncateStart(part, max)) : part;
23+
return [dim(left), bright(issue.symbol), dim(right)].join('');
2024
}
2125
return issue.symbol;
2226
};

0 commit comments

Comments
 (0)