mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Expose shared.js helper code for custom rule authors (fixes #134).
This commit is contained in:
parent
f614f3e1ce
commit
7e980401b8
52 changed files with 283 additions and 184 deletions
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue