mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
39
lib/md022.js
Normal file
39
lib/md022.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD022", "blanks-around-headers" ],
|
||||
"description": "Headers should be surrounded by blank lines",
|
||||
"tags": [ "headers", "blank_lines" ],
|
||||
"function": function MD022(params, onError) {
|
||||
var prevHeadingLineNumber = 0;
|
||||
var prevMaxLineIndex = -1;
|
||||
var needBlankLine = false;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
if ((token.map[0] - prevMaxLineIndex) === 0) {
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
token.line.trim());
|
||||
}
|
||||
} else if (token.type === "heading_close") {
|
||||
needBlankLine = true;
|
||||
}
|
||||
if (token.map) {
|
||||
if (needBlankLine) {
|
||||
if ((token.map[0] - prevMaxLineIndex) === 0) {
|
||||
shared.addErrorContext(onError, prevHeadingLineNumber,
|
||||
params.lines[prevHeadingLineNumber - 1].trim());
|
||||
}
|
||||
needBlankLine = false;
|
||||
}
|
||||
prevMaxLineIndex = Math.max(prevMaxLineIndex, token.map[1]);
|
||||
}
|
||||
if (token.type === "heading_open") {
|
||||
prevHeadingLineNumber = token.lineNumber;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue