Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions tools/links-check/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { Report } from "./report";

export function generateNotes(report: Report, label?: string): INotesEnvelopeV3 {
const perLink = new Map<string, { file: string; link: Link }[]>();
const commonPath: Map<string, number>[] = [];
const commonPathComponents: Map<string, number>[] = [];

for (const [file, links] of report.detected) {
const parts = file.split("/");
for (let i = 0; i < parts.length; i++) {
commonPath[i] = commonPath[i] || new Map();
commonPath[i].set(parts[i], (commonPath[i].get(parts[i]) || 0) + 1);
commonPathComponents[i] = commonPathComponents[i] || new Map();
commonPathComponents[i].set(parts[i], (commonPathComponents[i].get(parts[i]) || 0) + 1);
}

for (const link of links) {
Expand All @@ -25,21 +25,25 @@ export function generateNotes(report: Report, label?: string): INotesEnvelopeV3
}

const noOfFiles = report.detected.size;
const path = commonPath
.map((x) => {
for (const [k, count] of x.entries()) {
if (count === noOfFiles) {
return k;
}
return null;
}
})
.filter((x) => x)
.join("/");
// avoid stripping commonPath if we only have one file.
const commonPath =
noOfFiles < 2
? ""
: commonPathComponents
.map((x) => {
for (const [k, count] of x.entries()) {
if (count === noOfFiles) {
return k;
}
return null;
}
})
.filter((x) => x)
.join("/");

const notes = [];
for (const [_, linkData] of perLink) {
const note = linkToNote(linkData, path);
const note = linkToNote(linkData, commonPath);
if (label) {
note.labels.push(label);
}
Expand Down