diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 7e49292e..7abc89b1 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -4411,88 +4411,55 @@ module.exports = { // @ts-check var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, emphasisOrStrongStyleFor = _a.emphasisOrStrongStyleFor, forEachInlineChild = _a.forEachInlineChild, getNextChildToken = _a.getNextChildToken, getRangeAndFixInfoIfFound = _a.getRangeAndFixInfoIfFound; -module.exports = { - "names": ["MD049", "emphasis-style"], - "description": "Emphasis style should be consistent", - "tags": ["emphasis"], - "function": function MD049(params, onError) { - var expectedStyle = String(params.config.style || "consistent"); - var lastLineNumber = -1; - var instances = new Map(); - forEachInlineChild(params, "em_open", function (token, parent) { - var lineNumber = token.lineNumber, markup = token.markup; - var markupStyle = emphasisOrStrongStyleFor(markup); - if (expectedStyle === "consistent") { - expectedStyle = markupStyle; - } - if (expectedStyle !== markupStyle) { - var rangeAndFixInfo = {}; - var contentToken = getNextChildToken(parent, token, "text", "em_close"); - if (contentToken) { - var content = contentToken.content; - var actual = "".concat(markup).concat(content).concat(markup); - var expectedMarkup = (expectedStyle === "asterisk") ? "*" : "_"; - var expected = "".concat(expectedMarkup).concat(content).concat(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)); +var impl = function (params, onError, tagPrefix, asterisk, underline, style) { + var lastLineNumber = -1; + var instances = new Map(); + forEachInlineChild(params, "".concat(tagPrefix, "_open"), function (token, parent) { + var lineNumber = token.lineNumber, markup = token.markup; + var markupStyle = emphasisOrStrongStyleFor(markup); + if (style === "consistent") { + style = markupStyle; + } + if (style !== markupStyle) { + var rangeAndFixInfo = {}; + var contentToken = getNextChildToken(parent, token, "text", "".concat(tagPrefix, "_close")); + if (contentToken) { + var content = contentToken.content; + var actual = "".concat(markup).concat(content).concat(markup); + var expectedMarkup = (style === "asterisk") ? asterisk : underline; + var expected = "".concat(expectedMarkup).concat(content).concat(expectedMarkup); + if (lastLineNumber !== lineNumber) { + lastLineNumber = lineNumber; + instances.clear(); } - addError(onError, lineNumber, "Expected: ".concat(expectedStyle, "; Actual: ").concat(markupStyle), null, rangeAndFixInfo.range, rangeAndFixInfo.fixInfo); + var instance = (instances.get(expected) || 0) + 1; + instances.set(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); + } + }); }; - - -/***/ }), - -/***/ "../lib/md050.js": -/*!***********************!*\ - !*** ../lib/md050.js ***! - \***********************/ -/***/ ((module, __unused_webpack_exports, __webpack_require__) => { - -"use strict"; -// @ts-check - -var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addError = _a.addError, emphasisOrStrongStyleFor = _a.emphasisOrStrongStyleFor, forEachInlineChild = _a.forEachInlineChild, getNextChildToken = _a.getNextChildToken, getRangeAndFixInfoIfFound = _a.getRangeAndFixInfoIfFound; -module.exports = { - "names": ["MD050", "strong-style"], - "description": "Strong style should be consistent", - "tags": ["emphasis"], - "function": function MD050(params, onError) { - var expectedStyle = String(params.config.style || "consistent"); - var lastLineNumber = -1; - var instances = new Map(); - forEachInlineChild(params, "strong_open", function (token, parent) { - var lineNumber = token.lineNumber, markup = token.markup; - var markupStyle = emphasisOrStrongStyleFor(markup); - if (expectedStyle === "consistent") { - expectedStyle = markupStyle; - } - if (expectedStyle !== markupStyle) { - var rangeAndFixInfo = {}; - var contentToken = getNextChildToken(parent, token, "text", "strong_close"); - if (contentToken) { - var content = contentToken.content; - var actual = "".concat(markup).concat(content).concat(markup); - var expectedMarkup = (expectedStyle === "asterisk") ? "**" : "__"; - var expected = "".concat(expectedMarkup).concat(content).concat(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: ".concat(expectedStyle, "; Actual: ").concat(markupStyle), null, rangeAndFixInfo.range, rangeAndFixInfo.fixInfo); - } - }); +module.exports = [ + { + "names": ["MD049", "emphasis-style"], + "description": "Emphasis style should be consistent", + "tags": ["emphasis"], + "function": function MD049(params, onError) { + var style = String(params.config.style || "consistent"); + return impl(params, onError, "em", "*", "_", style); + } + }, + { + "names": ["MD050", "strong-style"], + "description": "Strong style should be consistent", + "tags": ["emphasis"], + "function": function MD050(params, onError) { + var style = String(params.config.style || "consistent"); + return impl(params, onError, "strong", "**", "__", style); + } } -}; +]; /***/ }), @@ -4583,13 +4550,22 @@ module.exports = { /*!***********************!*\ !*** ../lib/rules.js ***! \***********************/ -/***/ ((module, __unused_webpack_exports, __webpack_require__) => { +/***/ (function(module, __unused_webpack_exports, __webpack_require__) { "use strict"; // @ts-check +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; var _a = __webpack_require__(/*! ./constants */ "../lib/constants.js"), homepage = _a.homepage, version = _a.version; -var rules = [ +var rules = __spreadArray(__spreadArray([ __webpack_require__(/*! ./md001 */ "../lib/md001.js"), __webpack_require__(/*! ./md002 */ "../lib/md002.js"), __webpack_require__(/*! ./md003 */ "../lib/md003.js"), @@ -4633,11 +4609,10 @@ var rules = [ __webpack_require__(/*! ./md045 */ "../lib/md045.js"), __webpack_require__(/*! ./md046 */ "../lib/md046.js"), __webpack_require__(/*! ./md047 */ "../lib/md047.js"), - __webpack_require__(/*! ./md048 */ "../lib/md048.js"), - __webpack_require__(/*! ./md049-md050 */ "../lib/md049-md050.js"), - __webpack_require__(/*! ./md050 */ "../lib/md050.js"), + __webpack_require__(/*! ./md048 */ "../lib/md048.js") +], __webpack_require__(/*! ./md049-md050 */ "../lib/md049-md050.js"), true), [ __webpack_require__(/*! ./md051 */ "../lib/md051.js") -]; +], false); rules.forEach(function (rule) { var name = rule.names[0].toLowerCase(); // eslint-disable-next-line dot-notation diff --git a/lib/md049-md050.js b/lib/md049-md050.js index 74aaf809..43e64044 100644 --- a/lib/md049-md050.js +++ b/lib/md049-md050.js @@ -5,52 +5,69 @@ 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) - ); +const impl = (params, onError, tagPrefix, asterisk, underline, style) => { + let lastLineNumber = -1; + const instances = new Map(); + forEachInlineChild(params, `${tagPrefix}_open`, (token, parent) => { + const { lineNumber, markup } = token; + const markupStyle = emphasisOrStrongStyleFor(markup); + if (style === "consistent") { + style = markupStyle; + } + if (style !== markupStyle) { + let rangeAndFixInfo = {}; + const contentToken = getNextChildToken( + parent, token, "text", `${tagPrefix}_close` + ); + if (contentToken) { + const { content } = contentToken; + const actual = `${markup}${content}${markup}`; + const expectedMarkup = + (style === "asterisk") ? asterisk : underline; + const expected = `${expectedMarkup}${content}${expectedMarkup}`; + if (lastLineNumber !== lineNumber) { + lastLineNumber = lineNumber; + instances.clear(); } - addError( - onError, - lineNumber, - `Expected: ${expectedStyle}; Actual: ${markupStyle}`, - null, - rangeAndFixInfo.range, - rangeAndFixInfo.fixInfo + const instance = (instances.get(expected) || 0) + 1; + instances.set(expected, instance); + rangeAndFixInfo = getRangeAndFixInfoIfFound( + params.lines, + lineNumber - 1, + actual, + expected, + instance ); } - }); - } + addError( + onError, + lineNumber, + `Expected: ${style}; Actual: ${markupStyle}`, + null, + rangeAndFixInfo.range, + rangeAndFixInfo.fixInfo + ); + } + }); }; + +module.exports = [ + { + "names": [ "MD049", "emphasis-style" ], + "description": "Emphasis style should be consistent", + "tags": [ "emphasis" ], + "function": function MD049(params, onError) { + const style = String(params.config.style || "consistent"); + return impl(params, onError, "em", "*", "_", style); + } + }, + { + "names": [ "MD050", "strong-style" ], + "description": "Strong style should be consistent", + "tags": [ "emphasis" ], + "function": function MD050(params, onError) { + const style = String(params.config.style || "consistent"); + return impl(params, onError, "strong", "**", "__", style); + } + } +]; diff --git a/lib/md050.js b/lib/md050.js deleted file mode 100644 index 28c53f91..00000000 --- a/lib/md050.js +++ /dev/null @@ -1,56 +0,0 @@ -// @ts-check - -"use strict"; - -const { addError, emphasisOrStrongStyleFor, forEachInlineChild, - getNextChildToken, getRangeAndFixInfoIfFound } = require("../helpers"); - -module.exports = { - "names": [ "MD050", "strong-style" ], - "description": "Strong style should be consistent", - "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); - if (expectedStyle === "consistent") { - expectedStyle = markupStyle; - } - if (expectedStyle !== markupStyle) { - let rangeAndFixInfo = {}; - const contentToken = getNextChildToken( - parent, token, "text", "strong_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 - ); - } - }); - } -}; diff --git a/lib/rules.js b/lib/rules.js index f52adc5b..fdcc9c3a 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -49,8 +49,7 @@ const rules = [ require("./md046"), require("./md047"), require("./md048"), - require("./md049-md050"), - require("./md050"), + ...require("./md049-md050"), require("./md051") ]; rules.forEach((rule) => {