Fix MD039/no-space-in-links range for multiple issues on the same line.

This commit is contained in:
David Anson 2019-09-21 21:05:58 -07:00
parent 4843e277c0
commit a75f1ecf2a
4 changed files with 22 additions and 7 deletions

View file

@ -15,6 +15,7 @@ module.exports = {
const { line, lineNumber, children } = token; const { line, lineNumber, children } = token;
let inLink = false; let inLink = false;
let linkText = ""; let linkText = "";
let lineIndex = 0;
children.forEach((child) => { children.forEach((child) => {
if (child.type === "link_open") { if (child.type === "link_open") {
inLink = true; inLink = true;
@ -24,9 +25,10 @@ module.exports = {
const left = linkText.trimLeft().length !== linkText.length; const left = linkText.trimLeft().length !== linkText.length;
const right = linkText.trimRight().length !== linkText.length; const right = linkText.trimRight().length !== linkText.length;
if (left || right) { if (left || right) {
const match = line.match(spaceInLinkRe); const match = line.slice(lineIndex).match(spaceInLinkRe);
const column = match.index + 1; const column = match.index + lineIndex + 1;
const length = match[0].length; const length = match[0].length;
lineIndex = column + length - 1;
addErrorContext( addErrorContext(
onError, onError,
lineNumber, lineNumber,

View file

@ -56,3 +56,5 @@ text text ```` code
span code span code
span```` text span```` text
text. text.
Text [ space](link) text [space ](link) text [ space ](link) text.

View file

@ -58,3 +58,5 @@ text text ````code
span code span code
span```` text span```` text
text. text.
Text [space](link) text [space](link) text [space](link) text.

View file

@ -33,7 +33,7 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033",
"errorDetail": "Element: hr", "errorDetail": "Element: hr",
"errorContext": null, "errorContext": null,
"errorRange": [7, 5] "errorRange": [ 7, 5 ]
}, },
{ {
"lineNumber": 8, "lineNumber": 8,
@ -42,7 +42,7 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md034", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md034",
"errorDetail": null, "errorDetail": null,
"errorContext": "https://example.com", "errorContext": "https://example.com",
"errorRange": [6, 19] "errorRange": [ 6, 19 ]
}, },
{ {
"lineNumber": 11, "lineNumber": 11,
@ -69,7 +69,7 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037",
"errorDetail": null, "errorDetail": null,
"errorContext": "* inside *", "errorContext": "* inside *",
"errorRange": [7, 10] "errorRange": [ 7, 10 ]
}, },
{ {
"lineNumber": 31, "lineNumber": 31,
@ -123,7 +123,7 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md038", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md038",
"errorDetail": null, "errorDetail": null,
"errorContext": "` inside `", "errorContext": "` inside `",
"errorRange": [7, 10] "errorRange": [ 7, 10 ]
}, },
{ {
"lineNumber": 24, "lineNumber": 24,
@ -222,7 +222,16 @@
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039", "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039",
"errorDetail": null, "errorDetail": null,
"errorContext": "[ inside ]", "errorContext": "[ inside ]",
"errorRange": [7, 10] "errorRange": [ 7, 10 ]
},
{
"lineNumber": 60,
"ruleNames": [ "MD039", "no-space-in-links" ],
"ruleDescription": "Spaces inside link text",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md039",
"errorDetail": null,
"errorContext": "[ space]",
"errorRange": [ 6, 8 ]
}, },
{ {
"lineNumber": 21, "lineNumber": 21,