|
1 | 1 | // @ts-check
|
2 | 2 |
|
3 | 3 | import { addErrorContext } from "../helpers/helpers.cjs";
|
4 |
| -import { getReferenceLinkImageData, filterByTypesCached } from "./cache.mjs"; |
| 4 | +import { filterByTypesCached } from "./cache.mjs"; |
5 | 5 |
|
6 | 6 | /**
|
7 | 7 | * Adds an error for a label space issue.
|
@@ -35,41 +35,22 @@ function addLabelSpaceError(onError, label, labelText, isStart) {
|
35 | 35 | );
|
36 | 36 | }
|
37 | 37 |
|
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 |
| - |
50 | 38 | /** @type {import("markdownlint").Rule} */
|
51 | 39 | export default {
|
52 | 40 | "names": [ "MD039", "no-space-in-links" ],
|
53 | 41 | "description": "Spaces inside link text",
|
54 | 42 | "tags": [ "whitespace", "links" ],
|
55 | 43 | "parser": "micromark",
|
56 | 44 | "function": function MD039(params, onError) {
|
57 |
| - const { definitions } = getReferenceLinkImageData(); |
58 | 45 | const labels = filterByTypesCached([ "label" ])
|
59 | 46 | .filter((label) => label.parent?.type === "link");
|
60 | 47 | for (const label of labels) {
|
61 | 48 | const labelTexts = label.children.filter((child) => child.type === "labelText");
|
62 | 49 | 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) { |
67 | 51 | addLabelSpaceError(onError, label, labelText, true);
|
68 | 52 | }
|
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) { |
73 | 54 | addLabelSpaceError(onError, label, labelText, false);
|
74 | 55 | }
|
75 | 56 | }
|
|
0 commit comments