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 { addErrorDetailIf, filterTokens, headingStyleFor } =
require("../helpers");
module.exports = {
"names": [ "MD003", "heading-style", "header-style" ],
@ -10,8 +11,8 @@ module.exports = {
"tags": [ "headings", "headers" ],
"function": function MD003(params, onError) {
let style = params.config.style || "consistent";
shared.filterTokens(params, "heading_open", function forToken(token) {
const styleForToken = shared.headingStyleFor(token);
filterTokens(params, "heading_open", function forToken(token) {
const styleForToken = headingStyleFor(token);
if (style === "consistent") {
style = styleForToken;
}
@ -32,7 +33,7 @@ module.exports = {
} else if (style === "setext_with_atx_closed") {
expected = h12 ? "setext" : "atx_closed";
}
shared.addErrorDetailIf(onError, token.lineNumber,
addErrorDetailIf(onError, token.lineNumber,
expected, styleForToken);
}
}