forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd026.js
More file actions
50 lines (46 loc) · 1.46 KB
/
md026.js
File metadata and controls
50 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
"use strict";
const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
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) ? allPunctuationNoQuestion : punctuation
);
const trailingPunctuationRe =
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
const headings = filterByTypes(
params.parsers.micromark.tokens,
[ "atxHeadingText", "setextHeadingText" ]
);
for (const heading of headings) {
const { endLine, startColumn, text } = heading;
const match = trailingPunctuationRe.exec(text);
if (
match &&
!endOfLineHtmlEntityRe.test(text) &&
!endOfLineGemojiCodeRe.test(text)
) {
const fullMatch = match[0];
const column = startColumn + match.index;
const length = fullMatch.length;
addError(
onError,
endLine,
`Punctuation: '${fullMatch}'`,
undefined,
[ column, length ],
{
"editColumn": column,
"deleteCount": length
}
);
}
}
}
};