Expose shared.js helper code for custom rule authors (fixes #134).

This commit is contained in:
David Anson 2019-04-13 11:18:57 -07:00
parent f614f3e1ce
commit 7e980401b8
52 changed files with 283 additions and 184 deletions

View file

@ -2,14 +2,15 @@
"use strict";
const shared = require("./shared");
const { addErrorContext, bareUrlRe, filterTokens, rangeFromRegExp } =
require("../helpers");
module.exports = {
"names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used",
"tags": [ "links", "url" ],
"function": function MD034(params, onError) {
shared.filterTokens(params, "inline", function forToken(token) {
filterTokens(params, "inline", function forToken(token) {
let inLink = false;
token.children.forEach(function forChild(child) {
let match = null;
@ -19,9 +20,9 @@ module.exports = {
inLink = false;
} else if ((child.type === "text") &&
!inLink &&
(match = shared.bareUrlRe.exec(child.content))) {
shared.addErrorContext(onError, child.lineNumber, match[0], null,
null, shared.rangeFromRegExp(child.line, shared.bareUrlRe));
(match = bareUrlRe.exec(child.content))) {
addErrorContext(onError, child.lineNumber, match[0], null,
null, rangeFromRegExp(child.line, bareUrlRe));
}
});
});