diff --git a/README.md b/README.md index a6edf7b2..9b0fc19e 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ cases come directly from that project. * **MD032** - Lists should be surrounded by blank lines * **MD033** - Inline HTML * **MD034** - Bare URL used +* **MD035** - Horizontal rule style See [Rules.md](doc/Rules.md) for more details. @@ -79,6 +80,7 @@ See [Rules.md](doc/Rules.md) for more details. * **hard_tab** - MD010 * **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026 +* **hr** - MD035 * **html** - MD033 * **indentation** - MD005, MD006, MD007, MD027 * **line_length** - MD013 diff --git a/doc/Rules.md b/doc/Rules.md index 0a5e4950..9839a921 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -731,3 +731,37 @@ enclose it in a code block, otherwise in some markdown parsers it _will_ be converted: `http://www.example.com` + +## MD035 - Horizontal rule style + +Tags: hr + +Parameters: style ("consistent", "---", "***", or other string specifying the +horizontal rule; default "consistent") + +This rule is triggered when inconsistent styles of horizontal rules are used +in the document: + + --- + + - - - + + *** + + * * * + + **** + +To fix this, ensure any horizontal rules used in the document are consistent, +or match the given style if the rule is so configured: + + --- + + --- + +Note: by default, this rule is configured to just require that all horizontal +rules in the document are the same, and will trigger if any of the horizontal +rules are different than the first one encountered in the document. If you +want to configure the rule to match a specific style, the parameter given to +the 'style' option is a string containing the exact horizontal rule text that +is allowed. diff --git a/lib/rules.js b/lib/rules.js index f03dde41..2ad96268 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -649,5 +649,23 @@ module.exports = [ }); }); } + }, + + { + "name": "MD035", + "desc": "Horizontal rule style", + "tags": [ "hr" ], + "func": function MD035(params, errors) { + var style = params.options.style || "consistent"; + var horizontalRules = filterTokens(params.tokens, "hr"); + if ((style === "consistent") && horizontalRules.length) { + style = horizontalRules[0].line; + } + horizontalRules.forEach(function forToken(token) { + if (token.line !== style) { + errors.push(token.lineNumber); + } + }); + } } ]; diff --git a/style/cirosantilli.json b/style/cirosantilli.json index eede1446..41dae224 100644 --- a/style/cirosantilli.json +++ b/style/cirosantilli.json @@ -15,5 +15,8 @@ "ul_multi": 3, "ol_multi": 2 }, - "MD033": false + "MD033": false, + "MD035": { + "style": "---" + } } diff --git a/test/hr_style_dashes.json b/test/hr_style_dashes.json new file mode 100644 index 00000000..950405e6 --- /dev/null +++ b/test/hr_style_dashes.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD035": { + "style": "---" + } +} diff --git a/test/hr_style_dashes.md b/test/hr_style_dashes.md new file mode 100644 index 00000000..9a692250 --- /dev/null +++ b/test/hr_style_dashes.md @@ -0,0 +1,22 @@ +*** + +* * * + +***** + +--- + +- - - + +----- + +___ + +_ _ _ + +_____ + +*** + +{MD035:1} {MD035:3} {MD035:5} {MD035:9} {MD035:11} {MD035:13} {MD035:15} +{MD035:17} {MD035:19} diff --git a/test/hr_style_inconsistent.md b/test/hr_style_inconsistent.md new file mode 100644 index 00000000..df3cc726 --- /dev/null +++ b/test/hr_style_inconsistent.md @@ -0,0 +1,22 @@ +*** + +* * * + +***** + +--- + +- - - + +----- + +___ + +_ _ _ + +_____ + +*** + +{MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} +{MD035:17} diff --git a/test/hr_style_long.json b/test/hr_style_long.json new file mode 100644 index 00000000..deb61b30 --- /dev/null +++ b/test/hr_style_long.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD035": { + "style": "_____" + } +} diff --git a/test/hr_style_long.md b/test/hr_style_long.md new file mode 100644 index 00000000..0e9b1db2 --- /dev/null +++ b/test/hr_style_long.md @@ -0,0 +1,22 @@ +*** + +* * * + +***** + +--- + +- - - + +----- + +___ + +_ _ _ + +_____ + +*** + +{MD035:1} {MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} +{MD035:15} {MD035:19} diff --git a/test/hr_style_stars.json b/test/hr_style_stars.json new file mode 100644 index 00000000..eed96d15 --- /dev/null +++ b/test/hr_style_stars.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD035": { + "style": "***" + } +} diff --git a/test/hr_style_stars.md b/test/hr_style_stars.md new file mode 100644 index 00000000..df3cc726 --- /dev/null +++ b/test/hr_style_stars.md @@ -0,0 +1,22 @@ +*** + +* * * + +***** + +--- + +- - - + +----- + +___ + +_ _ _ + +_____ + +*** + +{MD035:3} {MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} +{MD035:17} diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 3f984abd..619aa984 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -498,7 +498,7 @@ module.exports.badFileSync = function badFileSync(test) { }; module.exports.readme = function readme(test) { - test.expect(80); + test.expect(83); var tagToRules = {}; rules.forEach(function forRule(rule) { rule.tags.forEach(function forTag(tag) { @@ -555,7 +555,7 @@ module.exports.readme = function readme(test) { }; module.exports.doc = function doc(test) { - test.expect(123); + test.expect(127); fs.readFile("doc/Rules.md", shared.utf8Encoding, function readFile(err, contents) { test.ifError(err);