remark-lint-list-item-spacing
Advanced tools
Comparing version 4.1.2 to 5.0.0
@@ -1,29 +0,18 @@ | ||
export default remarkLintListItemSpacing | ||
export type Root = import('mdast').Root | ||
export type ListItem = import('mdast').ListItem | ||
export default remarkLintListItemSpacing; | ||
export type ListItem = import('mdast').ListItem; | ||
export type Root = import('mdast').Root; | ||
/** | ||
* Options. | ||
* Configuration. | ||
*/ | ||
export type Options = { | ||
/** | ||
* Adhere to CommonMark looseness instead of markdown-style-guide preference. | ||
*/ | ||
checkBlanks?: boolean | null | undefined | ||
} | ||
declare const remarkLintListItemSpacing: import('unified').Plugin< | ||
| void[] | ||
| [ | ||
| Options | ||
| [ | ||
( | ||
| boolean | ||
| import('unified-lint-rule/lib/index.js').Label | ||
| import('unified-lint-rule/lib/index.js').Severity | ||
), | ||
(Options | undefined)? | ||
] | ||
| undefined | ||
], | ||
import('mdast').Root, | ||
import('mdast').Root | ||
> | ||
/** | ||
* Whether to follow CommonMark looseness instead of `markdown-style-guide` | ||
* preference (default: `false`). | ||
*/ | ||
checkBlanks?: boolean | null | undefined; | ||
}; | ||
declare const remarkLintListItemSpacing: { | ||
(config?: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity | Readonly<Options> | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: Readonly<Options> | null | undefined] | null | undefined): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined; | ||
readonly name: string; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
331
index.js
/** | ||
* remark-lint rule to warn when lists violate a given style. | ||
* | ||
* ## What is this? | ||
* | ||
* This package checks blank lines between list items. | ||
* | ||
* ## When should I use this? | ||
* | ||
* You can use this package to check that lists are loose or tight when | ||
* they should be. | ||
* You can use this package to check the style of lists. | ||
* | ||
* ## API | ||
* | ||
* The following options (default: `undefined`) are accepted: | ||
* ### `unified().use(remarkLintListItemSpacing[, options])` | ||
* | ||
* * `Object` with the following fields: | ||
* * `checkBlanks` (`boolean`, default: `false`) | ||
* — adhere to CommonMark looseness instead of markdown-style-guide | ||
* preference | ||
* Warn when lists violate a given style. | ||
* | ||
* ## Recommendation | ||
* ###### Parameters | ||
* | ||
* First, some background. | ||
* There are two types of lists in markdown (other than ordered and unordered): | ||
* tight and loose lists. | ||
* Lists are tight by default but if there is a blank line between two list | ||
* items or between two blocks inside an item, that turns the whole list into a | ||
* loose list. | ||
* When turning markdown into HTML, paragraphs in tight lists are not wrapped | ||
* in `<p>` tags. | ||
* * `options` ([`Options`][api-options], optional) | ||
* — configuration | ||
* | ||
* This rule defaults to the | ||
* [`markdown style guide`](https://cirosantilli.com/markdown-style-guide/) | ||
* preference for which lists should be loose or not: loose when at least one | ||
* item spans more than one line, tight otherwise. | ||
* With `{checkBlanks: true}`, this rule dictates that when at least one item is | ||
* loose, all items must be loose. | ||
* ###### Returns | ||
* | ||
* @module list-item-spacing | ||
* @summary | ||
* remark-lint rule to warn when lists are loose when they should be tight, | ||
* or vice versa. | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @example | ||
* {"name": "ok.md"} | ||
* Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
* | ||
* A tight list: | ||
* ### `Options` | ||
* | ||
* - item 1 | ||
* - item 2 | ||
* - item 3 | ||
* Configuration (TypeScript type). | ||
* | ||
* A loose list: | ||
* ###### Fields | ||
* | ||
* - Wrapped | ||
* item | ||
* * `checkBlanks` (`boolean`, default: `false`) | ||
* — expect blank lines between items based on whether an item has blank | ||
* lines *in* them; | ||
* the default is to expect blank lines based on whether items span multiple | ||
* lines | ||
* | ||
* - item 2 | ||
* ## Recommendation | ||
* | ||
* - item 3 | ||
* First some background. | ||
* Regardless of ordered and unordered, | ||
* there are two kinds of lists in markdown, | ||
* tight and loose. | ||
* Lists are tight by default but if there is a blank line between two list | ||
* items or between two blocks inside an item, | ||
* that turns the whole list into a loose list. | ||
* When turning markdown into HTML, | ||
* paragraphs in tight lists are not wrapped in `<p>` tags. | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "input"} | ||
* This rule defaults to the [`markdown-style-guide`][markdown-style-guide] | ||
* preference for which lists should be loose or not: | ||
* loose when at least one item spans more than one line and tight otherwise. | ||
* With `{checkBlanks: true}`, | ||
* this rule follows whether a list is loose or not according to Commonmark, | ||
* and when one item is loose, | ||
* all items must be loose. | ||
* | ||
* A tight list: | ||
* [api-options]: #options | ||
* [api-remark-lint-list-item-spacing]: #unifieduseremarklintlistitemspacing-options | ||
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
* [markdown-style-guide]: https://cirosantilli.com/markdown-style-guide/ | ||
* | ||
* - Wrapped | ||
* item | ||
* - item 2 | ||
* - item 3 | ||
* @module list-item-spacing | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* | ||
* A loose list: | ||
* @example | ||
* {"name": "ok.md"} | ||
* | ||
* - item 1 | ||
* * Mercury. | ||
* * Venus. | ||
* | ||
* - item 2 | ||
* + Mercury and | ||
* Venus. | ||
* | ||
* - item 3 | ||
* + Earth. | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "output"} | ||
* {"config": {"checkBlanks": true}, "name": "ok-check-blanks.md"} | ||
* | ||
* 4:9-5:1: Missing new line after list item | ||
* 5:11-6:1: Missing new line after list item | ||
* 10:11-12:1: Extraneous new line after list item | ||
* 12:11-14:1: Extraneous new line after list item | ||
* * Mercury. | ||
* * Venus. | ||
* | ||
* @example | ||
* {"name": "ok.md", "config": {"checkBlanks": true}} | ||
* + Mercury | ||
* | ||
* A tight list: | ||
* Mercury is the first planet from the Sun and the smallest in the Solar | ||
* System. | ||
* | ||
* - item 1 | ||
* - item 1.A | ||
* - item 2 | ||
* > Block quote | ||
* + Earth. | ||
* | ||
* A loose list: | ||
* @example | ||
* {"label": "input", "name": "not-ok.md"} | ||
* | ||
* - item 1 | ||
* * Mercury. | ||
* | ||
* - item 1.A | ||
* * Venus. | ||
* | ||
* - item 2 | ||
* + Mercury and | ||
* Venus. | ||
* + Earth. | ||
* | ||
* > Block quote | ||
* * Mercury. | ||
* | ||
* Mercury is the first planet from the Sun and the smallest in the Solar | ||
* System. | ||
* * Earth. | ||
* @example | ||
* {"name": "not-ok.md", "config": {"checkBlanks": true}, "label": "input"} | ||
* {"label": "output", "name": "not-ok.md"} | ||
* | ||
* A tight list: | ||
* 1:11-3:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
* 6:11-7:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
* 12:12-13:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
* | ||
* - item 1 | ||
* @example | ||
* {"config": {"checkBlanks": true}, "label": "input", "name": "not-ok-blank.md"} | ||
* | ||
* - item 1.A | ||
* - item 2 | ||
* * Mercury. | ||
* | ||
* > Block quote | ||
* - item 3 | ||
* * Venus. | ||
* | ||
* A loose list: | ||
* + Mercury and | ||
* Venus. | ||
* | ||
* - item 1 | ||
* - item 1.A | ||
* + Earth. | ||
* | ||
* - item 2 | ||
* > Block quote | ||
* * Mercury. | ||
* | ||
* Mercury is the first planet from the Sun and the smallest in the Solar | ||
* System. | ||
* * Earth. | ||
* @example | ||
* {"name": "not-ok.md", "config": {"checkBlanks": true}, "label": "output"} | ||
* {"config": {"checkBlanks": true}, "label": "output", "name": "not-ok-blank.md"} | ||
* | ||
* 5:15-6:1: Missing new line after list item | ||
* 8:18-9:1: Missing new line after list item | ||
* 14:15-16:1: Extraneous new line after list item | ||
* 1:11-3:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
* 6:11-8:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
* 13:12-14:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
*/ | ||
/** | ||
* @typedef {import('mdast').ListItem} ListItem | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').ListItem} ListItem | ||
* | ||
*/ | ||
/** | ||
* @typedef Options | ||
* Options. | ||
* Configuration. | ||
* @property {boolean | null | undefined} [checkBlanks=false] | ||
* Adhere to CommonMark looseness instead of markdown-style-guide preference. | ||
* Whether to follow CommonMark looseness instead of `markdown-style-guide` | ||
* preference (default: `false`). | ||
*/ | ||
import {phrasing} from 'mdast-util-phrasing' | ||
import pluralize from 'pluralize' | ||
import {lintRule} from 'unified-lint-rule' | ||
import {visit} from 'unist-util-visit' | ||
import {pointStart, pointEnd} from 'unist-util-position' | ||
import {generated} from 'unist-util-generated' | ||
import {pointEnd, pointStart} from 'unist-util-position' | ||
import {SKIP, visitParents} from 'unist-util-visit-parents' | ||
import {VFileMessage} from 'vfile-message' | ||
/** @type {Readonly<Options>} */ | ||
const emptyOptions = {} | ||
const remarkLintListItemSpacing = lintRule( | ||
@@ -154,34 +169,92 @@ { | ||
}, | ||
/** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
(tree, file, option = {}) => { | ||
const {checkBlanks} = option | ||
const infer = checkBlanks ? inferBlankLine : inferMultiline | ||
/** | ||
* @param {Root} tree | ||
* Tree. | ||
* @param {Readonly<Options> | null | undefined} [options] | ||
* Configuration (optional). | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function (tree, file, options) { | ||
const settings = options || emptyOptions | ||
// To do: change options. Maybe to `Style = 'markdown' | 'markdown-style-guide'`? | ||
const checkBlanks = settings.checkBlanks || false | ||
visit(tree, 'list', (node) => { | ||
if (!generated(node)) { | ||
let tight = true | ||
let index = -1 | ||
visitParents(tree, function (list, parents) { | ||
// Do not walk into phrasing. | ||
if (phrasing(list)) { | ||
return SKIP | ||
} | ||
while (++index < node.children.length) { | ||
if (infer(node.children[index])) { | ||
tight = false | ||
break | ||
} | ||
if (list.type !== 'list') return | ||
/** @type {VFileMessage | undefined} */ | ||
let spacedCause | ||
for (const item of list.children) { | ||
/** @type {boolean | null | undefined} */ | ||
let spaced = false | ||
if (checkBlanks) { | ||
spaced = item.spread | ||
} else { | ||
const tail = item.children.at(-1) | ||
const end = pointEnd(tail) | ||
const start = pointStart(item) | ||
spaced = end && start && end.line - start.line > 0 | ||
} | ||
index = 0 // Skip over first. | ||
if (spaced) { | ||
spacedCause = new VFileMessage( | ||
'Spaced list item first defined here', | ||
{ | ||
ancestors: [...parents, list, item], | ||
place: item.position, | ||
ruleId: 'list-item-spacing', | ||
source: 'remark-lint' | ||
} | ||
) | ||
break | ||
} | ||
} | ||
while (++index < node.children.length) { | ||
const child = node.children[index - 1] | ||
const next = node.children[index] | ||
const expected = spacedCause ? 1 : 0 | ||
/** @type {ListItem | undefined} */ | ||
let previous | ||
if (pointStart(next).line - pointEnd(child).line < 2 !== tight) { | ||
for (const item of list.children) { | ||
const previousEnd = pointEnd(previous) | ||
const itemStart = pointStart(item) | ||
if (previousEnd && itemStart) { | ||
const actual = itemStart.line - previousEnd.line - 1 | ||
if (actual !== expected) { | ||
const difference = expected - actual | ||
const differenceAbsolute = Math.abs(difference) | ||
file.message( | ||
tight | ||
? 'Extraneous new line after list item' | ||
: 'Missing new line after list item', | ||
{start: pointEnd(child), end: pointStart(next)} | ||
'Unexpected `' + | ||
actual + | ||
'` blank ' + | ||
pluralize('line', actual) + | ||
' between list items, expected `' + | ||
expected + | ||
'` blank ' + | ||
pluralize('line', expected) + | ||
', ' + | ||
(difference > 0 ? 'add' : 'remove') + | ||
' `' + | ||
differenceAbsolute + | ||
'` blank ' + | ||
pluralize('line', differenceAbsolute), | ||
{ | ||
ancestors: [...parents, list, item], | ||
cause: spacedCause, | ||
place: {start: previousEnd, end: itemStart} | ||
} | ||
) | ||
} | ||
} | ||
previous = item | ||
} | ||
@@ -193,33 +266,1 @@ }) | ||
export default remarkLintListItemSpacing | ||
/** | ||
* @param {ListItem} node | ||
* @returns {boolean} | ||
*/ | ||
function inferBlankLine(node) { | ||
let index = 0 | ||
while (++index < node.children.length) { | ||
const child = node.children[index - 1] | ||
const next = node.children[index] | ||
// All children in `listItem`s are block. | ||
if (pointStart(next).line - pointEnd(child).line > 1) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
/** | ||
* @param {ListItem} node | ||
* @returns {boolean} | ||
*/ | ||
function inferMultiline(node) { | ||
return ( | ||
pointEnd(node.children[node.children.length - 1]).line - | ||
pointStart(node.children[0]).line > | ||
0 | ||
) | ||
} |
{ | ||
"name": "remark-lint-list-item-spacing", | ||
"version": "4.1.2", | ||
"version": "5.0.0", | ||
"description": "remark-lint rule to warn when list looseness is incorrect", | ||
"license": "MIT", | ||
"keywords": [ | ||
"remark", | ||
"item", | ||
"lint", | ||
"rule", | ||
"remark-lint-rule", | ||
"list", | ||
"item", | ||
"loose", | ||
"remark", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule", | ||
"tight" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/remarkjs/remark-lint", | ||
"directory": "packages/remark-lint-list-item-spacing" | ||
}, | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-spacing", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
@@ -28,28 +25,35 @@ "funding": { | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com>" | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.d.ts", | ||
"index.d.ts.map", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"unified": "^10.0.0", | ||
"unified-lint-rule": "^2.0.0", | ||
"unist-util-generated": "^2.0.0", | ||
"unist-util-position": "^4.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"@types/mdast": "^4.0.0", | ||
"mdast-util-phrasing": "^4.0.0", | ||
"pluralize": "^8.0.0", | ||
"unified-lint-rule": "^3.0.0", | ||
"unist-util-position": "^5.0.0", | ||
"unist-util-visit-parents": "^6.0.0", | ||
"vfile-message": "^4.0.0" | ||
}, | ||
"scripts": {}, | ||
"xo": false, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"capitalized-comments": "off", | ||
"unicorn/prefer-at": "off" | ||
} | ||
} | ||
} |
333
readme.md
@@ -5,44 +5,41 @@ <!--This file is generated--> | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
[![Sponsors][sponsors-badge]][collective] | ||
[![Backers][backers-badge]][collective] | ||
[![Chat][chat-badge]][chat] | ||
[![Build][badge-build-image]][badge-build-url] | ||
[![Coverage][badge-coverage-image]][badge-coverage-url] | ||
[![Downloads][badge-downloads-image]][badge-downloads-url] | ||
[![Size][badge-size-image]][badge-size-url] | ||
[![Sponsors][badge-funding-sponsors-image]][badge-funding-url] | ||
[![Backers][badge-funding-backers-image]][badge-funding-url] | ||
[![Chat][badge-chat-image]][badge-chat-url] | ||
[`remark-lint`][mono] rule to warn when lists are loose when they should be tight, | ||
or vice versa. | ||
[`remark-lint`][github-remark-lint] rule to warn when lists violate a given style. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Presets](#presets) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`unified().use(remarkLintListItemSpacing[, config])`](#unifieduseremarklintlistitemspacing-config) | ||
* [Recommendation](#recommendation) | ||
* [Examples](#examples) | ||
* [Compatibility](#compatibility) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Presets](#presets) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`unified().use(remarkLintListItemSpacing[, options])`](#unifieduseremarklintlistitemspacing-options) | ||
* [`Options`](#options) | ||
* [Recommendation](#recommendation) | ||
* [Examples](#examples) | ||
* [Compatibility](#compatibility) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint` | ||
rule. | ||
Lint rules check markdown code style. | ||
This package checks blank lines between list items. | ||
## When should I use this? | ||
You can use this package to check that lists are loose or tight when | ||
they should be. | ||
You can use this package to check the style of lists. | ||
## Presets | ||
This rule is included in the following presets: | ||
This plugin is included in the following presets: | ||
| Preset | Setting | | ||
| Preset | Options | | ||
| - | - | | ||
@@ -53,4 +50,5 @@ | [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | | | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
This package is [ESM only][github-gist-esm]. | ||
In Node.js (version 16+), | ||
install with [npm][npm-install]: | ||
@@ -61,13 +59,13 @@ ```sh | ||
In Deno with [`esm.sh`][esmsh]: | ||
In Deno with [`esm.sh`][esm-sh]: | ||
```js | ||
import remarkLintListItemSpacing from 'https://esm.sh/remark-lint-list-item-spacing@4' | ||
import remarkLintListItemSpacing from 'https://esm.sh/remark-lint-list-item-spacing@5' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
In browsers with [`esm.sh`][esm-sh]: | ||
```html | ||
<script type="module"> | ||
import remarkLintListItemSpacing from 'https://esm.sh/remark-lint-list-item-spacing@4?bundle' | ||
import remarkLintListItemSpacing from 'https://esm.sh/remark-lint-list-item-spacing@5?bundle' | ||
</script> | ||
@@ -81,18 +79,20 @@ ``` | ||
```js | ||
import remarkLint from 'remark-lint' | ||
import remarkLintListItemSpacing from 'remark-lint-list-item-spacing' | ||
import remarkParse from 'remark-parse' | ||
import remarkStringify from 'remark-stringify' | ||
import {read} from 'to-vfile' | ||
import {unified} from 'unified' | ||
import {reporter} from 'vfile-reporter' | ||
import {remark} from 'remark' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintListItemSpacing from 'remark-lint-list-item-spacing' | ||
main() | ||
const file = await read('example.md') | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintListItemSpacing) | ||
.process(await read('example.md')) | ||
await unified() | ||
.use(remarkParse) | ||
.use(remarkLint) | ||
.use(remarkLintListItemSpacing) | ||
.use(remarkStringify) | ||
.process(file) | ||
console.error(reporter(file)) | ||
} | ||
console.error(reporter(file)) | ||
``` | ||
@@ -103,3 +103,3 @@ | ||
```sh | ||
remark --use remark-lint --use remark-lint-list-item-spacing example.md | ||
remark --frail --use remark-lint --use remark-lint-list-item-spacing . | ||
``` | ||
@@ -125,33 +125,51 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintListItemSpacing`. | ||
It exports the [TypeScript][typescript] type | ||
[`Options`][api-options]. | ||
The default export is | ||
[`remarkLintListItemSpacing`][api-remark-lint-list-item-spacing]. | ||
### `unified().use(remarkLintListItemSpacing[, config])` | ||
### `unified().use(remarkLintListItemSpacing[, options])` | ||
This rule supports standard configuration that all remark lint rules accept | ||
(such as `false` to turn it off or `[1, options]` to configure it). | ||
Warn when lists violate a given style. | ||
The following options (default: `undefined`) are accepted: | ||
###### Parameters | ||
* `Object` with the following fields: | ||
* `checkBlanks` (`boolean`, default: `false`) | ||
— adhere to CommonMark looseness instead of markdown-style-guide | ||
preference | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
###### Returns | ||
Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Fields | ||
* `checkBlanks` (`boolean`, default: `false`) | ||
— expect blank lines between items based on whether an item has blank | ||
lines *in* them; | ||
the default is to expect blank lines based on whether items span multiple | ||
lines | ||
## Recommendation | ||
First, some background. | ||
There are two types of lists in markdown (other than ordered and unordered): | ||
tight and loose lists. | ||
First some background. | ||
Regardless of ordered and unordered, | ||
there are two kinds of lists in markdown, | ||
tight and loose. | ||
Lists are tight by default but if there is a blank line between two list | ||
items or between two blocks inside an item, that turns the whole list into a | ||
loose list. | ||
When turning markdown into HTML, paragraphs in tight lists are not wrapped | ||
in `<p>` tags. | ||
items or between two blocks inside an item, | ||
that turns the whole list into a loose list. | ||
When turning markdown into HTML, | ||
paragraphs in tight lists are not wrapped in `<p>` tags. | ||
This rule defaults to the | ||
[`markdown style guide`](https://cirosantilli.com/markdown-style-guide/) | ||
preference for which lists should be loose or not: loose when at least one | ||
item spans more than one line, tight otherwise. | ||
With `{checkBlanks: true}`, this rule dictates that when at least one item is | ||
loose, all items must be loose. | ||
This rule defaults to the [`markdown-style-guide`][markdown-style-guide] | ||
preference for which lists should be loose or not: | ||
loose when at least one item spans more than one line and tight otherwise. | ||
With `{checkBlanks: true}`, | ||
this rule follows whether a list is loose or not according to Commonmark, | ||
and when one item is loose, | ||
all items must be loose. | ||
@@ -165,16 +183,9 @@ ## Examples | ||
```markdown | ||
A tight list: | ||
* Mercury. | ||
* Venus. | ||
- item 1 | ||
- item 2 | ||
- item 3 | ||
+ Mercury and | ||
Venus. | ||
A loose list: | ||
- Wrapped | ||
item | ||
- item 2 | ||
- item 3 | ||
+ Earth. | ||
``` | ||
@@ -186,21 +197,18 @@ | ||
##### `not-ok.md` | ||
##### `ok-check-blanks.md` | ||
When configured with `{ checkBlanks: true }`. | ||
###### In | ||
```markdown | ||
A tight list: | ||
* Mercury. | ||
* Venus. | ||
- Wrapped | ||
item | ||
- item 2 | ||
- item 3 | ||
+ Mercury | ||
A loose list: | ||
Mercury is the first planet from the Sun and the smallest in the Solar | ||
System. | ||
- item 1 | ||
- item 2 | ||
- item 3 | ||
+ Earth. | ||
``` | ||
@@ -210,32 +218,22 @@ | ||
```text | ||
4:9-5:1: Missing new line after list item | ||
5:11-6:1: Missing new line after list item | ||
10:11-12:1: Extraneous new line after list item | ||
12:11-14:1: Extraneous new line after list item | ||
``` | ||
No messages. | ||
##### `ok.md` | ||
##### `not-ok.md` | ||
When configured with `{ checkBlanks: true }`. | ||
###### In | ||
```markdown | ||
A tight list: | ||
* Mercury. | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Block quote | ||
* Venus. | ||
A loose list: | ||
+ Mercury and | ||
Venus. | ||
+ Earth. | ||
- item 1 | ||
* Mercury. | ||
- item 1.A | ||
- item 2 | ||
> Block quote | ||
Mercury is the first planet from the Sun and the smallest in the Solar | ||
System. | ||
* Earth. | ||
``` | ||
@@ -245,5 +243,9 @@ | ||
No messages. | ||
```text | ||
1:11-3:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
6:11-7:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
12:12-13:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
``` | ||
##### `not-ok.md` | ||
##### `not-ok-blank.md` | ||
@@ -255,19 +257,16 @@ When configured with `{ checkBlanks: true }`. | ||
```markdown | ||
A tight list: | ||
* Mercury. | ||
- item 1 | ||
* Venus. | ||
- item 1.A | ||
- item 2 | ||
+ Mercury and | ||
Venus. | ||
> Block quote | ||
- item 3 | ||
+ Earth. | ||
A loose list: | ||
* Mercury. | ||
- item 1 | ||
- item 1.A | ||
- item 2 | ||
> Block quote | ||
Mercury is the first planet from the Sun and the smallest in the Solar | ||
System. | ||
* Earth. | ||
``` | ||
@@ -278,5 +277,5 @@ | ||
```text | ||
5:15-6:1: Missing new line after list item | ||
8:18-9:1: Missing new line after list item | ||
14:15-16:1: Extraneous new line after list item | ||
1:11-3:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
6:11-8:1: Unexpected `1` blank line between list items, expected `0` blank lines, remove `1` blank line | ||
13:12-14:1: Unexpected `0` blank lines between list items, expected `1` blank line, add `1` blank line | ||
``` | ||
@@ -286,14 +285,18 @@ | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
When we cut a new major release, we drop support for unmaintained versions of | ||
Node. | ||
This means we try to keep the current release line, | ||
`remark-lint-list-item-spacing@5`, | ||
compatible with Node.js 16. | ||
## Contribute | ||
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways | ||
See [`contributing.md`][github-dotfiles-contributing] in [`remarkjs/.github`][github-dotfiles-health] for ways | ||
to get started. | ||
See [`support.md`][support] for ways to get help. | ||
See [`support.md`][github-dotfiles-support] for ways to get help. | ||
This project has a [code of conduct][coc]. | ||
This project has a [code of conduct][github-dotfiles-coc]. | ||
By interacting with this repository, organization, or community you agree to | ||
@@ -304,52 +307,58 @@ abide by its terms. | ||
[MIT][license] © [Titus Wormer][author] | ||
[MIT][file-license] © [Titus Wormer][author] | ||
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
[api-options]: #options | ||
[build]: https://github.com/remarkjs/remark-lint/actions | ||
[api-remark-lint-list-item-spacing]: #unifieduseremarklintlistitemspacing-options | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[author]: https://wooorm.com | ||
[coverage]: https://codecov.io/github/remarkjs/remark-lint | ||
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-list-item-spacing.svg | ||
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions | ||
[downloads]: https://www.npmjs.com/package/remark-lint-list-item-spacing | ||
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-list-item-spacing.svg | ||
[badge-chat-url]: https://github.com/remarkjs/remark/discussions | ||
[size]: https://bundlephobia.com/result?p=remark-lint-list-item-spacing | ||
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-list-item-spacing.svg | ||
[collective]: https://opencollective.com/unified | ||
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-list-item-spacing | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg | ||
[unified]: https://github.com/unifiedjs/unified | ||
[badge-funding-url]: https://opencollective.com/unified | ||
[remark]: https://github.com/remarkjs/remark | ||
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-list-item-spacing | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[badge-size-url]: https://bundlejs.com/?q=remark-lint-list-item-spacing | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[esm-sh]: https://esm.sh | ||
[esmsh]: https://esm.sh | ||
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[health]: https://github.com/remarkjs/.github | ||
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[github-dotfiles-health]: https://github.com/remarkjs/.github | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[github-remark-lint]: https://github.com/remarkjs/remark-lint | ||
[author]: https://wooorm.com | ||
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
[markdown-style-guide]: https://cirosantilli.com/markdown-style-guide/ | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[typescript]: https://www.typescriptlang.org |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
18570
5
265
351
7
1
1
+ Addedmdast-util-phrasing@^4.0.0
+ Addedpluralize@^8.0.0
+ Addedvfile-message@^4.0.0
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddequal@2.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedpluralize@8.0.0(transitive)
+ Addedunified@11.0.5(transitive)
+ Addedunified-lint-rule@3.0.0(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-position@5.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
+ Addedvfile@6.0.3(transitive)
+ Addedvfile-message@4.0.2(transitive)
- Removedunified@^10.0.0
- Removedunist-util-generated@^2.0.0
- Removedunist-util-visit@^4.0.0
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedunified@10.1.2(transitive)
- Removedunified-lint-rule@2.1.2(transitive)
- Removedunist-util-generated@2.0.1(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-position@4.0.4(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
- Removedvfile@5.3.7(transitive)
- Removedvfile-message@3.1.4(transitive)
Updated@types/mdast@^4.0.0
Updatedunified-lint-rule@^3.0.0
Updatedunist-util-position@^5.0.0