mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-10-26 19:31:42 +03:00
Add option to allow tight lists in no-missing-blank-lines
This new feature adds support for allowing missing blank lines between block-level nodes in lists, through passing `{exceptTightLists: true}` to `no-missing-blank-lines` (default: false). Closes GH-85.
This commit is contained in:
parent
956f380d86
commit
a4085f2664
35
doc/rules.md
35
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
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user