2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2019-03-21 21:42:24 -07:00
|
|
|
const { addErrorContext, filterTokens, isBlankLine } = shared;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"names": [ "MD022", "blanks-around-headings", "blanks-around-headers" ],
|
|
|
|
"description": "Headings should be surrounded by blank lines",
|
|
|
|
"tags": [ "headings", "headers", "blank_lines" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD022(params, onError) {
|
2019-03-21 21:42:24 -07:00
|
|
|
const { lines } = params;
|
|
|
|
filterTokens(params, "heading_open", (token) => {
|
|
|
|
const [ topIndex, nextIndex ] = token.map;
|
|
|
|
if (!isBlankLine(lines[topIndex - 1]) || !isBlankLine(lines[nextIndex])) {
|
|
|
|
addErrorContext(onError, topIndex + 1, lines[topIndex].trim());
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|