mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Rename md049.js in preparation for merging with md050.js.
This commit is contained in:
parent
c4f51090ae
commit
76bc976d3b
3 changed files with 6 additions and 6 deletions
56
lib/md049.js
56
lib/md049.js
|
@ -1,56 +0,0 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const { addError, emphasisOrStrongStyleFor, forEachInlineChild,
|
||||
getNextChildToken, getRangeAndFixInfoIfFound } = require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD049", "emphasis-style" ],
|
||||
"description": "Emphasis style should be consistent",
|
||||
"tags": [ "emphasis" ],
|
||||
"function": function MD049(params, onError) {
|
||||
let expectedStyle = String(params.config.style || "consistent");
|
||||
let lastLineNumber = -1;
|
||||
const instances = new Map();
|
||||
forEachInlineChild(params, "em_open", (token, parent) => {
|
||||
const { lineNumber, markup } = token;
|
||||
const markupStyle = emphasisOrStrongStyleFor(markup);
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = markupStyle;
|
||||
}
|
||||
if (expectedStyle !== markupStyle) {
|
||||
let rangeAndFixInfo = {};
|
||||
const contentToken = getNextChildToken(
|
||||
parent, token, "text", "em_close"
|
||||
);
|
||||
if (contentToken) {
|
||||
const { content } = contentToken;
|
||||
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,
|
||||
instances.get(expected)
|
||||
);
|
||||
}
|
||||
addError(
|
||||
onError,
|
||||
lineNumber,
|
||||
`Expected: ${expectedStyle}; Actual: ${markupStyle}`,
|
||||
null,
|
||||
rangeAndFixInfo.range,
|
||||
rangeAndFixInfo.fixInfo
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue