diff --git a/doc/rules.md b/doc/rules.md index fb13a051..f2689334 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -1790,7 +1790,11 @@ mailto:qux@quux.com ## `no-missing-blank-lines` -Warn for missing blank lines before a block node. +Warn when missing blank lines before a block node. + +This rule can be configured to allow tight list items +without blank lines between their contents through +`exceptTightLists: true` (default: false). When this rule is turned on, the following file `valid.md` is ok: @@ -1799,6 +1803,12 @@ When this rule is turned on, the following file # Foo ## Bar + +- Paragraph + + + List. + +Paragraph. ``` When this rule is turned on, the following file @@ -1807,6 +1817,29 @@ When this rule is turned on, the following file ```markdown # Foo ## Bar + +- Paragraph + + List. + +Paragraph. +``` + +```text +2:1-2:7: Missing blank line before block node +5:3-5:10: Missing blank line before block node +``` + +When this rule is `{ exceptTightLists: true }`, the following file +`tight.md` is **not** ok: + +```markdown +# Foo +## Bar + +- Paragraph + + List. + +Paragraph. ``` ```text diff --git a/lib/rules/no-missing-blank-lines.js b/lib/rules/no-missing-blank-lines.js index 36cd7404..fae9ca16 100644 --- a/lib/rules/no-missing-blank-lines.js +++ b/lib/rules/no-missing-blank-lines.js @@ -4,7 +4,11 @@ * @license MIT * @module no-missing-blank-lines * @fileoverview - * Warn for missing blank lines before a block node. + * Warn when missing blank lines before a block node. + * + * This rule can be configured to allow tight list items + * without blank lines between their contents through + * `exceptTightLists: true` (default: false). * * @example {"name": "valid.md"} * @@ -12,14 +16,40 @@ * * ## Bar * + * - Paragraph + * + * + List. + * + * Paragraph. + * * @example {"name": "invalid.md", "label": "input"} * * # Foo * ## Bar * + * - Paragraph + * + List. + * + * Paragraph. + * * @example {"name": "invalid.md", "label": "output"} * * 2:1-2:7: Missing blank line before block node + * 5:3-5:10: Missing blank line before block node + * + * @example {"name": "tight.md", "setting": {"exceptTightLists": true}, "label": "input"} + * + * # Foo + * ## Bar + * + * - Paragraph + * + List. + * + * Paragraph. + * + * @example {"name": "tight.md", "setting": {"exceptTightLists": true}, "label": "output"} + * + * 2:1-2:7: Missing blank line before block node */ 'use strict'; @@ -38,7 +68,9 @@ module.exports = noMissingBlankLines; * @param {Node} ast - Root node. * @param {File} file - Virtual file. */ -function noMissingBlankLines(ast, file) { +function noMissingBlankLines(ast, file, options) { + var allow = (options || {}).exceptTightLists; + visit(ast, function (node, index, parent) { var next = parent && parent.children[index + 1]; @@ -46,10 +78,14 @@ function noMissingBlankLines(ast, file) { return; } + if (allow && parent && parent.type === 'listItem') { + return; + } + if ( next && - isApplicable(node) && - isApplicable(next) && + applicable(node) && + applicable(next) && position.start(next).line === position.end(node).line + 1 ) { file.warn('Missing blank line before block node', next); @@ -63,7 +99,7 @@ function noMissingBlankLines(ast, file) { * @param {Node} node - Node to test. * @return {boolean} - Whether or not `node` is applicable. */ -function isApplicable(node) { +function applicable(node) { return [ 'paragraph', 'blockquote',