Update MD039/no-space-in-links to handle RegExp match failure (fixes #262).

This commit is contained in:
David Anson 2020-03-07 19:49:57 -08:00
parent 0f73f06232
commit 67d1476ed8
2 changed files with 20 additions and 9 deletions

View file

@ -28,22 +28,28 @@ module.exports = {
const right = linkText.trimRight().length !== linkText.length;
if (left || right) {
const line = params.lines[lineNumber - 1];
let range = null;
let fixInfo = null;
const match = line.slice(lineIndex).match(spaceInLinkRe);
const column = match.index + lineIndex + 1;
const length = match[0].length;
lineIndex = column + length - 1;
if (match) {
const column = match.index + lineIndex + 1;
const length = match[0].length;
range = [ column, length ];
fixInfo = {
"editColumn": column + 1,
"deleteCount": length - 2,
"insertText": linkText.trim()
};
lineIndex = column + length - 1;
}
addErrorContext(
onError,
lineNumber,
`[${linkText}]`,
left,
right,
[ column, length ],
{
"editColumn": column + 1,
"deleteCount": length - 2,
"insertText": linkText.trim()
}
range,
fixInfo
);
}
} else if ((type === "softbreak") || (type === "hardbreak")) {

View file

@ -45,3 +45,8 @@ function MoreCodeButNotCode(input) {
[Links](ending)
[with](spaces)
[error ]({MD039})
Wrapped [ link with leading space
](https://example.com) {MD039}
Non-wrapped [ link with leading space](https://example.com) {MD039}