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-20 21:48:18 -07:00
|
|
|
const { addErrorContext, forEachLine, isBlankLine } = shared;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD031", "blanks-around-fences" ],
|
|
|
|
"description": "Fenced code blocks should be surrounded by blank lines",
|
|
|
|
"tags": [ "code", "blank_lines" ],
|
|
|
|
"function": function MD031(params, onError) {
|
2019-03-20 21:48:18 -07:00
|
|
|
const { lines } = params;
|
|
|
|
const { length } = lines;
|
|
|
|
forEachLine(function forLine(line, i, inCode, onFence) {
|
|
|
|
if (((onFence > 0) && (i - 1 >= 0) && !isBlankLine(lines[i - 1])) ||
|
|
|
|
((onFence < 0) && (i + 1 < length) && !isBlankLine(lines[i + 1]))) {
|
|
|
|
addErrorContext(onError, i + 1, lines[i].trim());
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|