Skip to content

Commit

Permalink
Link checker: Add a method to ignore non-API docs for objects.inv (#2337
Browse files Browse the repository at this point in the history
)

This PR adds a new mechanism to ignore links where we can add a regex
expression to ignore all the URLs that match it. It adds regexes for the
non-API docs in the addons' and runtime's objects.inv.

Closes #2296
  • Loading branch information
arnaucasau authored Nov 18, 2024
1 parent b3861e2 commit 79746ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
5 changes: 4 additions & 1 deletion scripts/js/lib/links/FileBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ALWAYS_IGNORED_URL_PREFIXES,
FILES_TO_IGNORES,
IGNORED_FILES,
ALWAYS_IGNORED_URL_REGEXES,
} from "./ignores.js";
import { parseFile } from "./extractLinks.js";

Expand Down Expand Up @@ -112,12 +113,14 @@ export function addLinksToMap(
links: Set<string>,
linksToOriginFiles: Map<string, string[]>,
): void {
const ignoreUrlsRegex = new RegExp(ALWAYS_IGNORED_URL_REGEXES.join("|"), "i");
if (IGNORED_FILES.has(filePath)) return;
links.forEach((link) => {
if (
ALWAYS_IGNORED_URLS.has(link) ||
ALWAYS_IGNORED_URL_PREFIXES.some((prefix) => link.startsWith(prefix)) ||
FILES_TO_IGNORES[filePath]?.includes(link)
FILES_TO_IGNORES[filePath]?.includes(link) ||
ignoreUrlsRegex.test(link)
) {
return;
}
Expand Down
54 changes: 42 additions & 12 deletions scripts/js/lib/links/ignores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@
// Ignored files
// -----------------------------------------------------------------------------------

export const IGNORED_FILES = new Set([
"public/api/qiskit-ibm-runtime/0.14/objects.inv",
"public/api/qiskit-ibm-runtime/0.15/objects.inv",
"public/api/qiskit-ibm-runtime/0.16/objects.inv",
"public/api/qiskit-addon-cutting/objects.inv",
"public/api/qiskit-addon-aqc-tensor/objects.inv",
"public/api/qiskit-addon-mpf/objects.inv",
"public/api/qiskit-addon-obp/objects.inv",
"public/api/qiskit-addon-sqd/objects.inv",
"public/api/qiskit-addon-sqd/0.7/objects.inv",
"public/api/qiskit-addon-utils/objects.inv",
]);
export const IGNORED_FILES: Set<string> = new Set([]);

// -----------------------------------------------------------------------------------
// Always ignored URLs - prefer to use more precise ignores
Expand Down Expand Up @@ -79,6 +68,47 @@ export const ALWAYS_IGNORED_URLS = new Set([
...ALWAYS_IGNORED_URLS__SHOULD_FIX,
]);

// -----------------------------------------------------------------------------------
// Always ignored URL regexes - be careful using this
// -----------------------------------------------------------------------------------

function _addonsObjectsInvRegexes(): string[] {
// Addons have non-API docs in their Sphinx build that translate into invalid links
// we should ignore
return ["how-tos", "how_tos", "install", "index", "explanations"].flatMap(
(path) => [
// Latest version
`\/api\/qiskit-addon-[^\/]+\/${path}(\/.*|#.*|$)`,
// Historical versions
`\/api\/qiskit-addon-[^\/]+\/[0-9]+\.[0-9]\/${path}(\/.*|#.*|$)`,
],
);
}

function _runtimeObjectsInvRegexes(): string[] {
// Runtime has non-API docs in their Sphinx build that translate into invalid links
// we should ignore
return [
"errors",
"migrate",
"cloud",
"faqs",
"index",
"sessions",
"primitives",
"compare",
"retired",
].map(
(path) =>
`\/api\/qiskit-ibm-runtime\/(0.16|0.15|0.14)\/${path}(\/.*|#.*|$)`,
);
}

export const ALWAYS_IGNORED_URL_REGEXES: string[] = [
..._addonsObjectsInvRegexes(),
..._runtimeObjectsInvRegexes(),
];

// -----------------------------------------------------------------------------------
// Always ignored URL prefixes - be careful using this
// -----------------------------------------------------------------------------------
Expand Down

0 comments on commit 79746ea

Please sign in to comment.