Update MD049/emphasis-style and MD050/strong-style to correctly report and fix multiple identical violations on the same line (fixes #486).

This commit is contained in:
David Anson 2022-05-03 21:35:31 -07:00
parent 54369a00e6
commit c4f51090ae
8 changed files with 258 additions and 42 deletions

View file

@ -11,6 +11,8 @@ module.exports = {
"tags": [ "emphasis" ],
"function": function MD050(params, onError) {
let expectedStyle = String(params.config.style || "consistent");
let lastLineNumber = -1;
const instances = new Map();
forEachInlineChild(params, "strong_open", (token, parent) => {
const { lineNumber, markup } = token;
const markupStyle = emphasisOrStrongStyleFor(markup);
@ -27,8 +29,17 @@ module.exports = {
const actual = `${markup}${content}${markup}`;
const expectedMarkup = (expectedStyle === "asterisk") ? "**" : "__";
const expected = `${expectedMarkup}${content}${expectedMarkup}`;
if (lastLineNumber !== lineNumber) {
lastLineNumber = lineNumber;
instances.clear();
}
instances.set(expected, (instances.get(expected) || 0) + 1);
rangeAndFixInfo = getRangeAndFixInfoIfFound(
params.lines, lineNumber - 1, actual, expected
params.lines,
lineNumber - 1,
actual,
expected,
instances.get(expected)
);
}
addError(