diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 1cbd5912..aa3e6517 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -5660,6 +5660,48 @@ const { addErrorContext } = __webpack_require__(/*! ../helpers */ "../helpers/he const { filterByTypes } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"); const { referenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js"); +/** + * Adds an error for a label space issue. + * + * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. + * @param {import("../helpers/micromark.cjs").Token} label Label token. + * @param {import("../helpers/micromark.cjs").Token} labelText LabelText token. + * @param {boolean} isStart True iff error is at the start of the link. + */ +function addLabelSpaceError(onError, label, labelText, isStart) { + const match = labelText.text.match(isStart ? /^[^\S\r\n]+/ : /[^\S\r\n]+$/); + const range = match ? + [ + (isStart ? (labelText.startColumn) : (labelText.endColumn - match[0].length)), + match[0].length + ] : + undefined; + addErrorContext( + onError, + isStart ? (labelText.startLine + (match ? 0 : 1)) : (labelText.endLine - (match ? 0 : 1)), + label.text.replace(/\s+/g, " "), + isStart, + !isStart, + range, + range ? { + "editColumn": range[0], + "deleteCount": range[1] + } : undefined + ); +} + +/** + * Determines if a link is a valid link (and not a fake shortcut link due to parser tricks). + * + * @param {import("../helpers/micromark.cjs").Token} label Label token. + * @param {import("../helpers/micromark.cjs").Token} 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()); +} + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = { @@ -5674,44 +5716,22 @@ module.exports = { [ "label" ] ).filter((label) => label.parent?.type === "link"); for (const label of labels) { - const labelTexts = filterByTypes(label.children, [ "labelText" ]); + const labelTexts = filterByTypes( + label.children, + [ "labelText" ] + ); for (const labelText of labelTexts) { - const leftSpace = - labelText.text.trimStart().length !== labelText.text.length; - const rightSpace = - labelText.text.trimEnd().length !== labelText.text.length; if ( - (leftSpace || rightSpace) && - // Ignore non-shortcut link content "[ text ]" - ((label.parent?.children.length !== 1) || definitions.has(labelText.text.trim())) + (labelText.text.trimStart().length !== labelText.text.length) && + validLink(label, labelText, definitions) ) { - // eslint-disable-next-line no-undef-init - let range = undefined; - if (label.startLine === label.endLine) { - const labelColumn = label.startColumn; - const labelLength = label.endColumn - label.startColumn; - range = [ labelColumn, labelLength ]; - } - // eslint-disable-next-line no-undef-init - let fixInfo = undefined; - if (labelText.startLine === labelText.endLine) { - const textColumn = labelText.startColumn; - const textLength = labelText.endColumn - labelText.startColumn; - fixInfo = { - "editColumn": textColumn, - "deleteCount": textLength, - "insertText": labelText.text.trim() - }; - } - addErrorContext( - onError, - labelText.startLine, - label.text.replace(/\s+/g, " "), - leftSpace, - rightSpace, - range, - fixInfo - ); + addLabelSpaceError(onError, label, labelText, true); + } + if ( + (labelText.text.trimEnd().length !== labelText.text.length) && + validLink(label, labelText, definitions) + ) { + addLabelSpaceError(onError, label, labelText, false); } } } diff --git a/lib/md039.js b/lib/md039.js index 31757b07..196ff6bf 100644 --- a/lib/md039.js +++ b/lib/md039.js @@ -6,6 +6,48 @@ const { addErrorContext } = require("../helpers"); const { filterByTypes } = require("../helpers/micromark.cjs"); const { referenceLinkImageData } = require("./cache"); +/** + * Adds an error for a label space issue. + * + * @param {import("./markdownlint").RuleOnError} onError Error-reporting callback. + * @param {import("../helpers/micromark.cjs").Token} label Label token. + * @param {import("../helpers/micromark.cjs").Token} labelText LabelText token. + * @param {boolean} isStart True iff error is at the start of the link. + */ +function addLabelSpaceError(onError, label, labelText, isStart) { + const match = labelText.text.match(isStart ? /^[^\S\r\n]+/ : /[^\S\r\n]+$/); + const range = match ? + [ + (isStart ? (labelText.startColumn) : (labelText.endColumn - match[0].length)), + match[0].length + ] : + undefined; + addErrorContext( + onError, + isStart ? (labelText.startLine + (match ? 0 : 1)) : (labelText.endLine - (match ? 0 : 1)), + label.text.replace(/\s+/g, " "), + isStart, + !isStart, + range, + range ? { + "editColumn": range[0], + "deleteCount": range[1] + } : undefined + ); +} + +/** + * Determines if a link is a valid link (and not a fake shortcut link due to parser tricks). + * + * @param {import("../helpers/micromark.cjs").Token} label Label token. + * @param {import("../helpers/micromark.cjs").Token} 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()); +} + // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ module.exports = { @@ -20,44 +62,22 @@ module.exports = { [ "label" ] ).filter((label) => label.parent?.type === "link"); for (const label of labels) { - const labelTexts = filterByTypes(label.children, [ "labelText" ]); + const labelTexts = filterByTypes( + label.children, + [ "labelText" ] + ); for (const labelText of labelTexts) { - const leftSpace = - labelText.text.trimStart().length !== labelText.text.length; - const rightSpace = - labelText.text.trimEnd().length !== labelText.text.length; if ( - (leftSpace || rightSpace) && - // Ignore non-shortcut link content "[ text ]" - ((label.parent?.children.length !== 1) || definitions.has(labelText.text.trim())) + (labelText.text.trimStart().length !== labelText.text.length) && + validLink(label, labelText, definitions) ) { - // eslint-disable-next-line no-undef-init - let range = undefined; - if (label.startLine === label.endLine) { - const labelColumn = label.startColumn; - const labelLength = label.endColumn - label.startColumn; - range = [ labelColumn, labelLength ]; - } - // eslint-disable-next-line no-undef-init - let fixInfo = undefined; - if (labelText.startLine === labelText.endLine) { - const textColumn = labelText.startColumn; - const textLength = labelText.endColumn - labelText.startColumn; - fixInfo = { - "editColumn": textColumn, - "deleteCount": textLength, - "insertText": labelText.text.trim() - }; - } - addErrorContext( - onError, - labelText.startLine, - label.text.replace(/\s+/g, " "), - leftSpace, - rightSpace, - range, - fixInfo - ); + addLabelSpaceError(onError, label, labelText, true); + } + if ( + (labelText.text.trimEnd().length !== labelText.text.length) && + validLink(label, labelText, definitions) + ) { + addLabelSpaceError(onError, label, labelText, false); } } } diff --git a/test/snapshots/markdownlint-test-scenarios.js.md b/test/snapshots/markdownlint-test-scenarios.js.md index 80b44a1e..27f45b59 100644 --- a/test/snapshots/markdownlint-test-scenarios.js.md +++ b/test/snapshots/markdownlint-test-scenarios.js.md @@ -1473,13 +1473,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ inside ]', errorDetail: null, errorRange: [ - 7, - 10, + 8, + 1, ], fixInfo: { - deleteCount: 8, + deleteCount: 1, editColumn: 8, - insertText: 'inside', + }, + lineNumber: 19, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ inside ]', + errorDetail: null, + errorRange: [ + 15, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 15, }, lineNumber: 19, ruleDescription: 'Spaces inside link text', @@ -1493,13 +1511,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ space]', errorDetail: null, errorRange: [ - 6, - 8, + 7, + 1, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 7, - insertText: 'space', }, lineNumber: 60, ruleDescription: 'Spaces inside link text', @@ -1513,13 +1530,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[space ]', errorDetail: null, errorRange: [ - 26, - 8, + 32, + 1, ], fixInfo: { - deleteCount: 6, - editColumn: 27, - insertText: 'space', + deleteCount: 1, + editColumn: 32, }, lineNumber: 60, ruleDescription: 'Spaces inside link text', @@ -1533,13 +1549,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ space ]', errorDetail: null, errorRange: [ - 46, - 9, + 47, + 1, ], fixInfo: { - deleteCount: 7, + deleteCount: 1, editColumn: 47, - insertText: 'space', + }, + lineNumber: 60, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ space ]', + errorDetail: null, + errorRange: [ + 53, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 53, }, lineNumber: 60, ruleDescription: 'Spaces inside link text', @@ -7426,13 +7460,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[link with space ]', errorDetail: null, errorRange: [ + 17, 1, - 18, ], fixInfo: { - deleteCount: 16, - editColumn: 2, - insertText: 'link with space', + deleteCount: 1, + editColumn: 17, }, lineNumber: 71, ruleDescription: 'Spaces inside link text', @@ -13416,13 +13449,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ - 6, - 8, + 7, + 1, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 7, - insertText: 'link', + }, + lineNumber: 8, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 12, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 12, }, lineNumber: 8, ruleDescription: 'Spaces inside link text', @@ -30090,13 +30141,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[link ]', errorDetail: null, errorRange: [ - 6, - 7, + 11, + 1, ], fixInfo: { - deleteCount: 5, - editColumn: 7, - insertText: 'link', + deleteCount: 1, + editColumn: 11, }, lineNumber: 32, ruleDescription: 'Spaces inside link text', @@ -30110,13 +30160,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link]', errorDetail: null, errorRange: [ - 6, 7, + 1, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 7, - insertText: 'link', }, lineNumber: 34, ruleDescription: 'Spaces inside link text', @@ -30130,13 +30179,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ - 6, - 8, + 7, + 1, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 7, - insertText: 'link', + }, + lineNumber: 36, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 12, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 12, }, lineNumber: 36, ruleDescription: 'Spaces inside link text', @@ -30150,13 +30217,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[link ]', errorDetail: null, errorRange: [ - 6, - 7, + 11, + 1, ], fixInfo: { - deleteCount: 5, - editColumn: 7, - insertText: 'link', + deleteCount: 1, + editColumn: 11, }, lineNumber: 38, ruleDescription: 'Spaces inside link text', @@ -30170,13 +30236,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link]', errorDetail: null, errorRange: [ - 6, 7, + 1, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 7, - insertText: 'link', }, lineNumber: 40, ruleDescription: 'Spaces inside link text', @@ -30190,13 +30255,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ - 6, - 8, + 7, + 1, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 7, - insertText: 'link', + }, + lineNumber: 42, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 12, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 12, }, lineNumber: 42, ruleDescription: 'Spaces inside link text', @@ -30269,13 +30352,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '...k has `code` and right space ]', errorDetail: null, errorRange: [ + 38, 1, - 39, ], fixInfo: { - deleteCount: 37, - editColumn: 2, - insertText: 'This link has `code` and right space', + deleteCount: 1, + editColumn: 38, }, lineNumber: 11, ruleDescription: 'Spaces inside link text', @@ -30289,13 +30371,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ This link has *emphasis* and...', errorDetail: null, errorRange: [ + 2, 1, - 42, ], fixInfo: { - deleteCount: 40, + deleteCount: 1, editColumn: 2, - insertText: 'This link has *emphasis* and left space', }, lineNumber: 13, ruleDescription: 'Spaces inside link text', @@ -30309,13 +30390,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[too ]', errorDetail: null, errorRange: [ - 19, - 6, + 23, + 1, ], fixInfo: { - deleteCount: 4, - editColumn: 20, - insertText: 'too', + deleteCount: 1, + editColumn: 23, }, lineNumber: 17, ruleDescription: 'Spaces inside link text', @@ -38426,13 +38506,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ - 29, - 8, + 30, + 1, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 30, - insertText: 'link', + }, + lineNumber: 26, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 35, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 35, }, lineNumber: 26, ruleDescription: 'Spaces inside link text', @@ -47970,13 +48068,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ + 2, 1, - 8, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 2, - insertText: 'link', + }, + lineNumber: 3, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 7, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 7, }, lineNumber: 3, ruleDescription: 'Spaces inside link text', @@ -47990,13 +48106,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ "link" ]', errorDetail: null, errorRange: [ + 2, 1, - 10, ], fixInfo: { - deleteCount: 8, + deleteCount: 1, editColumn: 2, - insertText: '"link"', + }, + lineNumber: 5, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ "link" ]', + errorDetail: null, + errorRange: [ + 9, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 9, }, lineNumber: 5, ruleDescription: 'Spaces inside link text', @@ -48010,13 +48144,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ `link` ]', errorDetail: null, errorRange: [ + 2, 1, - 10, ], fixInfo: { - deleteCount: 8, + deleteCount: 1, editColumn: 2, - insertText: '`link`', + }, + lineNumber: 7, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ `link` ]', + errorDetail: null, + errorRange: [ + 9, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 9, }, lineNumber: 7, ruleDescription: 'Spaces inside link text', @@ -48030,13 +48182,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ *link* ]', errorDetail: null, errorRange: [ + 2, 1, - 10, ], fixInfo: { - deleteCount: 8, + deleteCount: 1, editColumn: 2, - insertText: '*link*', + }, + lineNumber: 9, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ *link* ]', + errorDetail: null, + errorRange: [ + 9, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 9, }, lineNumber: 9, ruleDescription: 'Spaces inside link text', @@ -48050,13 +48220,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ __link__ ]', errorDetail: null, errorRange: [ + 2, 1, - 12, ], fixInfo: { - deleteCount: 10, + deleteCount: 1, editColumn: 2, - insertText: '__link__', + }, + lineNumber: 11, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ __link__ ]', + errorDetail: null, + errorRange: [ + 11, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 11, }, lineNumber: 11, ruleDescription: 'Spaces inside link text', @@ -48070,13 +48258,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link "link" ]', errorDetail: null, errorRange: [ + 2, 1, - 15, ], fixInfo: { - deleteCount: 13, + deleteCount: 1, editColumn: 2, - insertText: 'link "link"', + }, + lineNumber: 13, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link "link" ]', + errorDetail: null, + errorRange: [ + 14, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 14, }, lineNumber: 13, ruleDescription: 'Spaces inside link text', @@ -48090,13 +48296,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link `link` ]', errorDetail: null, errorRange: [ + 2, 1, - 15, ], fixInfo: { - deleteCount: 13, + deleteCount: 1, editColumn: 2, - insertText: 'link `link`', + }, + lineNumber: 15, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link `link` ]', + errorDetail: null, + errorRange: [ + 14, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 14, }, lineNumber: 15, ruleDescription: 'Spaces inside link text', @@ -48110,13 +48334,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ *link* link ]', errorDetail: null, errorRange: [ + 2, 1, - 15, ], fixInfo: { - deleteCount: 13, + deleteCount: 1, editColumn: 2, - insertText: '*link* link', + }, + lineNumber: 17, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ *link* link ]', + errorDetail: null, + errorRange: [ + 14, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 14, }, lineNumber: 17, ruleDescription: 'Spaces inside link text', @@ -51451,17 +51693,111 @@ Generated by [AVA](https://avajs.dev). { errors: [ + { + errorContext: null, + errorDetail: 'Expected: 0 or 2; Actual: 1', + errorRange: [ + 10, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 10, + }, + lineNumber: 60, + ruleDescription: 'Trailing spaces', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md009.md', + ruleNames: [ + 'MD009', + 'no-trailing-spaces', + ], + }, + { + errorContext: null, + errorDetail: 'Expected: 0 or 2; Actual: 1', + errorRange: [ + 34, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 34, + }, + lineNumber: 63, + ruleDescription: 'Trailing spaces', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md009.md', + ruleNames: [ + 'MD009', + 'no-trailing-spaces', + ], + }, + { + errorContext: null, + errorDetail: 'Expected: 0 or 2; Actual: 1', + errorRange: [ + 10, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 10, + }, + lineNumber: 69, + ruleDescription: 'Trailing spaces', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md009.md', + ruleNames: [ + 'MD009', + 'no-trailing-spaces', + ], + }, + { + errorContext: null, + errorDetail: 'Expected: 0 or 2; Actual: 1', + errorRange: [ + 38, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 38, + }, + lineNumber: 74, + ruleDescription: 'Trailing spaces', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md009.md', + ruleNames: [ + 'MD009', + 'no-trailing-spaces', + ], + }, { errorContext: '[ ]', errorDetail: null, errorRange: [ + 2, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 2, + }, + lineNumber: 17, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ ]', + errorDetail: null, + errorRange: [ + 2, 1, - 3, ], fixInfo: { deleteCount: 1, editColumn: 2, - insertText: '', }, lineNumber: 17, ruleDescription: 'Spaces inside link text', @@ -51475,13 +51811,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[foo ]', errorDetail: null, errorRange: [ + 5, 1, - 6, ], fixInfo: { - deleteCount: 4, - editColumn: 2, - insertText: 'foo', + deleteCount: 1, + editColumn: 5, }, lineNumber: 19, ruleDescription: 'Spaces inside link text', @@ -51495,13 +51830,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ foo]', errorDetail: null, errorRange: [ + 2, 1, - 6, ], fixInfo: { - deleteCount: 4, + deleteCount: 1, editColumn: 2, - insertText: 'foo', }, lineNumber: 21, ruleDescription: 'Spaces inside link text', @@ -51515,13 +51849,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ foo ]', errorDetail: null, errorRange: [ + 2, 1, - 7, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 2, - insertText: 'foo', + }, + lineNumber: 23, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ foo ]', + errorDetail: null, + errorRange: [ + 6, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 6, }, lineNumber: 23, ruleDescription: 'Spaces inside link text', @@ -51535,13 +51887,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ "foo" ]', errorDetail: null, errorRange: [ + 2, 1, - 9, ], fixInfo: { - deleteCount: 7, + deleteCount: 1, editColumn: 2, - insertText: '"foo"', + }, + lineNumber: 25, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ "foo" ]', + errorDetail: null, + errorRange: [ + 8, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 8, }, lineNumber: 25, ruleDescription: 'Spaces inside link text', @@ -51555,13 +51925,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ `foo` ]', errorDetail: null, errorRange: [ + 2, 1, - 9, ], fixInfo: { - deleteCount: 7, + deleteCount: 1, editColumn: 2, - insertText: '`foo`', + }, + lineNumber: 27, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ `foo` ]', + errorDetail: null, + errorRange: [ + 8, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 8, }, lineNumber: 27, ruleDescription: 'Spaces inside link text', @@ -51575,13 +51963,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ *foo* ]', errorDetail: null, errorRange: [ + 2, 1, - 9, ], fixInfo: { - deleteCount: 7, + deleteCount: 1, editColumn: 2, - insertText: '*foo*', + }, + lineNumber: 29, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ *foo* ]', + errorDetail: null, + errorRange: [ + 8, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 8, }, lineNumber: 29, ruleDescription: 'Spaces inside link text', @@ -51595,13 +52001,31 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ __foo__ ]', errorDetail: null, errorRange: [ + 2, 1, - 11, ], fixInfo: { - deleteCount: 9, + deleteCount: 1, editColumn: 2, - insertText: '__foo__', + }, + lineNumber: 31, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ __foo__ ]', + errorDetail: null, + errorRange: [ + 10, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 10, }, lineNumber: 31, ruleDescription: 'Spaces inside link text', @@ -51615,13 +52039,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[- ]', errorDetail: null, errorRange: [ - 25, - 4, + 27, + 1, ], fixInfo: { - deleteCount: 2, - editColumn: 26, - insertText: '-', + deleteCount: 1, + editColumn: 27, }, lineNumber: 37, ruleDescription: 'Spaces inside link text', @@ -51635,13 +52058,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[- ]', errorDetail: null, errorRange: [ - 26, - 4, + 28, + 1, ], fixInfo: { - deleteCount: 2, - editColumn: 27, - insertText: '-', + deleteCount: 1, + editColumn: 28, }, lineNumber: 41, ruleDescription: 'Spaces inside link text', @@ -51655,13 +52077,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[- ]', errorDetail: null, errorRange: [ - 26, - 4, + 28, + 1, ], fixInfo: { - deleteCount: 2, - editColumn: 27, - insertText: '-', + deleteCount: 1, + editColumn: 28, }, lineNumber: 43, ruleDescription: 'Spaces inside link text', @@ -51675,13 +52096,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[error ]', errorDetail: null, errorRange: [ + 7, 1, - 8, ], fixInfo: { - deleteCount: 6, - editColumn: 2, - insertText: 'error', + deleteCount: 1, + editColumn: 7, }, lineNumber: 49, ruleDescription: 'Spaces inside link text', @@ -51691,32 +52111,203 @@ Generated by [AVA](https://avajs.dev). 'no-space-in-links', ], }, - { - errorContext: '[ link with lea...space {MD039} ]', - errorDetail: null, - errorRange: null, - fixInfo: null, - lineNumber: 51, - ruleDescription: 'Spaces inside link text', - ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', - ruleNames: [ - 'MD039', - 'no-space-in-links', - ], - }, { errorContext: '[ link with leading space]', errorDetail: null, errorRange: [ - 13, - 26, + 14, + 1, ], fixInfo: { - deleteCount: 24, + deleteCount: 1, editColumn: 14, - insertText: 'link with leading space', }, - lineNumber: 54, + lineNumber: 51, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[link with trailing space ]', + errorDetail: null, + errorRange: [ + 38, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 38, + }, + lineNumber: 53, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link with leading and traili...', + errorDetail: null, + errorRange: [ + 14, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 14, + }, + lineNumber: 55, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '...h leading and trailing space ]', + errorDetail: null, + errorRange: [ + 51, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 51, + }, + lineNumber: 55, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link with leading space]', + errorDetail: null, + errorRange: null, + fixInfo: null, + lineNumber: 58, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link with leading space]', + errorDetail: null, + errorRange: [ + 10, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 10, + }, + lineNumber: 60, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[link with trailing space ]', + errorDetail: null, + errorRange: null, + fixInfo: null, + lineNumber: 63, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[link with trailing space ]', + errorDetail: null, + errorRange: [ + 1, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 1, + }, + lineNumber: 67, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link with leading and traili...', + errorDetail: null, + errorRange: [ + 10, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 10, + }, + lineNumber: 69, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '...h leading and trailing space ]', + errorDetail: null, + errorRange: [ + 1, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 1, + }, + lineNumber: 71, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link with leading and traili...', + errorDetail: null, + errorRange: null, + fixInfo: null, + lineNumber: 74, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '...h leading and trailing space ]', + errorDetail: null, + errorRange: null, + fixInfo: null, + lineNumber: 74, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51728,15 +52319,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[link ]', errorDetail: null, errorRange: [ + 6, 1, - 7, ], fixInfo: { - deleteCount: 5, - editColumn: 2, - insertText: 'link', + deleteCount: 1, + editColumn: 6, }, - lineNumber: 60, + lineNumber: 81, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51748,15 +52338,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link]', errorDetail: null, errorRange: [ + 2, 1, - 7, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 2, - insertText: 'link', }, - lineNumber: 62, + lineNumber: 83, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51768,15 +52357,33 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ link ]', errorDetail: null, errorRange: [ + 2, 1, - 8, ], fixInfo: { - deleteCount: 6, + deleteCount: 1, editColumn: 2, - insertText: 'link', }, - lineNumber: 64, + lineNumber: 85, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ link ]', + errorDetail: null, + errorRange: [ + 7, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 7, + }, + lineNumber: 85, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51788,15 +52395,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ref ]', errorDetail: null, errorRange: [ + 5, 1, - 6, ], fixInfo: { - deleteCount: 4, - editColumn: 2, - insertText: 'ref', + deleteCount: 1, + editColumn: 5, }, - lineNumber: 68, + lineNumber: 89, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51808,15 +52414,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ ref]', errorDetail: null, errorRange: [ + 2, 1, - 6, ], fixInfo: { - deleteCount: 4, + deleteCount: 1, editColumn: 2, - insertText: 'ref', }, - lineNumber: 70, + lineNumber: 91, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51828,15 +52433,33 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ ref ]', errorDetail: null, errorRange: [ + 2, 1, - 7, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 2, - insertText: 'ref', }, - lineNumber: 72, + lineNumber: 93, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ ref ]', + errorDetail: null, + errorRange: [ + 6, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 6, + }, + lineNumber: 93, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51848,15 +52471,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ref ]', errorDetail: null, errorRange: [ + 5, 1, - 6, ], fixInfo: { - deleteCount: 4, - editColumn: 2, - insertText: 'ref', + deleteCount: 1, + editColumn: 5, }, - lineNumber: 76, + lineNumber: 97, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51868,15 +52490,14 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ ref]', errorDetail: null, errorRange: [ + 2, 1, - 6, ], fixInfo: { - deleteCount: 4, + deleteCount: 1, editColumn: 2, - insertText: 'ref', }, - lineNumber: 78, + lineNumber: 99, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51888,15 +52509,33 @@ Generated by [AVA](https://avajs.dev). errorContext: '[ ref ]', errorDetail: null, errorRange: [ + 2, 1, - 7, ], fixInfo: { - deleteCount: 5, + deleteCount: 1, editColumn: 2, - insertText: 'ref', }, - lineNumber: 80, + lineNumber: 101, + ruleDescription: 'Spaces inside link text', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', + ruleNames: [ + 'MD039', + 'no-space-in-links', + ], + }, + { + errorContext: '[ ref ]', + errorDetail: null, + errorRange: [ + 6, + 1, + ], + fixInfo: { + deleteCount: 1, + editColumn: 6, + }, + lineNumber: 101, ruleDescription: 'Spaces inside link text', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md', ruleNames: [ @@ -51955,11 +52594,32 @@ Generated by [AVA](https://avajs.dev). [with](spaces) ␊ [error]({MD039})␊ ␊ - Wrapped [ link with leading space {MD039}␊ - ](https://example.com)␊ - ␊ Non-wrapped [link with leading space](https://example.com) {MD039}␊ ␊ + Non-wrapped [link with trailing space](https://example.com) {MD039}␊ + ␊ + Non-wrapped [link with leading and trailing space](https://example.com) {MD039}␊ + ␊ + Wrapped [␊ + link with leading space](https://example.com) {MD039}␊ + ␊ + Wrapped [␊ + link with leading space](https://example.com) {MD009:-1} {MD039:-1}␊ + ␊ + Wrapped [link with trailing space␊ + ](https://example.com) {MD009:-1} {MD039:-1}␊ + ␊ + Wrapped [link with trailing space␊ + ](https://example.com) {MD039}␊ + ␊ + Wrapped [␊ + link with leading and trailing space␊ + ](https://example.com) {MD009:-2} {MD039:-2} {MD039}␊ + ␊ + Wrapped [␊ + link with leading and trailing space␊ + ](https://example.com) {MD009:-1} {MD039:-1}␊ + ␊ [][ref]␊ ␊ [link][ref]␊ @@ -53636,13 +54296,12 @@ Generated by [AVA](https://avajs.dev). errorContext: '[link ]', errorDetail: null, errorRange: [ - 3, - 7, + 8, + 1, ], fixInfo: { - deleteCount: 5, - editColumn: 4, - insertText: 'link', + deleteCount: 1, + editColumn: 8, }, lineNumber: 12, ruleDescription: 'Spaces inside link text', diff --git a/test/snapshots/markdownlint-test-scenarios.js.snap b/test/snapshots/markdownlint-test-scenarios.js.snap index 0ec57a42..3217687c 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.js.snap and b/test/snapshots/markdownlint-test-scenarios.js.snap differ diff --git a/test/spaces_inside_link_text.md b/test/spaces_inside_link_text.md index 8c0a1881..0d7e7aac 100644 --- a/test/spaces_inside_link_text.md +++ b/test/spaces_inside_link_text.md @@ -48,11 +48,32 @@ function MoreCodeButNotCode(input) { [with](spaces) [error ]({MD039}) -Wrapped [ link with leading space {MD039} - ](https://example.com) - Non-wrapped [ link with leading space](https://example.com) {MD039} +Non-wrapped [link with trailing space ](https://example.com) {MD039} + +Non-wrapped [ link with leading and trailing space ](https://example.com) {MD039} + +Wrapped [ + link with leading space](https://example.com) {MD039} + +Wrapped [ +link with leading space](https://example.com) {MD009:-1} {MD039:-1} + +Wrapped [link with trailing space +](https://example.com) {MD009:-1} {MD039:-1} + +Wrapped [link with trailing space + ](https://example.com) {MD039} + +Wrapped [ +link with leading and trailing space + ](https://example.com) {MD009:-2} {MD039:-2} {MD039} + +Wrapped [ + link with leading and trailing space +](https://example.com) {MD009:-1} {MD039:-1} + [][ref] [link][ref]