From c744c4872a28ad8cc2e9d50d832e5c95f878855a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Thu, 5 Feb 2026 21:12:22 +0100 Subject: [PATCH] fix: ignore external https image links --- src/index.js | 17 +++++++++++++++-- test/fixtures/valid/ignore-external-image.md | 3 +++ test/index.test.js | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/valid/ignore-external-image.md diff --git a/src/index.js b/src/index.js index 7a27e2e..0dc84bd 100644 --- a/src/index.js +++ b/src/index.js @@ -70,11 +70,24 @@ const relativeLinksRule = { url = new URL(hrefSrc, pathToFileURL(params.name)) } - if (url.protocol !== "file:" && type !== "image") { + const detail = `"${hrefSrc}"` + + if ( + type === "image" && + url.protocol !== "file:" && + url.protocol !== "http:" && + url.protocol !== "https:" + ) { + onError({ + lineNumber, + detail: `${detail} should be an image`, + }) continue } - const detail = `"${hrefSrc}"` + if (url.protocol !== "file:") { + continue + } if (!fs.existsSync(url)) { onError({ diff --git a/test/fixtures/valid/ignore-external-image.md b/test/fixtures/valid/ignore-external-image.md new file mode 100644 index 0000000..63d5cca --- /dev/null +++ b/test/fixtures/valid/ignore-external-image.md @@ -0,0 +1,3 @@ +# Valid + +![External Image](https://example.com/image.png) diff --git a/test/index.test.js b/test/index.test.js index 1cadcc8..5e079d6 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -152,7 +152,7 @@ test("ensure the rule validates correctly", async (t) => { fixturePath: "test/fixtures/invalid/invalid-image.md", errors: [ '"../not-an-image.txt" should be an image', - '"mailto:not-an-image@pictures.com" should exist in the file system', + '"mailto:not-an-image@pictures.com" should be an image', ], }, ] @@ -239,6 +239,10 @@ test("ensure the rule validates correctly", async (t) => { }, }, }, + { + name: "should ignore external image links", + fixturePath: "test/fixtures/valid/ignore-external-image.md", + }, ] for (const { name, fixturePath, config = defaultConfig } of testCases) {