mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD039/no-space-in-links to remove outdated validLink helper and simplify slightly.
This commit is contained in:
parent
d4352c7a44
commit
637975f517
1 changed files with 3 additions and 22 deletions
|
@ -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<string, any>} 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue