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,7 +2,8 @@
"use strict";
const shared = require("./shared");
const { addErrorContext, filterTokens, newLineRe, rangeFromRegExp } =
require("../helpers");
const dollarCommandRe = /^(\s*)(\$\s)/;
@ -12,15 +13,15 @@ module.exports = {
"tags": [ "code" ],
"function": function MD014(params, onError) {
[ "code_block", "fence" ].forEach(function forType(type) {
shared.filterTokens(params, type, function forToken(token) {
filterTokens(params, type, function forToken(token) {
let allBlank = true;
if (token.content && token.content.split(shared.newLineRe)
if (token.content && token.content.split(newLineRe)
.every(function forLine(line) {
return !line || (allBlank = false) || dollarCommandRe.test(line);
}) && !allBlank) {
shared.addErrorContext(onError, token.lineNumber,
token.content.split(shared.newLineRe)[0].trim(), null, null,
shared.rangeFromRegExp(token.line, dollarCommandRe));
addErrorContext(onError, token.lineNumber,
token.content.split(newLineRe)[0].trim(), null, null,
rangeFromRegExp(token.line, dollarCommandRe));
}
});
});