Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-list-item-indent

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-list-item-indent - npm Package Compare versions

Comparing version 3.1.2 to 4.0.0

index.d.ts.map

30

index.d.ts

@@ -1,23 +0,11 @@

export default remarkLintListItemIndent
export type Root = import('mdast').Root
export default remarkLintListItemIndent;
export type Root = import('mdast').Root;
/**
* Options.
* Configuration.
*/
export type Options = 'tab-size' | 'space' | 'mixed'
declare const remarkLintListItemIndent: 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
>
export type Options = 'mixed' | 'one' | 'tab';
declare const remarkLintListItemIndent: {
(config?: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity | Options | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: 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
/**
* remark-lint rule to warn when the whitespace after list item markers violate
* a given style.
*
* ## What is this?
*
* This package checks the style of whitespace after list item markers.
*
* ## When should I use this?
*
* You can use this package to check that the spacing between list item markers
* and content is inconsistent.
* You can use this package to check that the style of whitespace after list
* item markers and before content is consistent.
*
* ## API
*
* The following options (default: `'tab-size'`) are accepted:
* ### `unified().use(remarkLintListItemIndent[, options])`
*
* * `'space'`
* — prefer a single space
* * `'tab-size'`
* — prefer spaces the size of the next tab stop
* * `'mixed'`
* — prefer `'space'` for tight lists and `'tab-size'` for loose lists
* Warn when the whitespace after list item markers violate a given style.
*
* ###### Parameters
*
* * `options` ([`Options`][api-options], default: `'one'`)
* — preferred style
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ### `Options`
*
* Configuration (TypeScript type).
*
* * `'mixed'`
* — prefer `'one'` for tight lists and `'tab'` for loose lists
* * `'one'`
* — prefer the size of the bullet and a single space
* * `'tab'`
* — prefer the size of the bullet and a single space to the next tab stop
*
* ###### Type
*
* ```ts
* type Options = 'mixed' | 'one' | 'tab'
* ```
*
* ## Recommendation
*
* First, some background.
* First some background.
* The number of spaces that occur after list markers (`*`, `-`, and `+` for
* unordered lists, or `.` and `)` for unordered lists) and before the content
* on the first line, defines how much indentation can be used for further
* lines.
* At least one space is required and up to 4 spaces are allowed (if there is no
* further content after the marker then it’s a blank line which is handled as
* if there was one space; if there are 5 or more spaces and then content, it’s
* also seen as one space and the rest is seen as indented code).
* unordered lists and `.` and `)` for unordered lists) and before the content
* on the first line,
* defines how much indentation can be used for further lines.
* At least one space is required and up to 4 spaces are allowed.
* If there is no further content after the marker then it’s a blank line which
* is handled as if there was one space.
* If there are 5 or more spaces and then content then it’s also seen as one
* space and the rest is seen as indented code.
*
* There are two types of lists in markdown (other than ordered and unordered):
* tight and loose lists.
* 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.
*
* Historically, how indentation of lists works in markdown has been a mess,
* How indentation of lists works in markdown has historically been a mess,
* especially with how they interact with indented code.
* CommonMark made that a *lot* better, but there remain (documented but
* complex) edge cases and some behavior intuitive.
* Due to this, the default of this list is `'tab-size'`, which worked the best
* in most markdown parsers.
* Currently, the situation between markdown parsers is better, so choosing
* `'space'` (which seems to be the most common style used by authors) should
* be okay.
* CommonMark made that a *lot* better,
* but there remain (documented but complex) edge cases and some behavior
* intuitive.
* Due to this, `'tab'` works the best in most markdown parsers *and* in
* CommonMark.
* Currently the situation between markdown parsers is better,
* so the default `'one'`,
* which seems to be the most common style used by authors,
* is okay.
*
* ## Fix
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
* uses `'tab-size'` (named `'tab'` there) by default.
* [`listItemIndent: '1'` (for `'space'`) or `listItemIndent: 'mixed'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent)
* is supported.
* [`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'`
* by default.
* `listItemIndent: 'mixed'` or `listItemIndent: 'tab'` is also supported.
*
* [api-options]: #options
* [api-remark-lint-list-item-indent]: #unifieduseremarklintlistitemindent-options
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module list-item-indent
* @summary
* remark-lint rule to warn when spacing between list item markers and
* content is inconsistent.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md"}
*
* *···List
* ····item.
* *␠Mercury.
* *␠Venus.
*
* Paragraph.
* 111.␠Earth
* ␠␠␠␠␠and Mars.
*
* 11.·List
* ····item.
* *␠**Jupiter**.
*
* Paragraph.
* ␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠System.
*
* *···List
* ····item.
* *␠Saturn.
*
* *···List
* ····item.
* ␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
*
* @example
* {"name": "ok.md", "config": "mixed"}
* {"config": "mixed", "name": "ok.md"}
*
* *·List item.
* *␠Mercury.
* *␠Venus.
*
* Paragraph.
* 111.␠Earth
* ␠␠␠␠␠and Mars.
*
* 11.·List item
* *␠␠␠**Jupiter**.
*
* Paragraph.
* ␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠␠␠System.
*
* *···List
* ····item.
* *␠␠␠Saturn.
*
* *···List
* ····item.
* ␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
*
* @example
* {"name": "ok.md", "config": "space"}
* {"config": "mixed", "label": "input", "name": "not-ok.md"}
*
* *·List item.
* *␠␠␠Mercury.
* *␠␠␠Venus.
*
* Paragraph.
* 111.␠␠␠␠Earth
* ␠␠␠␠␠␠␠␠and Mars.
*
* 11.·List item
* *␠**Jupiter**.
*
* Paragraph.
* ␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠System.
*
* *·List
* ··item.
* *␠Saturn.
*
* *·List
* ··item.
* ␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
* @example
* {"config": "mixed", "label": "output", "name": "not-ok.md"}
*
* 1:5: Unexpected `3` spaces between list item marker and content in tight list, expected `1` space, remove `2` spaces
* 2:5: Unexpected `3` spaces between list item marker and content in tight list, expected `1` space, remove `2` spaces
* 4:9: Unexpected `4` spaces between list item marker and content in tight list, expected `1` space, remove `3` spaces
* 7:3: Unexpected `1` space between list item marker and content in loose list, expected `3` spaces, add `2` spaces
* 12:3: Unexpected `1` space between list item marker and content in loose list, expected `3` spaces, add `2` spaces
*
* @example
* {"name": "not-ok.md", "config": "space", "label": "input"}
* {"config": "one", "name": "ok.md"}
*
* *···List
* ····item.
* *␠Mercury.
* *␠Venus.
*
* 111.␠Earth
* ␠␠␠␠␠and Mars.
*
* *␠**Jupiter**.
*
* ␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠System.
*
* *␠Saturn.
*
* ␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
*
* @example
* {"name": "not-ok.md", "config": "space", "label": "output"}
* {"config": "one", "label": "input", "name": "not-ok.md"}
*
* 1:5: Incorrect list-item indent: remove 2 spaces
* *␠␠␠Mercury.
* *␠␠␠Venus.
*
* 111.␠␠␠␠Earth
* ␠␠␠␠␠␠␠␠and Mars.
*
* *␠␠␠**Jupiter**.
*
* ␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠␠␠System.
*
* *␠␠␠Saturn.
*
* ␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
* @example
* {"name": "not-ok.md", "config": "tab-size", "label": "input"}
* {"config": "one", "label": "output", "name": "not-ok.md"}
*
* *·List
* ··item.
* 1:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
* 2:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
* 4:9: Unexpected `4` spaces between list item marker and content, expected `1` space, remove `3` spaces
* 7:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
* 12:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
*
* @example
* {"name": "not-ok.md", "config": "tab-size", "label": "output"}
* {"config": "tab", "name": "ok.md"}
*
* 1:3: Incorrect list-item indent: add 2 spaces
* *␠␠␠Mercury.
* *␠␠␠Venus.
*
* 111.␠␠␠␠Earth
* ␠␠␠␠␠␠␠␠and Mars.
*
* *␠␠␠**Jupiter**.
*
* ␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠␠␠System.
*
* *␠␠␠Saturn.
*
* ␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
*
* @example
* {"name": "not-ok.md", "config": "mixed", "label": "input"}
* {"config": "tab", "label": "input", "name": "not-ok.md"}
*
* *···List item.
* *␠Mercury.
* *␠Venus.
*
* 111.␠Earth
* ␠␠␠␠␠and Mars.
*
* *␠**Jupiter**.
*
* ␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
* ␠␠System.
*
* *␠Saturn.
*
* ␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
* @example
* {"name": "not-ok.md", "config": "mixed", "label": "output"}
* {"config": "tab", "label": "output", "name": "not-ok.md"}
*
* 1:5: Incorrect list-item indent: remove 2 spaces
* 1:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
* 2:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
* 4:6: Unexpected `1` space between list item marker and content, expected `4` spaces, add `3` spaces
* 7:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
* 12:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
*
* @example
* {"name": "not-ok.md", "config": "💩", "label": "output", "positionless": true}
* {"config": "🌍", "label": "output", "name": "not-ok.md", "positionless": true}
*
* 1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'`
* 1:1: Unexpected value `🌍` for `options`, expected `'mixed'`, `'one'`, or `'tab'`
*
* @example
* {"config": "mixed", "gfm": true, "label": "input", "name": "gfm.md"}
*
* *␠[x] Mercury.
*
* 1.␠␠[ ] Venus.
*
* 2.␠␠[ ] Earth.
*
* @example
* {"config": "one", "gfm": true, "name": "gfm.md"}
*
* *␠[x] Mercury.
*
* 1.␠[ ] Venus.
*
* 2.␠[ ] Earth.
*
* @example
* {"config": "tab", "gfm": true, "name": "gfm.md"}
*
* *␠␠␠[x] Mercury.
*
* 1.␠␠[ ] Venus.
*
* 2.␠␠[ ] Earth.
*
* @example
* {"config": "mixed", "name": "loose-tight.md"}
*
* Loose lists have blank lines between items:
*
* *␠␠␠Mercury.
*
* *␠␠␠Venus.
*
* …or between children of items:
*
* 1.␠␠Earth.
*
* ␠␠␠␠Earth is the third planet from the Sun and the only astronomical
* ␠␠␠␠object known to harbor life.
*/

@@ -158,11 +300,11 @@

/**
* @typedef {'tab-size' | 'space' | 'mixed'} Options
* Options.
* @typedef {'mixed' | 'one' | 'tab'} Options
* Configuration.
*/
import {phrasing} from 'mdast-util-phrasing'
import pluralize from 'pluralize'
import {lintRule} from 'unified-lint-rule'
import plural from 'pluralize'
import {visit} from 'unist-util-visit'
import {pointStart} from 'unist-util-position'
import {generated} from 'unist-util-generated'
import {SKIP, visitParents} from 'unist-util-visit-parents'

@@ -174,49 +316,121 @@ const remarkLintListItemIndent = lintRule(

},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'tab-size') => {
/**
* @param {Root} tree
* Tree.
* @param {Options | null | undefined} [options='one']
* Configuration (default: `'one'`).
* @returns {undefined}
* Nothing.
*/
function (tree, file, options) {
const value = String(file)
/** @type {Options} */
let expected
if (option !== 'tab-size' && option !== 'space' && option !== 'mixed') {
if (options === null || options === undefined) {
expected = 'one'
/* c8 ignore next 10 -- previous names. */
// @ts-expect-error: old name.
} else if (options === 'space') {
file.fail(
'Incorrect list-item indent style `' +
option +
"`: use either `'tab-size'`, `'space'`, or `'mixed'`"
'Unexpected value `' + options + "` for `options`, expected `'one'`"
)
// @ts-expect-error: old name.
} else if (options === 'tab-size') {
file.fail(
'Unexpected value `' + options + "` for `options`, expected `'tab'`"
)
} else if (options === 'mixed' || options === 'one' || options === 'tab') {
expected = options
} else {
file.fail(
'Unexpected value `' +
options +
"` for `options`, expected `'mixed'`, `'one'`, or `'tab'`"
)
}
visit(tree, 'list', (node) => {
if (generated(node)) return
visitParents(tree, function (node, parents) {
// Do not walk into phrasing.
if (phrasing(node)) {
return SKIP
}
const spread = node.spread
let index = -1
if (node.type !== 'list') return
while (++index < node.children.length) {
const item = node.children[index]
const head = item.children[0]
const final = pointStart(head)
let loose = node.spread
const marker = value
.slice(pointStart(item).offset, final.offset)
.replace(/\[[x ]?]\s*$/i, '')
if (!loose) {
for (const child of node.children) {
if (child.spread) {
loose = true
break
}
}
}
const bulletSize = marker.replace(/\s+$/, '').length
for (const child of node.children) {
const head = child.children[0]
const itemStart = pointStart(child)
const headStart = pointStart(head)
const style =
option === 'tab-size' || (option === 'mixed' && spread)
? Math.ceil(bulletSize / 4) * 4
: bulletSize + 1
if (
itemStart &&
headStart &&
typeof itemStart.offset === 'number' &&
typeof headStart.offset === 'number'
) {
let slice = value.slice(itemStart.offset, headStart.offset)
if (marker.length !== style) {
const diff = style - marker.length
const abs = Math.abs(diff)
// GFM tasklist.
const checkboxIndex = slice.indexOf('[')
if (checkboxIndex !== -1) slice = slice.slice(0, checkboxIndex)
file.message(
'Incorrect list-item indent: ' +
(diff > 0 ? 'add' : 'remove') +
' ' +
abs +
' ' +
plural('space', abs),
final
)
const actualIndent = slice.length
// To do: actual hard tabs?
// Remove whitespace.
let end = actualIndent
let previous = slice.charCodeAt(end - 1)
while (previous === 9 || previous === 32) {
end--
previous = slice.charCodeAt(end - 1)
}
let expectedIndent = end + 1 // One space needed after marker.
if (expected === 'tab' || (expected === 'mixed' && loose)) {
expectedIndent = Math.ceil(expectedIndent / 4) * 4
}
const expectedSpaces = expectedIndent - end
const actualSpaces = actualIndent - end
if (actualSpaces !== expectedSpaces) {
const difference = expectedSpaces - actualSpaces
const differenceAbsolute = Math.abs(difference)
file.message(
'Unexpected `' +
actualSpaces +
'` ' +
pluralize('space', actualSpaces) +
' between list item marker and content' +
(expected === 'mixed'
? ' in ' + (loose ? 'loose' : 'tight') + ' list'
: '') +
', expected `' +
expectedSpaces +
'` ' +
pluralize('space', expectedSpaces) +
', ' +
(difference > 0 ? 'add' : 'remove') +
' `' +
differenceAbsolute +
'` ' +
pluralize('space', differenceAbsolute),
{ancestors: [...parents, node, child], place: headStart}
)
}
}

@@ -223,0 +437,0 @@ }

{
"name": "remark-lint-list-item-indent",
"version": "3.1.2",
"version": "4.0.0",
"description": "remark-lint rule to warn when the spacing between a list item’s bullet and its content violates a given style",
"license": "MIT",
"keywords": [
"indent",
"item",
"lint",
"list",
"remark",
"lint",
"rule",
"remark-lint",
"remark-lint-rule",
"list",
"item",
"indent"
"rule"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-list-item-indent"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-indent",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -27,29 +24,36 @@ "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",
"@types/mdast": "^4.0.0",
"mdast-util-phrasing": "^4.0.0",
"pluralize": "^8.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"
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.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",
"complexity": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off"
}
}
}

@@ -5,53 +5,53 @@ <!--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 spacing between list item markers and
content is inconsistent.
[`remark-lint`][github-remark-lint] rule to warn when the whitespace after list item markers 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(remarkLintListItemIndent[, config])`](#unifieduseremarklintlistitemindent-config)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [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(remarkLintListItemIndent[, options])`](#unifieduseremarklintlistitemindent-options)
* [`Options`](#options)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [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 the style of whitespace after list item markers.
## When should I use this?
You can use this package to check that the spacing between list item markers
and content is inconsistent.
You can use this package to check that the style of whitespace after list
item markers and before content is consistent.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |
| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | `'mixed'` |
| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | `'tab-size'` |
| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | `'one'` |
## Install
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]:

@@ -62,13 +62,13 @@ ```sh

In Deno with [`esm.sh`][esmsh]:
In Deno with [`esm.sh`][esm-sh]:
```js
import remarkLintListItemIndent from 'https://esm.sh/remark-lint-list-item-indent@3'
import remarkLintListItemIndent from 'https://esm.sh/remark-lint-list-item-indent@4'
```
In browsers with [`esm.sh`][esmsh]:
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import remarkLintListItemIndent from 'https://esm.sh/remark-lint-list-item-indent@3?bundle'
import remarkLintListItemIndent from 'https://esm.sh/remark-lint-list-item-indent@4?bundle'
</script>

@@ -82,18 +82,20 @@ ```

```js
import remarkLint from 'remark-lint'
import remarkLintListItemIndent from 'remark-lint-list-item-indent'
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 remarkLintListItemIndent from 'remark-lint-list-item-indent'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintListItemIndent)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintListItemIndent)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

@@ -104,3 +106,3 @@

```sh
remark --use remark-lint --use remark-lint-list-item-indent example.md
remark --frail --use remark-lint --use remark-lint-list-item-indent .
```

@@ -126,54 +128,76 @@

This package exports no identifiers.
The default export is `remarkLintListItemIndent`.
It exports the [TypeScript][typescript] type
[`Options`][api-options].
The default export is
[`remarkLintListItemIndent`][api-remark-lint-list-item-indent].
### `unified().use(remarkLintListItemIndent[, config])`
### `unified().use(remarkLintListItemIndent[, 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 the whitespace after list item markers violate a given style.
The following options (default: `'tab-size'`) are accepted:
###### Parameters
* `'space'`
— prefer a single space
* `'tab-size'`
— prefer spaces the size of the next tab stop
* `'mixed'`
— prefer `'space'` for tight lists and `'tab-size'` for loose lists
* `options` ([`Options`][api-options], default: `'one'`)
— preferred style
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
### `Options`
Configuration (TypeScript type).
* `'mixed'`
— prefer `'one'` for tight lists and `'tab'` for loose lists
* `'one'`
— prefer the size of the bullet and a single space
* `'tab'`
— prefer the size of the bullet and a single space to the next tab stop
###### Type
```ts
type Options = 'mixed' | 'one' | 'tab'
```
## Recommendation
First, some background.
First some background.
The number of spaces that occur after list markers (`*`, `-`, and `+` for
unordered lists, or `.` and `)` for unordered lists) and before the content
on the first line, defines how much indentation can be used for further
lines.
At least one space is required and up to 4 spaces are allowed (if there is no
further content after the marker then it’s a blank line which is handled as
if there was one space; if there are 5 or more spaces and then content, it’s
also seen as one space and the rest is seen as indented code).
unordered lists and `.` and `)` for unordered lists) and before the content
on the first line,
defines how much indentation can be used for further lines.
At least one space is required and up to 4 spaces are allowed.
If there is no further content after the marker then it’s a blank line which
is handled as if there was one space.
If there are 5 or more spaces and then content then it’s also seen as one
space and the rest is seen as indented code.
There are two types of lists in markdown (other than ordered and unordered):
tight and loose lists.
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.
Historically, how indentation of lists works in markdown has been a mess,
How indentation of lists works in markdown has historically been a mess,
especially with how they interact with indented code.
CommonMark made that a *lot* better, but there remain (documented but
complex) edge cases and some behavior intuitive.
Due to this, the default of this list is `'tab-size'`, which worked the best
in most markdown parsers.
Currently, the situation between markdown parsers is better, so choosing
`'space'` (which seems to be the most common style used by authors) should
be okay.
CommonMark made that a *lot* better,
but there remain (documented but complex) edge cases and some behavior
intuitive.
Due to this, `'tab'` works the best in most markdown parsers *and* in
CommonMark.
Currently the situation between markdown parsers is better,
so the default `'one'`,
which seems to be the most common style used by authors,
is okay.
## Fix
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
uses `'tab-size'` (named `'tab'` there) by default.
[`listItemIndent: '1'` (for `'space'`) or `listItemIndent: 'mixed'`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionslistitemindent)
is supported.
[`remark-stringify`][github-remark-stringify] uses `listItemIndent: 'one'`
by default.
`listItemIndent: 'mixed'` or `listItemIndent: 'tab'` is also supported.

@@ -186,20 +210,17 @@ ## Examples

> 👉 **Note**: `·` represents a space.
```markdown
*···List
····item.
*␠Mercury.
*␠Venus.
Paragraph.
111.␠Earth
␠␠␠␠␠and Mars.
11.·List
····item.
*␠**Jupiter**.
Paragraph.
␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠System.
*···List
····item.
*␠Saturn.
*···List
····item.
␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -217,18 +238,17 @@

> 👉 **Note**: `·` represents a space.
```markdown
*·List item.
*␠Mercury.
*␠Venus.
Paragraph.
111.␠Earth
␠␠␠␠␠and Mars.
11.·List item
*␠␠␠**Jupiter**.
Paragraph.
␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠␠␠System.
*···List
····item.
*␠␠␠Saturn.
*···List
····item.
␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -246,6 +266,17 @@

> 👉 **Note**: `·` represents a space.
```markdown
*␠␠␠Mercury.
*␠␠␠Venus.
```markdown
*···List item.
111.␠␠␠␠Earth
␠␠␠␠␠␠␠␠and Mars.
*␠**Jupiter**.
␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠System.
*␠Saturn.
␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -256,3 +287,7 @@

```text
1:5: Incorrect list-item indent: remove 2 spaces
1:5: Unexpected `3` spaces between list item marker and content in tight list, expected `1` space, remove `2` spaces
2:5: Unexpected `3` spaces between list item marker and content in tight list, expected `1` space, remove `2` spaces
4:9: Unexpected `4` spaces between list item marker and content in tight list, expected `1` space, remove `3` spaces
7:3: Unexpected `1` space between list item marker and content in loose list, expected `3` spaces, add `2` spaces
12:3: Unexpected `1` space between list item marker and content in loose list, expected `3` spaces, add `2` spaces
```

@@ -262,22 +297,21 @@

When configured with `'space'`.
When configured with `'one'`.
###### In
> 👉 **Note**: `·` represents a space.
```markdown
*·List item.
*␠Mercury.
*␠Venus.
Paragraph.
111.␠Earth
␠␠␠␠␠and Mars.
11.·List item
*␠**Jupiter**.
Paragraph.
␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠System.
*·List
··item.
*␠Saturn.
*·List
··item.
␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -291,11 +325,21 @@

When configured with `'space'`.
When configured with `'one'`.
###### In
> 👉 **Note**: `·` represents a space.
```markdown
*␠␠␠Mercury.
*␠␠␠Venus.
```markdown
*···List
····item.
111.␠␠␠␠Earth
␠␠␠␠␠␠␠␠and Mars.
*␠␠␠**Jupiter**.
␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠␠␠System.
*␠␠␠Saturn.
␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -306,16 +350,57 @@

```text
1:5: Incorrect list-item indent: remove 2 spaces
1:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
2:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
4:9: Unexpected `4` spaces between list item marker and content, expected `1` space, remove `3` spaces
7:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
12:5: Unexpected `3` spaces between list item marker and content, expected `1` space, remove `2` spaces
```
##### `ok.md`
When configured with `'tab'`.
###### In
```markdown
*␠␠␠Mercury.
*␠␠␠Venus.
111.␠␠␠␠Earth
␠␠␠␠␠␠␠␠and Mars.
*␠␠␠**Jupiter**.
␠␠␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠␠␠System.
*␠␠␠Saturn.
␠␠␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```
###### Out
No messages.
##### `not-ok.md`
When configured with `'tab-size'`.
When configured with `'tab'`.
###### In
> 👉 **Note**: `·` represents a space.
```markdown
*␠Mercury.
*␠Venus.
```markdown
*·List
··item.
111.␠Earth
␠␠␠␠␠and Mars.
*␠**Jupiter**.
␠␠Jupiter is the fifth planet from the Sun and the largest in the Solar
␠␠System.
*␠Saturn.
␠␠Saturn is the sixth planet from the Sun and the second-largest in the Solar System, after Jupiter.
```

@@ -326,3 +411,7 @@

```text
1:3: Incorrect list-item indent: add 2 spaces
1:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
2:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
4:6: Unexpected `1` space between list item marker and content, expected `4` spaces, add `3` spaces
7:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
12:3: Unexpected `1` space between list item marker and content, expected `3` spaces, add `2` spaces
```

@@ -332,3 +421,3 @@

When configured with `'💩'`.
When configured with `'🌍'`.

@@ -338,19 +427,111 @@ ###### Out

```text
1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'`
1:1: Unexpected value `🌍` for `options`, expected `'mixed'`, `'one'`, or `'tab'`
```
##### `gfm.md`
When configured with `'mixed'`.
###### In
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
*␠[x] Mercury.
1.␠␠[ ] Venus.
2.␠␠[ ] Earth.
```
###### Out
No messages.
##### `gfm.md`
When configured with `'one'`.
###### In
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
*␠[x] Mercury.
1.␠[ ] Venus.
2.␠[ ] Earth.
```
###### Out
No messages.
##### `gfm.md`
When configured with `'tab'`.
###### In
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
*␠␠␠[x] Mercury.
1.␠␠[ ] Venus.
2.␠␠[ ] Earth.
```
###### Out
No messages.
##### `loose-tight.md`
When configured with `'mixed'`.
###### In
```markdown
Loose lists have blank lines between items:
*␠␠␠Mercury.
*␠␠␠Venus.
…or between children of items:
1.␠␠Earth.
␠␠␠␠Earth is the third planet from the Sun and the only astronomical
␠␠␠␠object known to harbor life.
```
###### Out
No messages.
## Compatibility
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-indent@4`,
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

@@ -361,52 +542,60 @@ 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-indent]: #unifieduseremarklintlistitemindent-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-indent.svg
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[downloads]: https://www.npmjs.com/package/remark-lint-list-item-indent
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-list-item-indent.svg
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size]: https://bundlephobia.com/result?p=remark-lint-list-item-indent
[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-indent.svg
[collective]: https://opencollective.com/unified
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-list-item-indent
[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-indent
[mono]: https://github.com/remarkjs/remark-lint
[badge-size-url]: https://bundlejs.com/?q=remark-lint-list-item-indent
[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-gfm]: https://github.com/remarkjs/remark-gfm
[author]: https://wooorm.com
[github-remark-lint]: https://github.com/remarkjs/remark-lint
[github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
[npm-install]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc