remark-lint-list-item-spacing
Advanced tools
Comparing version 1.0.0 to 1.1.0
116
index.js
@@ -15,2 +15,10 @@ /** | ||
* | ||
* By default, all items must be “loose” (a blank line must be between | ||
* them) if one or more items are multiline (span more than one line). | ||
* Otherwise, the list must be tight (no blank line must be between | ||
* items). | ||
* | ||
* If you pass `{checkBlanks: true}`, all items must be “loose” if one or | ||
* more items contain blank lines. Otherwise, the list must be tight. | ||
* | ||
* @example {"name": "valid.md"} | ||
@@ -56,2 +64,67 @@ * | ||
* 13:1-14:1: Extraneous new line after list item | ||
* | ||
* @example {"name": "valid.md", "setting": {"checkBlanks": true}} | ||
* | ||
* A tight list: | ||
* | ||
* - item 1 | ||
* - item 1.A | ||
* - item 2 | ||
* > Blockquote | ||
* - item 3 | ||
* ```js | ||
* code() | ||
* ``` | ||
* | ||
* A loose list: | ||
* | ||
* - item 1 | ||
* | ||
* - item 1.A | ||
* | ||
* - item 2 | ||
* | ||
* > Blockquote | ||
* | ||
* - item 3 | ||
* | ||
* ```js | ||
* code() | ||
* ``` | ||
* | ||
* @example {"name": "invalid.md", "setting": {"checkBlanks": true}, "label": "input"} | ||
* | ||
* A tight list: | ||
* | ||
* - item 1 | ||
* | ||
* - item 1.A | ||
* - item 2 | ||
* | ||
* > Blockquote | ||
* - item 3 | ||
* | ||
* ```js | ||
* code() | ||
* ``` | ||
* | ||
* A loose list: | ||
* | ||
* - item 1 | ||
* - item 1.A | ||
* | ||
* - item 2 | ||
* > Blockquote | ||
* | ||
* - item 3 | ||
* ```js | ||
* code() | ||
* ``` | ||
* | ||
* @example {"name": "invalid.md", "setting": {"checkBlanks": true}, "label": "output"} | ||
* | ||
* 5:15-6:1: Missing new line after list item | ||
* 8:17-9:1: Missing new line after list item | ||
* 19:1-20:1: Extraneous new line after list item | ||
* 22:1-23:1: Extraneous new line after list item | ||
*/ | ||
@@ -71,3 +144,9 @@ | ||
function listItemSpacing(ast, file) { | ||
function listItemSpacing(ast, file, preferred) { | ||
var blanks = Boolean( | ||
preferred && | ||
typeof preferred === 'object' && | ||
preferred.checkBlanks | ||
); | ||
visit(ast, 'list', visitor); | ||
@@ -92,8 +171,5 @@ | ||
function infer(item) { | ||
var content = item.children; | ||
var head = content[0]; | ||
var tail = content[content.length - 1]; | ||
var isLoose = (end(tail).line - start(head).line) > 0; | ||
var fn = blanks ? inferBlankLine : inferMultiline; | ||
if (isLoose) { | ||
if (fn(item)) { | ||
isTightList = false; | ||
@@ -103,2 +179,30 @@ } | ||
function inferBlankLine(item) { | ||
var children = item.children; | ||
var length = children.length; | ||
var index = 0; | ||
var child = children[index]; | ||
var next; | ||
while (++index < length) { | ||
next = children[index]; | ||
/* All children in `listItem`s are block. */ | ||
if ((start(next).line - end(child).line) > 1) { | ||
return true; | ||
} | ||
child = next; | ||
} | ||
return false; | ||
} | ||
function inferMultiline(item) { | ||
var content = item.children; | ||
var head = content[0]; | ||
var tail = content[content.length - 1]; | ||
return (end(tail).line - start(head).line) > 0; | ||
} | ||
function warn(item, index) { | ||
@@ -105,0 +209,0 @@ var next = items[index + 1]; |
{ | ||
"name": "remark-lint-list-item-spacing", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "remark-lint rule to warn when list looseness is incorrect", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -13,2 +13,10 @@ <!--This file is generated--> | ||
By default, all items must be “loose” (a blank line must be between | ||
them) if one or more items are multiline (span more than one line). | ||
Otherwise, the list must be tight (no blank line must be between | ||
items). | ||
If you pass `{checkBlanks: true}`, all items must be “loose” if one or | ||
more items contain blank lines. Otherwise, the list must be tight. | ||
## Install | ||
@@ -69,4 +77,75 @@ | ||
When this rule is `{ checkBlanks: true }`, the following file | ||
`valid.md` is ok: | ||
````markdown | ||
A tight list: | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Blockquote | ||
- item 3 | ||
```js | ||
code() | ||
``` | ||
A loose list: | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Blockquote | ||
- item 3 | ||
```js | ||
code() | ||
``` | ||
```` | ||
When this rule is `{ checkBlanks: true }`, the following file | ||
`invalid.md` is **not** ok: | ||
````markdown | ||
A tight list: | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Blockquote | ||
- item 3 | ||
```js | ||
code() | ||
``` | ||
A loose list: | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Blockquote | ||
- item 3 | ||
```js | ||
code() | ||
``` | ||
```` | ||
```text | ||
5:15-6:1: Missing new line after list item | ||
8:17-9:1: Missing new line after list item | ||
19:1-20:1: Extraneous new line after list item | ||
22:1-23:1: Extraneous new line after list item | ||
``` | ||
## License | ||
[MIT](https://github.com/wooorm/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8535
207
150