mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Update MD026/MD030 to report fixInfo for violations.
This commit is contained in:
parent
00a7e765ec
commit
0502e370de
5 changed files with 53 additions and 17 deletions
29
lib/md026.js
29
lib/md026.js
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, allPunctuation, escapeForRegExp, forEachHeading,
|
||||
rangeFromRegExp } = require("../helpers");
|
||||
const { addError, allPunctuation, escapeForRegExp, forEachHeading } =
|
||||
require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
|
|
@ -15,13 +15,26 @@ module.exports = {
|
|||
punctuation = allPunctuation;
|
||||
}
|
||||
const trailingPunctuationRe =
|
||||
new RegExp("[" + escapeForRegExp(punctuation) + "]$");
|
||||
forEachHeading(params, (heading, content) => {
|
||||
const match = trailingPunctuationRe.exec(content);
|
||||
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
|
||||
forEachHeading(params, (heading) => {
|
||||
const { line, lineNumber } = heading;
|
||||
const trimmedLine = line.replace(/[\s#]*$/, "");
|
||||
const match = trailingPunctuationRe.exec(trimmedLine);
|
||||
if (match) {
|
||||
addError(onError, heading.lineNumber,
|
||||
"Punctuation: '" + match[0] + "'", null,
|
||||
rangeFromRegExp(heading.line, trailingPunctuationRe));
|
||||
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
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue