diff --git a/doc/Rules.md b/doc/Rules.md index 4c47f9dc..e7ad7fc9 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -51,6 +51,9 @@ Aliases: first-heading-h1, first-header-h1 Parameters: level (number; default 1) +> Note: *MD002 has been deprecated and is disabled by default.* +> [MD041](#md041) offers an improved implementation of the rule. + This rule is intended to ensure document headings start at the top level and is triggered when the first heading in the document isn't an h1 heading: @@ -71,8 +74,6 @@ The first heading in the document should be an h1 heading: Note: The `level` parameter can be used to change the top level (ex: to h2) in cases where an h1 is added externally. -See also: [MD041](#md041) for an improved version of this rule. - ## MD003 - Heading style diff --git a/lib/markdownlint.js b/lib/markdownlint.js index 1a5391d7..511f8ef9 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -9,6 +9,8 @@ const markdownIt = require("markdown-it"); const rules = require("./rules"); const shared = require("./shared"); +const deprecatedRuleNames = [ "MD002" ]; + // Validates the list of rules for structure and reuse function validateRuleList(ruleList) { let result = null; @@ -212,16 +214,19 @@ function mapAliasToRuleNames(ruleList) { // Apply (and normalize) config function getEffectiveConfig(ruleList, config, aliasToRuleNames) { - const defaultKey = Object.keys(config).filter(function forKey(key) { - return key.toUpperCase() === "DEFAULT"; - }); + const defaultKey = Object.keys(config).filter( + (key) => key.toUpperCase() === "DEFAULT" + ); const ruleDefault = (defaultKey.length === 0) || !!config[defaultKey[0]]; const effectiveConfig = {}; - ruleList.forEach(function forRule(rule) { + ruleList.forEach((rule) => { const ruleName = rule.names[0].toUpperCase(); effectiveConfig[ruleName] = ruleDefault; }); - Object.keys(config).forEach(function forKey(key) { + deprecatedRuleNames.forEach((ruleName) => { + effectiveConfig[ruleName] = false; + }); + Object.keys(config).forEach((key) => { let value = config[key]; if (value) { if (!(value instanceof Object)) { @@ -231,7 +236,7 @@ function getEffectiveConfig(ruleList, config, aliasToRuleNames) { value = false; } const keyUpper = key.toUpperCase(); - (aliasToRuleNames[keyUpper] || []).forEach(function forRule(ruleName) { + (aliasToRuleNames[keyUpper] || []).forEach((ruleName) => { effectiveConfig[ruleName] = value; }); }); diff --git a/test/break-all-the-rules.json b/test/break-all-the-rules.json index ba0e7404..7b0c685c 100644 --- a/test/break-all-the-rules.json +++ b/test/break-all-the-rules.json @@ -1,5 +1,6 @@ { "default": true, + "MD002": true, "MD041": true, "MD043": { "headings": [ diff --git a/test/detailed-results-MD001-MD010.json b/test/detailed-results-MD001-MD010.json new file mode 100644 index 00000000..9275931c --- /dev/null +++ b/test/detailed-results-MD001-MD010.json @@ -0,0 +1,4 @@ +{ + "default": true, + "MD002": true +} diff --git a/test/first_heading_bad_atx.md b/test/first_heading_bad_atx.md index d28a1c77..37f21480 100644 --- a/test/first_heading_bad_atx.md +++ b/test/first_heading_bad_atx.md @@ -1 +1 @@ -## Heading {MD002} \ No newline at end of file +## Heading \ No newline at end of file diff --git a/test/first_heading_bad_setext.md b/test/first_heading_bad_setext.md index 462170c7..c9ebf7c5 100644 --- a/test/first_heading_bad_setext.md +++ b/test/first_heading_bad_setext.md @@ -1,2 +1,2 @@ -Heading {MD002} --------------- \ No newline at end of file +Heading +------- \ No newline at end of file diff --git a/test/front-matter-embedded.md b/test/front-matter-embedded.md index 1ea1c808..17720668 100644 --- a/test/front-matter-embedded.md +++ b/test/front-matter-embedded.md @@ -1,7 +1,7 @@ Text text text --- -layout: post {MD002} {MD022} +layout: post {MD022} hard: tab {MD010} title: embedded --- diff --git a/test/front-matter-with-dashes.md b/test/front-matter-with-dashes.md index bfd7bc0c..3ab79fa5 100644 --- a/test/front-matter-with-dashes.md +++ b/test/front-matter-with-dashes.md @@ -3,7 +3,7 @@ layout: post title: Title with --- tags: front matter --- -## Heading {MD002} +## Heading --- diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 7146bba6..6f8d57b2 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -140,7 +140,10 @@ module.exports.resultFormattingV0 = function resultFormattingV0(test) { "./test/atx_heading_spacing.md", "./test/first_heading_bad_atx.md" ], - "config": defaultConfig, + "config": { + "MD002": true, + "MD041": false + }, "resultVersion": 0 }; markdownlint(options, function callback(err, actualResult) { @@ -193,7 +196,10 @@ module.exports.resultFormattingSyncV0 = function resultFormattingSyncV0(test) { "./test/atx_heading_spacing.md", "./test/first_heading_bad_atx.md" ], - "config": defaultConfig, + "config": { + "MD002": true, + "MD041": false + }, "resultVersion": 0 }; const actualResult = markdownlint.sync(options); @@ -248,7 +254,10 @@ module.exports.resultFormattingV1 = function resultFormattingV1(test) { "./test/atx_heading_spacing.md", "./test/first_heading_bad_atx.md" ], - "config": defaultConfig, + "config": { + "MD002": true, + "MD041": false + }, "resultVersion": 1 }; markdownlint(options, function callback(err, actualResult) { @@ -347,7 +356,10 @@ module.exports.resultFormattingV2 = function resultFormattingV2(test) { "./test/atx_heading_spacing.md", "./test/first_heading_bad_atx.md" ], - "config": defaultConfig + "config": { + "MD002": true, + "MD041": false + } }; markdownlint(options, function callback(err, actualResult) { test.ifError(err); @@ -503,13 +515,11 @@ module.exports.defaultTrue = function defaultTrue(test) { test.ifError(err); const expectedResult = { "./test/atx_heading_spacing.md": { - "MD002": [ 3 ], "MD018": [ 1 ], "MD019": [ 3, 5 ], "MD041": [ 1 ] }, "./test/first_heading_bad_atx.md": { - "MD002": [ 1 ], "MD041": [ 1 ] } }; @@ -555,13 +565,11 @@ module.exports.defaultUndefined = function defaultUndefined(test) { test.ifError(err); const expectedResult = { "./test/atx_heading_spacing.md": { - "MD002": [ 3 ], "MD018": [ 1 ], "MD019": [ 3, 5 ], "MD041": [ 1 ] }, "./test/first_heading_bad_atx.md": { - "MD002": [ 1 ], "MD041": [ 1 ] } }; @@ -675,11 +683,9 @@ module.exports.disableTag = function disableTag(test) { test.ifError(err); const expectedResult = { "./test/atx_heading_spacing.md": { - "MD002": [ 3 ], "MD041": [ 1 ] }, "./test/first_heading_bad_atx.md": { - "MD002": [ 1 ], "MD041": [ 1 ] } }; @@ -767,7 +773,6 @@ module.exports.styleAll = function styleAll(test) { const expectedResult = { "./test/break-all-the-rules.md": { "MD001": [ 3 ], - "MD002": [ 1 ], "MD003": [ 5, 30 ], "MD004": [ 8 ], "MD005": [ 12 ], @@ -823,7 +828,6 @@ module.exports.styleRelaxed = function styleRelaxed(test) { const expectedResult = { "./test/break-all-the-rules.md": { "MD001": [ 3 ], - "MD002": [ 1 ], "MD003": [ 5, 30 ], "MD004": [ 8 ], "MD005": [ 12 ], @@ -2649,7 +2653,6 @@ $$` test.ifError(err); const expected = { "string": { - "MD002": [ 1 ], "MD041": [ 1 ] } }; diff --git a/test/no_first_line_top_level_heading.md b/test/no_first_line_top_level_heading.md index c4ef94c7..35d68ecb 100644 --- a/test/no_first_line_top_level_heading.md +++ b/test/no_first_line_top_level_heading.md @@ -1 +1 @@ -## Second level heading {MD041} {MD002} +## Second level heading {MD041} diff --git a/test/required-headings-missing-first.md b/test/required-headings-missing-first.md index 95bd40ea..85c4e81c 100644 --- a/test/required-headings-missing-first.md +++ b/test/required-headings-missing-first.md @@ -1,5 +1,5 @@ text -## Two {MD002} {MD043} +## Two {MD043} ### Three