2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-07-26 23:03:56 -07:00
|
|
|
const { addError, allPunctuation, escapeForRegExp, 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-07-26 23:03:56 -07:00
|
|
|
let punctuation = params.config.punctuation;
|
|
|
|
if (punctuation === undefined) {
|
|
|
|
punctuation = allPunctuation;
|
|
|
|
}
|
|
|
|
const trailingPunctuationRe =
|
|
|
|
new RegExp("[" + escapeForRegExp(punctuation) + "]$");
|
|
|
|
forEachHeading(params, (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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|