Skip to content

Commit

Permalink
deduplicate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaucasau committed Nov 19, 2024
1 parent e5749c8 commit 5df19a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions scripts/js/commands/checkAltText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@ import { readMarkdown } from "../lib/markdownReader.js";

async function main() {
const files = await globby(["docs/**/*.{ipynb,mdx}", "!docs/api/**/*.mdx"]);
const errors: string[] = [];
const fileErrors: string[] = [];

for (const file of files) {
const markdown = await readMarkdown(file);
const images: Image[] = await extractMarkdownImages(markdown);
const fileErrors = images.flatMap((image: Image) =>
const imageErrors = images.flatMap((image: Image) =>
image.altText
? []
: `The image '${image.imageName}' does not have an alt text defined.`,
);
const imageErrorsDeduplicated = new Set(imageErrors);

if (fileErrors.length > 0) {
errors.push(`Error in file '${file}':\n\t- ${fileErrors.join("\n\t- ")}`);
if (imageErrorsDeduplicated.size > 0) {
fileErrors.push(
`Error in file '${file}':\n\t- ${[...imageErrorsDeduplicated].join("\n\t- ")}`,
);
}
}

if (errors.length > 0) {
errors.forEach((error) => console.log(error));
if (fileErrors.length > 0) {
fileErrors.forEach((error) => console.log(error));
console.error("\nSome images are missing alt text 💔\n");
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/js/lib/extractMarkdownImages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { expect, test } from "@playwright/test";

import { Image, extractMarkdownImages } from "./extractMarkdownImages.js";
import { extractMarkdownImages } from "./extractMarkdownImages.js";

test("Test the extraction of the images", async () => {
const markdown = `
Expand Down

0 comments on commit 5df19a4

Please sign in to comment.