mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Refactor MD049/emphasis-style and MD050/strong-style slightly to simplify.
This commit is contained in:
parent
d5f108b35e
commit
a4a38ec9d2
2 changed files with 64 additions and 52 deletions
|
|
@ -6092,7 +6092,8 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
|
||||||
forEachInlineChild = _require.forEachInlineChild,
|
forEachInlineChild = _require.forEachInlineChild,
|
||||||
getNextChildToken = _require.getNextChildToken,
|
getNextChildToken = _require.getNextChildToken,
|
||||||
getRangeAndFixInfoIfFound = _require.getRangeAndFixInfoIfFound;
|
getRangeAndFixInfoIfFound = _require.getRangeAndFixInfoIfFound;
|
||||||
var impl = function impl(params, onError, tagPrefix, asterisk, underline, style) {
|
var impl = function impl(params, onError, tagPrefix, asterisk, underline) {
|
||||||
|
var style = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "consistent";
|
||||||
var lastLineNumber = -1;
|
var lastLineNumber = -1;
|
||||||
var instances = new Map();
|
var instances = new Map();
|
||||||
forEachInlineChild(params, "".concat(tagPrefix, "_open"), function (token, parent) {
|
forEachInlineChild(params, "".concat(tagPrefix, "_open"), function (token, parent) {
|
||||||
|
|
@ -6118,7 +6119,7 @@ var impl = function impl(params, onError, tagPrefix, asterisk, underline, style)
|
||||||
instances.set(expected, instance);
|
instances.set(expected, instance);
|
||||||
rangeAndFixInfo = getRangeAndFixInfoIfFound(params.lines, lineNumber - 1, actual, expected, instance);
|
rangeAndFixInfo = getRangeAndFixInfoIfFound(params.lines, lineNumber - 1, actual, expected, instance);
|
||||||
}
|
}
|
||||||
addError(onError, lineNumber, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), null, rangeAndFixInfo.range, rangeAndFixInfo.fixInfo);
|
addError(onError, lineNumber, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), undefined, rangeAndFixInfo.range, rangeAndFixInfo.fixInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -6127,16 +6128,14 @@ module.exports = [{
|
||||||
"description": "Emphasis style should be consistent",
|
"description": "Emphasis style should be consistent",
|
||||||
"tags": ["emphasis"],
|
"tags": ["emphasis"],
|
||||||
"function": function MD049(params, onError) {
|
"function": function MD049(params, onError) {
|
||||||
var style = String(params.config.style || "consistent");
|
return impl(params, onError, "em", "*", "_", params.config.style || undefined);
|
||||||
return impl(params, onError, "em", "*", "_", style);
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"names": ["MD050", "strong-style"],
|
"names": ["MD050", "strong-style"],
|
||||||
"description": "Strong style should be consistent",
|
"description": "Strong style should be consistent",
|
||||||
"tags": ["emphasis"],
|
"tags": ["emphasis"],
|
||||||
"function": function MD050(params, onError) {
|
"function": function MD050(params, onError) {
|
||||||
var style = String(params.config.style || "consistent");
|
return impl(params, onError, "strong", "**", "__", params.config.style || undefined);
|
||||||
return impl(params, onError, "strong", "**", "__", style);
|
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,51 +5,52 @@
|
||||||
const { addError, emphasisOrStrongStyleFor, forEachInlineChild,
|
const { addError, emphasisOrStrongStyleFor, forEachInlineChild,
|
||||||
getNextChildToken, getRangeAndFixInfoIfFound } = require("../helpers");
|
getNextChildToken, getRangeAndFixInfoIfFound } = require("../helpers");
|
||||||
|
|
||||||
const impl = (params, onError, tagPrefix, asterisk, underline, style) => {
|
const impl =
|
||||||
let lastLineNumber = -1;
|
(params, onError, tagPrefix, asterisk, underline, style = "consistent") => {
|
||||||
const instances = new Map();
|
let lastLineNumber = -1;
|
||||||
forEachInlineChild(params, `${tagPrefix}_open`, (token, parent) => {
|
const instances = new Map();
|
||||||
const { lineNumber, markup } = token;
|
forEachInlineChild(params, `${tagPrefix}_open`, (token, parent) => {
|
||||||
const markupStyle = emphasisOrStrongStyleFor(markup);
|
const { lineNumber, markup } = token;
|
||||||
if (style === "consistent") {
|
const markupStyle = emphasisOrStrongStyleFor(markup);
|
||||||
style = markupStyle;
|
if (style === "consistent") {
|
||||||
}
|
style = markupStyle;
|
||||||
if (style !== markupStyle) {
|
}
|
||||||
let rangeAndFixInfo = {};
|
if (style !== markupStyle) {
|
||||||
const contentToken = getNextChildToken(
|
let rangeAndFixInfo = {};
|
||||||
parent, token, "text", `${tagPrefix}_close`
|
const contentToken = getNextChildToken(
|
||||||
);
|
parent, token, "text", `${tagPrefix}_close`
|
||||||
if (contentToken) {
|
);
|
||||||
const { content } = contentToken;
|
if (contentToken) {
|
||||||
const actual = `${markup}${content}${markup}`;
|
const { content } = contentToken;
|
||||||
const expectedMarkup =
|
const actual = `${markup}${content}${markup}`;
|
||||||
(style === "asterisk") ? asterisk : underline;
|
const expectedMarkup =
|
||||||
const expected = `${expectedMarkup}${content}${expectedMarkup}`;
|
(style === "asterisk") ? asterisk : underline;
|
||||||
if (lastLineNumber !== lineNumber) {
|
const expected = `${expectedMarkup}${content}${expectedMarkup}`;
|
||||||
lastLineNumber = lineNumber;
|
if (lastLineNumber !== lineNumber) {
|
||||||
instances.clear();
|
lastLineNumber = lineNumber;
|
||||||
|
instances.clear();
|
||||||
|
}
|
||||||
|
const instance = (instances.get(expected) || 0) + 1;
|
||||||
|
instances.set(expected, instance);
|
||||||
|
rangeAndFixInfo = getRangeAndFixInfoIfFound(
|
||||||
|
params.lines,
|
||||||
|
lineNumber - 1,
|
||||||
|
actual,
|
||||||
|
expected,
|
||||||
|
instance
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const instance = (instances.get(expected) || 0) + 1;
|
addError(
|
||||||
instances.set(expected, instance);
|
onError,
|
||||||
rangeAndFixInfo = getRangeAndFixInfoIfFound(
|
lineNumber,
|
||||||
params.lines,
|
`Expected: ${style}; Actual: ${markupStyle}`,
|
||||||
lineNumber - 1,
|
undefined,
|
||||||
actual,
|
rangeAndFixInfo.range,
|
||||||
expected,
|
rangeAndFixInfo.fixInfo
|
||||||
instance
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
addError(
|
});
|
||||||
onError,
|
};
|
||||||
lineNumber,
|
|
||||||
`Expected: ${style}; Actual: ${markupStyle}`,
|
|
||||||
null,
|
|
||||||
rangeAndFixInfo.range,
|
|
||||||
rangeAndFixInfo.fixInfo
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
|
|
@ -57,8 +58,14 @@ module.exports = [
|
||||||
"description": "Emphasis style should be consistent",
|
"description": "Emphasis style should be consistent",
|
||||||
"tags": [ "emphasis" ],
|
"tags": [ "emphasis" ],
|
||||||
"function": function MD049(params, onError) {
|
"function": function MD049(params, onError) {
|
||||||
const style = String(params.config.style || "consistent");
|
return impl(
|
||||||
return impl(params, onError, "em", "*", "_", style);
|
params,
|
||||||
|
onError,
|
||||||
|
"em",
|
||||||
|
"*",
|
||||||
|
"_",
|
||||||
|
params.config.style || undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -66,8 +73,14 @@ module.exports = [
|
||||||
"description": "Strong style should be consistent",
|
"description": "Strong style should be consistent",
|
||||||
"tags": [ "emphasis" ],
|
"tags": [ "emphasis" ],
|
||||||
"function": function MD050(params, onError) {
|
"function": function MD050(params, onError) {
|
||||||
const style = String(params.config.style || "consistent");
|
return impl(
|
||||||
return impl(params, onError, "strong", "**", "__", style);
|
params,
|
||||||
|
onError,
|
||||||
|
"strong",
|
||||||
|
"**",
|
||||||
|
"__",
|
||||||
|
params.config.style || undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue