Skip to content

Commit 066a396

Browse files
Deduplicate error messages in link checker for same link in same file (Qiskit#553)
Otherwise, we get a couple of duplicate error messages. This happens when the same file has the same bad link >1 times.
1 parent 0a41a7b commit 066a396

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

scripts/lib/LinkChecker.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ describe("Test the constructor of Link", () => {
2222
testLink.originFiles,
2323
testLink.isExternal,
2424
];
25-
const correct_values = ["/testpath", "", ["/testorigin.mdx"], false];
25+
const correct_values = [
26+
"/testpath",
27+
"",
28+
new Set(["/testorigin.mdx"]),
29+
false,
30+
];
2631
expect(attributes).toEqual(correct_values);
2732
});
2833

@@ -37,7 +42,7 @@ describe("Test the constructor of Link", () => {
3742
const correct_values = [
3843
"/testpath",
3944
"#testanchor",
40-
["/testorigin.mdx"],
45+
new Set(["/testorigin.mdx"]),
4146
false,
4247
];
4348
expect(attributes).toEqual(correct_values);
@@ -54,7 +59,7 @@ describe("Test the constructor of Link", () => {
5459
const correct_values = [
5560
"https://test.link.com",
5661
"",
57-
["/testorigin.mdx"],
62+
new Set(["/testorigin.mdx"]),
5863
true,
5964
];
6065
expect(attributes).toEqual(correct_values);
@@ -129,6 +134,8 @@ describe("Validate links", () => {
129134
let testLink = new Link("../testpath", [
130135
"docs/test/testorigin.mdx",
131136
"docs/test/test2/testorigin.mdx",
137+
// Duplicate of the above value to confirm we de-duplicate originFiles.
138+
"docs/test/test2/testorigin.mdx",
132139
"docs/test/test3/testorigin.mdx",
133140
"docs/test/test2/test4/testorigin.mdx",
134141
]);

scripts/lib/LinkChecker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class File {
3535
export class Link {
3636
readonly value: string;
3737
readonly anchor: string;
38-
readonly originFiles: string[];
38+
readonly originFiles: Set<string>;
3939
readonly isExternal: boolean;
4040

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

0 commit comments

Comments
 (0)