diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 3ec5d9c1f..9fce96cf1 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -2063,10 +2063,18 @@ function getEnabledRulesPerLineNumber( handleInlineConfig(lines, enableDisableFile); handleInlineConfig(lines, captureRestoreEnableDisable, updateLineState); handleInlineConfig(lines, disableLineNextLine); + // Create the list of rules that are used at least once + const enabledRuleList = []; + for (const [ index, ruleName ] of allRuleNames.entries()) { + if (enabledRulesPerLineNumber.some((enabledRulesForLine) => enabledRulesForLine[ruleName])) { + enabledRuleList.push(ruleList[index]); + } + } // Return results return { effectiveConfig, - enabledRulesPerLineNumber + enabledRulesPerLineNumber, + enabledRuleList }; } @@ -2108,7 +2116,7 @@ function lintContent( const { frontMatterLines } = removeFrontMatterResult; content = removeFrontMatterResult.content; // Get enabled rules per line (with HTML comments present) - const { effectiveConfig, enabledRulesPerLineNumber } = + const { effectiveConfig, enabledRulesPerLineNumber, enabledRuleList } = getEnabledRulesPerLineNumber( ruleList, content.split(helpers.newLineRe), @@ -2118,7 +2126,7 @@ function lintContent( configParsers, aliasToRuleNames ); - const needMarkdownItTokens = ruleList.some( + const needMarkdownItTokens = enabledRuleList.some( (rule) => (rule.parser === "markdownit") || (rule.parser === undefined) ); // Parse content into parser tokens @@ -2350,8 +2358,8 @@ function lintContent( return results; } // Run all rules - const ruleListAsync = ruleList.filter((rule) => rule.asynchronous); - const ruleListSync = ruleList.filter((rule) => !rule.asynchronous); + const ruleListAsync = enabledRuleList.filter((rule) => rule.asynchronous); + const ruleListSync = enabledRuleList.filter((rule) => !rule.asynchronous); const ruleListAsyncFirst = [ ...ruleListAsync, ...ruleListSync diff --git a/lib/markdownlint.js b/lib/markdownlint.js index eb157325e..2c2847ef8 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -510,10 +510,18 @@ function getEnabledRulesPerLineNumber( handleInlineConfig(lines, enableDisableFile); handleInlineConfig(lines, captureRestoreEnableDisable, updateLineState); handleInlineConfig(lines, disableLineNextLine); + // Create the list of rules that are used at least once + const enabledRuleList = []; + for (const [ index, ruleName ] of allRuleNames.entries()) { + if (enabledRulesPerLineNumber.some((enabledRulesForLine) => enabledRulesForLine[ruleName])) { + enabledRuleList.push(ruleList[index]); + } + } // Return results return { effectiveConfig, - enabledRulesPerLineNumber + enabledRulesPerLineNumber, + enabledRuleList }; } @@ -555,7 +563,7 @@ function lintContent( const { frontMatterLines } = removeFrontMatterResult; content = removeFrontMatterResult.content; // Get enabled rules per line (with HTML comments present) - const { effectiveConfig, enabledRulesPerLineNumber } = + const { effectiveConfig, enabledRulesPerLineNumber, enabledRuleList } = getEnabledRulesPerLineNumber( ruleList, content.split(helpers.newLineRe), @@ -565,7 +573,7 @@ function lintContent( configParsers, aliasToRuleNames ); - const needMarkdownItTokens = ruleList.some( + const needMarkdownItTokens = enabledRuleList.some( (rule) => (rule.parser === "markdownit") || (rule.parser === undefined) ); // Parse content into parser tokens @@ -797,8 +805,8 @@ function lintContent( return results; } // Run all rules - const ruleListAsync = ruleList.filter((rule) => rule.asynchronous); - const ruleListSync = ruleList.filter((rule) => !rule.asynchronous); + const ruleListAsync = enabledRuleList.filter((rule) => rule.asynchronous); + const ruleListSync = enabledRuleList.filter((rule) => !rule.asynchronous); const ruleListAsyncFirst = [ ...ruleListAsync, ...ruleListSync diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 3a5a7f3d1..234b09ec4 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -1161,6 +1161,28 @@ test("markdownItPluginsNoMarkdownIt", (t) => new Promise((resolve) => { }); })); +test("markdownItPluginsUnusedUncalled", (t) => new Promise((resolve) => { + t.plan(2); + markdownlint({ + "config": { + "default": false + }, + "strings": { + "string": "# Heading\n\nText\n" + }, + // Use a markdown-it custom rule so the markdown-it plugin will be run + "customRules": customRules.anyBlockquote, + "markdownItPlugins": [ + [ pluginInline, "check_text_plugin", "text", () => t.fail() ] + ] + }, function callback(err, actual) { + t.falsy(err); + const expected = { "string": [] }; + t.deepEqual(actual, expected, "Unexpected issues."); + resolve(); + }); +})); + test("Pandoc footnote", (t) => new Promise((resolve) => { t.plan(2); markdownlint({