mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +01:00
Move each rule implementation into its own file (fixes #83).
This commit is contained in:
parent
49e36f817c
commit
9ba143555d
42 changed files with 1289 additions and 1028 deletions
41
lib/md003.js
Normal file
41
lib/md003.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD003", "header-style" ],
|
||||
"description": "Header style",
|
||||
"tags": [ "headers" ],
|
||||
"function": function MD003(params, onError) {
|
||||
var style = params.config.style || "consistent";
|
||||
shared.filterTokens(params, "heading_open", function forToken(token) {
|
||||
var styleForToken = shared.headingStyleFor(token);
|
||||
if (style === "consistent") {
|
||||
style = styleForToken;
|
||||
}
|
||||
if (styleForToken !== style) {
|
||||
var h12 = /h[12]/.test(token.tag);
|
||||
var setextWithAtx =
|
||||
(style === "setext_with_atx") &&
|
||||
((h12 && (styleForToken === "setext")) ||
|
||||
(!h12 && (styleForToken === "atx")));
|
||||
var setextWithAtxClosed =
|
||||
(style === "setext_with_atx_closed") &&
|
||||
((h12 && (styleForToken === "setext")) ||
|
||||
(!h12 && (styleForToken === "atx_closed")));
|
||||
if (!setextWithAtx && !setextWithAtxClosed) {
|
||||
var expected = style;
|
||||
if (style === "setext_with_atx") {
|
||||
expected = h12 ? "setext" : "atx";
|
||||
} else if (style === "setext_with_atx_closed") {
|
||||
expected = h12 ? "setext" : "atx_closed";
|
||||
}
|
||||
shared.addErrorDetailIf(onError, token.lineNumber,
|
||||
expected, styleForToken);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue