Skip to content

Commit 637975f

Browse files
committed
Update MD039/no-space-in-links to remove outdated validLink helper and simplify slightly.
1 parent d4352c7 commit 637975f

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

lib/md039.mjs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

33
import { addErrorContext } from "../helpers/helpers.cjs";
4-
import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs";
4+
import { filterByTypesCached } from "./cache.mjs";
55

66
/**
77
* Adds an error for a label space issue.
@@ -35,41 +35,22 @@ function addLabelSpaceError(onError, label, labelText, isStart) {
3535
);
3636
}
3737

38-
/**
39-
* Determines if a link is a valid link (and not a fake shortcut link due to parser tricks).
40-
*
41-
* @param {import("markdownlint").MicromarkToken} label Label token.
42-
* @param {import("markdownlint").MicromarkToken} labelText LabelText token.
43-
* @param {Map<string, any>} definitions Map of link definitions.
44-
* @returns {boolean} True iff the link is valid.
45-
*/
46-
function validLink(label, labelText, definitions) {
47-
return (label.parent?.children.length !== 1) || definitions.has(labelText.text.trim());
48-
}
49-
5038
/** @type {import("markdownlint").Rule} */
5139
export default {
5240
"names": [ "MD039", "no-space-in-links" ],
5341
"description": "Spaces inside link text",
5442
"tags": [ "whitespace", "links" ],
5543
"parser": "micromark",
5644
"function": function MD039(params, onError) {
57-
const { definitions } = getReferenceLinkImageData();
5845
const labels = filterByTypesCached([ "label" ])
5946
.filter((label) => label.parent?.type === "link");
6047
for (const label of labels) {
6148
const labelTexts = label.children.filter((child) => child.type === "labelText");
6249
for (const labelText of labelTexts) {
63-
if (
64-
(labelText.text.trimStart().length !== labelText.text.length) &&
65-
validLink(label, labelText, definitions)
66-
) {
50+
if (labelText.text.trimStart().length !== labelText.text.length) {
6751
addLabelSpaceError(onError, label, labelText, true);
6852
}
69-
if (
70-
(labelText.text.trimEnd().length !== labelText.text.length) &&
71-
validLink(label, labelText, definitions)
72-
) {
53+
if (labelText.text.trimEnd().length !== labelText.text.length) {
7354
addLabelSpaceError(onError, label, labelText, false);
7455
}
7556
}

0 commit comments

Comments
 (0)