mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
// @ts-check
|
|
|
|
"use strict";
|
|
|
|
const { addError, allPunctuation, escapeForRegExp, forEachHeading } =
|
|
require("../helpers");
|
|
|
|
module.exports = {
|
|
"names": [ "MD026", "no-trailing-punctuation" ],
|
|
"description": "Trailing punctuation in heading",
|
|
"tags": [ "headings", "headers" ],
|
|
"function": function MD026(params, onError) {
|
|
let punctuation = params.config.punctuation;
|
|
punctuation =
|
|
String((punctuation === undefined) ? allPunctuation : punctuation);
|
|
const trailingPunctuationRe =
|
|
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
|
|
forEachHeading(params, (heading) => {
|
|
const { line, lineNumber } = heading;
|
|
const trimmedLine = line.replace(/[\s#]*$/, "");
|
|
const match = trailingPunctuationRe.exec(trimmedLine);
|
|
if (match) {
|
|
const fullMatch = match[0];
|
|
const column = match.index + 1;
|
|
const length = fullMatch.length;
|
|
addError(
|
|
onError,
|
|
lineNumber,
|
|
`Punctuation: '${fullMatch}'`,
|
|
null,
|
|
[ column, length ],
|
|
{
|
|
"editColumn": column,
|
|
"deleteCount": length
|
|
}
|
|
);
|
|
}
|
|
});
|
|
}
|
|
};
|