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, addErrorDetailIf, forEachHeading } =
require("../helpers");
module.exports = {
"names": [ "MD043", "required-headings", "required-headers" ],
@ -18,7 +19,7 @@ module.exports = {
let i = 0;
let optional = false;
let errorCount = 0;
shared.forEachHeading(params, function forHeading(heading, content) {
forEachHeading(params, function forHeading(heading, content) {
if (!errorCount) {
const actual = levels[heading.tag] + " " + content;
const expected = requiredHeadings[i++] || "[None]";
@ -29,14 +30,14 @@ module.exports = {
} else if (optional) {
i--;
} else {
shared.addErrorDetailIf(onError, heading.lineNumber,
addErrorDetailIf(onError, heading.lineNumber,
expected, actual);
errorCount++;
}
}
});
if ((i < requiredHeadings.length) && !errorCount) {
shared.addErrorContext(onError, params.lines.length,
addErrorContext(onError, params.lines.length,
requiredHeadings[i]);
}
}