Skip to content

Commit 7ff0b70

Browse files
committedJan 12, 2025
Improve reported line sorting
1 parent d850cbe commit 7ff0b70

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed
 

‎packages/knip/src/reporters/symbols.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ const TRUNCATE_WIDTH = 40;
1313
const truncate = (text: string) => (text.length > TRUNCATE_WIDTH ? `${text.slice(0, TRUNCATE_WIDTH - 3)}...` : text);
1414
const truncateStart = (text: string, width: number) => (text.length > width ? `...${text.slice(-(width - 3))}` : text);
1515

16+
const sortByPos = (a: Issue, b: Issue) => {
17+
const [f, r, c] = a.filePath.split(':');
18+
const [f2, r2, c2] = b.filePath.split(':');
19+
return f === f2 ? (Number(r) === Number(r2) ? Number(c) - Number(c2) : Number(r) - Number(r2)) : f.localeCompare(f2);
20+
};
21+
1622
const hl = (issue: Issue) => {
1723
if (issue.specifier && issue.specifier !== issue.symbol && issue.specifier.includes(issue.symbol)) {
1824
const parts = issue.specifier.split(issue.symbol);
@@ -38,7 +44,7 @@ const logIssueRecord = (issues: Issue[]) => {
3844
issue.isFixed && table.cell('fixed', print('(removed)'));
3945
table.newRow();
4046
}
41-
console.log(table.sort(['filePath', 'parentSymbol', 'symbol']).print().trim());
47+
console.log(table.sort(sortByPos).print().trim());
4248
};
4349

4450
export default ({ report, issues, tagHints, configurationHints, noConfigHints, isShowProgress }: ReporterOptions) => {

0 commit comments

Comments
 (0)
Please sign in to comment.