2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-06-06 22:21:31 -07:00
|
|
|
const { addError, allPunctuation, forEachHeading, rangeFromRegExp } =
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD026", "no-trailing-punctuation" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Trailing punctuation in heading",
|
|
|
|
"tags": [ "headings", "headers" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD026(params, onError) {
|
2019-06-06 22:21:31 -07:00
|
|
|
const punctuation = params.config.punctuation || allPunctuation;
|
2018-04-27 22:05:34 -07:00
|
|
|
const trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
2019-04-13 11:18:57 -07:00
|
|
|
forEachHeading(params, function forHeading(heading, content) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const match = trailingPunctuationRe.exec(content);
|
2018-01-21 21:44:25 -08:00
|
|
|
if (match) {
|
2019-04-13 11:18:57 -07:00
|
|
|
addError(onError, heading.lineNumber,
|
2018-01-21 21:44:25 -08:00
|
|
|
"Punctuation: '" + match[0] + "'", null,
|
2019-04-13 11:18:57 -07:00
|
|
|
rangeFromRegExp(heading.line, trailingPunctuationRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|