Update MD034/no-bare-urls to report multiple instances on the same line.

This commit is contained in:
David Anson 2019-09-22 21:31:02 -07:00
parent a75f1ecf2a
commit 737126cf93
5 changed files with 37 additions and 23 deletions

View file

@ -21,7 +21,7 @@ const inlineCommentRe =
module.exports.inlineCommentRe = inlineCommentRe; module.exports.inlineCommentRe = inlineCommentRe;
// Regular expressions for range matching // Regular expressions for range matching
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/i; module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s]*/ig;
module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+[.)])\s+/; module.exports.listItemMarkerRe = /^[\s>]*(?:[*+-]|\d+[.)])\s+/;
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;

View file

@ -18,28 +18,29 @@ module.exports = {
inLink = true; inLink = true;
} else if (type === "link_close") { } else if (type === "link_close") {
inLink = false; inLink = false;
} else if ((type === "text") && !inLink && } else if ((type === "text") && !inLink) {
(match = bareUrlRe.exec(content))) { while ((match = bareUrlRe.exec(content)) !== null) {
const [ bareUrl ] = match; const [ bareUrl ] = match;
const index = line.indexOf(content); const index = line.indexOf(content);
const range = (index === -1) ? null : [ const range = (index === -1) ? null : [
line.indexOf(content) + match.index + 1, line.indexOf(content) + match.index + 1,
bareUrl.length bareUrl.length
]; ];
const fixInfo = range ? { const fixInfo = range ? {
"editColumn": range[0], "editColumn": range[0],
"deleteCount": range[1], "deleteCount": range[1],
"insertText": `<${bareUrl}>` "insertText": `<${bareUrl}>`
} : null; } : null;
addErrorContext( addErrorContext(
onError, onError,
lineNumber, lineNumber,
bareUrl, bareUrl,
null, null,
null, null,
range, range,
fixInfo fixInfo
); );
}
} }
}); });
}); });

View file

@ -24,3 +24,5 @@ Code https://example.com/code?type=fence code
Text <https://example.com/same> more text https://example.com/same still more text <https://example.com/same> done Text <https://example.com/same> more text https://example.com/same still more text <https://example.com/same> done
Text <https://example.com/same> more \* text https://example.com/same more \[ text <https://example.com/same> done Text <https://example.com/same> more \* text https://example.com/same more \[ text <https://example.com/same> done
Text https://example.com/first more text https://example.com/second still more text https://example.com/third done

View file

@ -24,3 +24,5 @@ Code https://example.com/code?type=fence code
Text <https://example.com/same> more text <https://example.com/same> still more text <https://example.com/same> done Text <https://example.com/same> more text <https://example.com/same> still more text <https://example.com/same> done
Text <https://example.com/same> more \* text https://example.com/same more \[ text <https://example.com/same> done Text <https://example.com/same> more \* text https://example.com/same more \[ text <https://example.com/same> done
Text <https://example.com/first> more text <https://example.com/second> still more text <https://example.com/third> done

View file

@ -88,5 +88,14 @@
"errorDetail": null, "errorDetail": null,
"errorContext": "https://example.com/same", "errorContext": "https://example.com/same",
"errorRange": null "errorRange": null
},
{
"lineNumber": 28,
"ruleNames": [ "MD034", "no-bare-urls" ],
"ruleDescription": "Bare URL used",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md034",
"errorDetail": null,
"errorContext": "https://example.com/first",
"errorRange": [ 6, 25 ]
} }
] ]