Skip to content

Commit

Permalink
Deduplicate error messages in link checker for same link in same file (
Browse files Browse the repository at this point in the history
…Qiskit#553)

Otherwise, we get a couple of duplicate error messages. This happens
when the same file has the same bad link >1 times.
  • Loading branch information
Eric-Arellano authored Dec 22, 2023
1 parent ffac062 commit 4a8b8a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions scripts/lib/LinkChecker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ describe("Test the constructor of Link", () => {
testLink.originFiles,
testLink.isExternal,
];
const correct_values = ["/testpath", "", ["/testorigin.mdx"], false];
const correct_values = [
"/testpath",
"",
new Set(["/testorigin.mdx"]),
false,
];
expect(attributes).toEqual(correct_values);
});

Expand All @@ -37,7 +42,7 @@ describe("Test the constructor of Link", () => {
const correct_values = [
"/testpath",
"#testanchor",
["/testorigin.mdx"],
new Set(["/testorigin.mdx"]),
false,
];
expect(attributes).toEqual(correct_values);
Expand All @@ -54,7 +59,7 @@ describe("Test the constructor of Link", () => {
const correct_values = [
"https://test.link.com",
"",
["/testorigin.mdx"],
new Set(["/testorigin.mdx"]),
true,
];
expect(attributes).toEqual(correct_values);
Expand Down Expand Up @@ -129,6 +134,8 @@ describe("Validate links", () => {
let testLink = new Link("../testpath", [
"docs/test/testorigin.mdx",
"docs/test/test2/testorigin.mdx",
// Duplicate of the above value to confirm we de-duplicate originFiles.
"docs/test/test2/testorigin.mdx",
"docs/test/test3/testorigin.mdx",
"docs/test/test2/test4/testorigin.mdx",
]);
Expand Down
4 changes: 2 additions & 2 deletions scripts/lib/LinkChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class File {
export class Link {
readonly value: string;
readonly anchor: string;
readonly originFiles: string[];
readonly originFiles: Set<string>;
readonly isExternal: boolean;

/**
Expand All @@ -46,7 +46,7 @@ export class Link {
const splitLink = linkString.split("#", 2);
this.value = splitLink[0];
this.anchor = splitLink.length > 1 ? `#${splitLink[1]}` : "";
this.originFiles = originFiles;
this.originFiles = new Set(originFiles);
this.isExternal = linkString.startsWith("http");
}

Expand Down

0 comments on commit 4a8b8a5

Please sign in to comment.