From 961adb98cef65ff11736121ea766ea92c15df343 Mon Sep 17 00:00:00 2001 From: David Anson Date: Mon, 6 Jan 2025 20:07:36 -0800 Subject: [PATCH] Update MD039/no-space-in-links to remove outdated validLink helper and simplify slightly. --- lib/md039.mjs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/md039.mjs b/lib/md039.mjs index 691a5aff1..074fefbc7 100644 --- a/lib/md039.mjs +++ b/lib/md039.mjs @@ -1,7 +1,7 @@ // @ts-check import { addErrorContext } from "../helpers/helpers.cjs"; -import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs"; +import { filterByTypesCached } from "./cache.mjs"; /** * Adds an error for a label space issue. @@ -35,18 +35,6 @@ function addLabelSpaceError(onError, label, labelText, isStart) { ); } -/** - * Determines if a link is a valid link (and not a fake shortcut link due to parser tricks). - * - * @param {import("markdownlint").MicromarkToken} label Label token. - * @param {import("markdownlint").MicromarkToken} labelText LabelText token. - * @param {Map} definitions Map of link definitions. - * @returns {boolean} True iff the link is valid. - */ -function validLink(label, labelText, definitions) { - return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim()); -} - /** @type {import("markdownlint").Rule} */ export default { "names": [ "MD039", "no-space-in-links" ], @@ -54,22 +42,15 @@ export default { "tags": [ "whitespace", "links" ], "parser": "micromark", "function": function MD039(params, onError) { - const { definitions } = getReferenceLinkImageData(); const labels = filterByTypesCached([ "label" ]) .filter((label) => label.parent?.type === "link"); for (const label of labels) { const labelTexts = label.children.filter((child) => child.type === "labelText"); for (const labelText of labelTexts) { - if ( - (labelText.text.trimStart().length !== labelText.text.length) && - validLink(label, labelText, definitions) - ) { + if (labelText.text.trimStart().length !== labelText.text.length) { addLabelSpaceError(onError, label, labelText, true); } - if ( - (labelText.text.trimEnd().length !== labelText.text.length) && - validLink(label, labelText, definitions) - ) { + if (labelText.text.trimEnd().length !== labelText.text.length) { addLabelSpaceError(onError, label, labelText, false); } }