remark-lint-list-item-bullet-indent
Advanced tools
Comparing version 4.1.2 to 5.0.0
@@ -1,7 +0,7 @@ | ||
export default remarkLintListItemBulletIndent | ||
export type Root = import('mdast').Root | ||
declare const remarkLintListItemBulletIndent: import('unified').Plugin< | ||
void[] | [unknown], | ||
import('mdast').Root, | ||
import('mdast').Root | ||
> | ||
export default remarkLintListItemBulletIndent; | ||
export type Root = import('mdast').Root; | ||
declare const remarkLintListItemBulletIndent: { | ||
(config?: unknown): ((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 |
127
index.js
/** | ||
* remark-lint rule to warn when list item markers are indented. | ||
* | ||
* ## What is this? | ||
* | ||
* This package checks indentation before list item markers. | ||
* | ||
* ## When should I use this? | ||
* | ||
* You can use this package to check that list items are not indented. | ||
* You can use this package to check that the style of list items is | ||
* consistent. | ||
* | ||
* ## API | ||
* | ||
* ### `unified().use(remarkLintListItemBulletIndent)` | ||
* | ||
* Warn when list item markers are indented. | ||
* | ||
* ###### Parameters | ||
* | ||
* There are no options. | ||
* | ||
* ###### Returns | ||
* | ||
* Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
* | ||
* ## Recommendation | ||
* | ||
* There is no specific handling of indented list items (or anything else) in | ||
* markdown. | ||
* There is no specific handling of indented list items in markdown. | ||
* While it is possible to use an indent to align ordered lists on their marker: | ||
* | ||
* ```markdown | ||
* 1. One | ||
* 10. Ten | ||
* 100. Hundred | ||
* 1. Mercury | ||
* 10. Venus | ||
* 100. Earth | ||
* ``` | ||
* | ||
* …such a style is uncommon and a bit hard to maintain: adding a 10th item | ||
* means 9 other items have to change (more arduous, while unlikely, would be | ||
* …such a style is uncommon and hard to maintain as adding a 10th item | ||
* means 9 other items have to change (more arduous while unlikely would be | ||
* the 100th item). | ||
* Hence, it’s recommended to not indent items and to turn this rule on. | ||
* So it is recommended to not indent items and to turn this rule on. | ||
* | ||
* ## Fix | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) | ||
* formats all items without indent. | ||
* [`remark-stringify`][github-remark-stringify] formats all items without | ||
* indent. | ||
* | ||
* [api-remark-lint-list-item-bullet-indent]: #unifieduseremarklintlistitembulletindent | ||
* [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-bullet-indent | ||
* @summary | ||
* remark-lint rule to warn when list items are indented. | ||
* @author Titus Wormer | ||
@@ -41,20 +59,20 @@ * @copyright 2015 Titus Wormer | ||
* | ||
* Paragraph. | ||
* Mercury. | ||
* | ||
* * List item | ||
* * List item | ||
* * Venus. | ||
* * Earth. | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "input"} | ||
* {"label": "input", "name": "not-ok.md"} | ||
* | ||
* Paragraph. | ||
* Mercury. | ||
* | ||
* ·* List item | ||
* ·* List item | ||
* ␠* Venus. | ||
* ␠* Earth. | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "output"} | ||
* {"label": "output", "name": "not-ok.md"} | ||
* | ||
* 3:2: Incorrect indentation before bullet: remove 1 space | ||
* 4:2: Incorrect indentation before bullet: remove 1 space | ||
* 3:2: Unexpected `1` space before list item, expected `0` spaces, remove them | ||
* 4:2: Unexpected `1` space before list item, expected `0` spaces, remove them | ||
*/ | ||
@@ -66,5 +84,5 @@ | ||
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' | ||
@@ -76,33 +94,40 @@ const remarkLintListItemBulletIndent = lintRule( | ||
}, | ||
/** @type {import('unified-lint-rule').Rule<Root, void>} */ | ||
(tree, file) => { | ||
visit(tree, 'list', (list, _, grandparent) => { | ||
let index = -1 | ||
/** | ||
* @param {Root} tree | ||
* Tree. | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function (tree, file) { | ||
const treeStart = pointStart(tree) | ||
while (++index < list.children.length) { | ||
const item = list.children[index] | ||
// Unknown containers are not supported. | ||
if (!tree || tree.type !== 'root' || !treeStart) return | ||
if ( | ||
grandparent && | ||
grandparent.type === 'root' && | ||
grandparent.position && | ||
typeof grandparent.position.start.column === 'number' && | ||
item.position && | ||
typeof item.position.start.column === 'number' | ||
) { | ||
const indent = | ||
item.position.start.column - grandparent.position.start.column | ||
for (const child of tree.children) { | ||
if (child.type !== 'list') continue | ||
if (indent) { | ||
file.message( | ||
'Incorrect indentation before bullet: remove ' + | ||
indent + | ||
' ' + | ||
plural('space', indent), | ||
item.position.start | ||
) | ||
} | ||
const list = child | ||
for (const item of list.children) { | ||
const place = pointStart(item) | ||
/* c8 ignore next 2 -- doesn’t happen in tests as the whole tree is | ||
* generated. */ | ||
if (!place) continue | ||
const actual = place.column - treeStart.column | ||
if (actual) { | ||
file.message( | ||
'Unexpected `' + | ||
actual + | ||
'` ' + | ||
pluralize('space', actual) + | ||
' before list item, expected `0` spaces, remove them', | ||
{ancestors: [tree, list, item], place} | ||
) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
@@ -109,0 +134,0 @@ ) |
{ | ||
"name": "remark-lint-list-item-bullet-indent", | ||
"version": "4.1.2", | ||
"version": "5.0.0", | ||
"description": "remark-lint rule to warn when list item bullets are indented", | ||
"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-bullet-indent" | ||
}, | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-list-item-bullet-indent", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
@@ -27,27 +24,31 @@ "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", | ||
"pluralize": "^8.0.0", | ||
"unified": "^10.0.0", | ||
"unified-lint-rule": "^2.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"unified-lint-rule": "^3.0.0", | ||
"unist-util-position": "^5.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" | ||
} | ||
} | ||
} |
216
readme.md
@@ -5,43 +5,42 @@ <!--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 list items are indented. | ||
[`remark-lint`][github-remark-lint] rule to warn when list item markers are indented. | ||
## 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(remarkLintListItemBulletIndent[, config])`](#unifieduseremarklintlistitembulletindent-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(remarkLintListItemBulletIndent)`](#unifieduseremarklintlistitembulletindent) | ||
* [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 indentation before list item markers. | ||
## When should I use this? | ||
You can use this package to check that list items are not indented. | ||
You can use this package to check that the style of list items is | ||
consistent. | ||
## Presets | ||
This rule is included in the following presets: | ||
This plugin is included in the following presets: | ||
| Preset | Setting | | ||
| Preset | Options | | ||
| - | - | | ||
@@ -52,4 +51,5 @@ | [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended) | | | ||
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]: | ||
@@ -60,13 +60,13 @@ ```sh | ||
In Deno with [`esm.sh`][esmsh]: | ||
In Deno with [`esm.sh`][esm-sh]: | ||
```js | ||
import remarkLintListItemBulletIndent from 'https://esm.sh/remark-lint-list-item-bullet-indent@4' | ||
import remarkLintListItemBulletIndent from 'https://esm.sh/remark-lint-list-item-bullet-indent@5' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
In browsers with [`esm.sh`][esm-sh]: | ||
```html | ||
<script type="module"> | ||
import remarkLintListItemBulletIndent from 'https://esm.sh/remark-lint-list-item-bullet-indent@4?bundle' | ||
import remarkLintListItemBulletIndent from 'https://esm.sh/remark-lint-list-item-bullet-indent@5?bundle' | ||
</script> | ||
@@ -80,18 +80,20 @@ ``` | ||
```js | ||
import remarkLint from 'remark-lint' | ||
import remarkLintListItemBulletIndent from 'remark-lint-list-item-bullet-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 remarkLintListItemBulletIndent from 'remark-lint-list-item-bullet-indent' | ||
main() | ||
const file = await read('example.md') | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintListItemBulletIndent) | ||
.process(await read('example.md')) | ||
await unified() | ||
.use(remarkParse) | ||
.use(remarkLint) | ||
.use(remarkLintListItemBulletIndent) | ||
.use(remarkStringify) | ||
.process(file) | ||
console.error(reporter(file)) | ||
} | ||
console.error(reporter(file)) | ||
``` | ||
@@ -102,3 +104,3 @@ | ||
```sh | ||
remark --use remark-lint --use remark-lint-list-item-bullet-indent example.md | ||
remark --frail --use remark-lint --use remark-lint-list-item-bullet-indent . | ||
``` | ||
@@ -124,32 +126,38 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintListItemBulletIndent`. | ||
It exports no additional [TypeScript][typescript] types. | ||
The default export is | ||
[`remarkLintListItemBulletIndent`][api-remark-lint-list-item-bullet-indent]. | ||
### `unified().use(remarkLintListItemBulletIndent[, config])` | ||
### `unified().use(remarkLintListItemBulletIndent)` | ||
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 list item markers are indented. | ||
###### Parameters | ||
There are no options. | ||
###### Returns | ||
Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
## Recommendation | ||
There is no specific handling of indented list items (or anything else) in | ||
markdown. | ||
There is no specific handling of indented list items in markdown. | ||
While it is possible to use an indent to align ordered lists on their marker: | ||
```markdown | ||
1. One | ||
10. Ten | ||
100. Hundred | ||
1. Mercury | ||
10. Venus | ||
100. Earth | ||
``` | ||
…such a style is uncommon and a bit hard to maintain: adding a 10th item | ||
means 9 other items have to change (more arduous, while unlikely, would be | ||
…such a style is uncommon and hard to maintain as adding a 10th item | ||
means 9 other items have to change (more arduous while unlikely would be | ||
the 100th item). | ||
Hence, it’s recommended to not indent items and to turn this rule on. | ||
So it is recommended to not indent items and to turn this rule on. | ||
## Fix | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) | ||
formats all items without indent. | ||
[`remark-stringify`][github-remark-stringify] formats all items without | ||
indent. | ||
@@ -163,6 +171,6 @@ ## Examples | ||
```markdown | ||
Paragraph. | ||
Mercury. | ||
* List item | ||
* List item | ||
* Venus. | ||
* Earth. | ||
``` | ||
@@ -178,9 +186,7 @@ | ||
> 👉 **Note**: `·` represents a space. | ||
```markdown | ||
Paragraph. | ||
Mercury. | ||
·* List item | ||
·* List item | ||
␠* Venus. | ||
␠* Earth. | ||
``` | ||
@@ -191,4 +197,4 @@ | ||
```text | ||
3:2: Incorrect indentation before bullet: remove 1 space | ||
4:2: Incorrect indentation before bullet: remove 1 space | ||
3:2: Unexpected `1` space before list item, expected `0` spaces, remove them | ||
4:2: Unexpected `1` space before list item, expected `0` spaces, remove them | ||
``` | ||
@@ -198,14 +204,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-bullet-indent@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 | ||
@@ -216,52 +226,56 @@ 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-remark-lint-list-item-bullet-indent]: #unifieduseremarklintlistitembulletindent | ||
[build]: https://github.com/remarkjs/remark-lint/actions | ||
[author]: https://wooorm.com | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
[coverage]: https://codecov.io/github/remarkjs/remark-lint | ||
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions | ||
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-list-item-bullet-indent.svg | ||
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[downloads]: https://www.npmjs.com/package/remark-lint-list-item-bullet-indent | ||
[badge-chat-url]: https://github.com/remarkjs/remark/discussions | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-list-item-bullet-indent.svg | ||
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[size]: https://bundlephobia.com/result?p=remark-lint-list-item-bullet-indent | ||
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-list-item-bullet-indent.svg | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-list-item-bullet-indent | ||
[collective]: https://opencollective.com/unified | ||
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
[badge-funding-url]: https://opencollective.com/unified | ||
[unified]: https://github.com/unifiedjs/unified | ||
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-list-item-bullet-indent | ||
[remark]: https://github.com/remarkjs/remark | ||
[badge-size-url]: https://bundlejs.com/?q=remark-lint-list-item-bullet-indent | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[esm-sh]: https://esm.sh | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[esmsh]: https://esm.sh | ||
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[health]: https://github.com/remarkjs/.github | ||
[github-dotfiles-health]: https://github.com/remarkjs/.github | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[github-remark-lint]: https://github.com/remarkjs/remark-lint | ||
[license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify | ||
[author]: https://wooorm.com | ||
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
[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
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
11953
4
5
128
271
1
+ Addedunist-util-position@^5.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)
+ Addedunified@11.0.5(transitive)
+ Addedunified-lint-rule@3.0.0(transitive)
+ Addedunist-util-position@5.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedvfile@6.0.3(transitive)
+ Addedvfile-message@4.0.2(transitive)
- Removedunified@^10.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-is@5.2.1(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