Socket
Socket
Sign inDemoInstall

remark-lint-ordered-list-marker-value

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-ordered-list-marker-value - npm Package Compare versions

Comparing version 2.0.1 to 3.1.1

index.d.ts

205

index.js
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module ordered-list-marker-value
* @fileoverview
* Warn when the list item marker values of ordered lists violate a given
* style.
* ## When should I use this?
*
* Options: `'single'`, `'one'`, or `'ordered'`, default: `'ordered'`.
* You can use this package to check that ordered list values are consistent.
*
* When set to `'ordered'`, list item bullets should increment by one,
* relative to the starting point.
* When set to `'single'`, bullets should be the same as the relative starting
* point.
* When set to `'one'`, bullets should always be `1`.
* ## API
*
* ## Fix
* The following options (default: `'ordered'`) are accepted:
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify)
* retains the number of the first list item bullet, and by default
* increments the other items.
* Pass
* [`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionsincrementlistmarker)
* to not increment further list items.
* * `'ordered'`
* β€” values should increment by one from the first item
* * `'single'`
* β€” values should stay the same as the first item
* * `'one'`
* β€” values should always be exactly `1`
*
* See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
* on how to automatically fix warnings for this rule.
* ## Recommendation
*
* @example {"name": "ok.md"}
* While `'single'` might be the smartest style, as it makes it easier to move
* items around without having to renumber everything and doesn’t have
* problems with aligning content of the 9th and the 10th item, it’s not used a
* lot and arguably looks unnatural.
* `'one'` is like `'single'` but forces every list to start at `1`.
* While not often needed, starting lists at other values is sometimes useful.
* Due to this, `'ordered'` is recommended, although `'single'` is also a viable
* choice.
*
* ## Fix
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
* retains the value of the first item and increments further items by default.
* Pass
* [`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker)
* to not increment further items.
*
* @module ordered-list-marker-value
* @summary
* remark-lint rule to warn when ordered list values are inconsistent.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @example
* {"name": "ok.md"}
*
* The default value is `ordered`, so unless changed, the below

@@ -49,3 +62,4 @@ * is OK.

*
* @example {"name": "ok.md", "setting": "one"}
* @example
* {"name": "ok.md", "setting": "one"}
*

@@ -62,3 +76,4 @@ * 1. Foo

*
* @example {"name": "ok.md", "setting": "single"}
* @example
* {"name": "ok.md", "setting": "single"}
*

@@ -81,3 +96,4 @@ * 1. Foo

*
* @example {"name": "ok.md", "setting": "ordered"}
* @example
* {"name": "ok.md", "setting": "ordered"}
*

@@ -100,3 +116,4 @@ * 1. Foo

*
* @example {"name": "not-ok.md", "setting": "one", "label": "input"}
* @example
* {"name": "not-ok.md", "setting": "one", "label": "input"}
*

@@ -106,7 +123,9 @@ * 1. Foo

*
* @example {"name": "not-ok.md", "setting": "one", "label": "output"}
* @example
* {"name": "not-ok.md", "setting": "one", "label": "output"}
*
* 2:1-2:8: Marker should be `1`, was `2`
*
* @example {"name": "also-not-ok.md", "setting": "one", "label": "input"}
* @example
* {"name": "also-not-ok.md", "setting": "one", "label": "input"}
*

@@ -116,7 +135,9 @@ * 2. Foo

*
* @example {"name": "also-not-ok.md", "setting": "one", "label": "output"}
* @example
* {"name": "also-not-ok.md", "setting": "one", "label": "output"}
*
* 1:1-1:8: Marker should be `1`, was `2`
*
* @example {"name": "not-ok.md", "setting": "ordered", "label": "input"}
* @example
* {"name": "not-ok.md", "setting": "ordered", "label": "input"}
*

@@ -126,77 +147,83 @@ * 1. Foo

*
* @example {"name": "not-ok.md", "setting": "ordered", "label": "output"}
* @example
* {"name": "not-ok.md", "setting": "ordered", "label": "output"}
*
* 2:1-2:8: Marker should be `2`, was `1`
*
* @example {"name": "not-ok.md", "setting": "πŸ’©", "label": "output", "config": {"positionless": true}}
* @example
* {"name": "not-ok.md", "setting": "πŸ’©", "label": "output", "positionless": true}
*
* 1:1: Incorrect ordered list item marker value `πŸ’©`: use either `'ordered'` or `'one'`
* 1:1: Incorrect ordered list item marker value `πŸ’©`: use either `'ordered'`, `'one'`, or `'single'`
*/
'use strict'
/**
* @typedef {import('mdast').Root} Root
* @typedef {'single'|'one'|'ordered'} Options
*/
var rule = require('unified-lint-rule')
var visit = require('unist-util-visit')
var position = require('unist-util-position')
var generated = require('unist-util-generated')
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart} from 'unist-util-position'
import {generated} from 'unist-util-generated'
module.exports = rule(
'remark-lint:ordered-list-marker-value',
orderedListMarkerValue
)
const remarkLintOrderedListMarkerValue = lintRule(
{
origin: 'remark-lint:ordered-list-marker-value',
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value#readme'
},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'ordered') => {
const value = String(file)
var start = position.start
if (option !== 'ordered' && option !== 'one' && option !== 'single') {
file.fail(
'Incorrect ordered list item marker value `' +
option +
"`: use either `'ordered'`, `'one'`, or `'single'`"
)
}
var styles = {ordered: true, single: true, one: true}
visit(tree, 'list', (node) => {
if (!node.ordered) return
function orderedListMarkerValue(tree, file, option) {
var contents = String(file)
var preferred = typeof option === 'string' ? option : 'ordered'
let expected =
option === 'one' || node.start === null || node.start === undefined
? 1
: node.start
let index = -1
if (styles[preferred] !== true) {
file.fail(
'Incorrect ordered list item marker value `' +
preferred +
"`: use either `'ordered'` or `'one'`"
)
}
while (++index < node.children.length) {
const child = node.children[index]
visit(tree, 'list', visitor)
// Ignore generated nodes, first items.
if (generated(child) || (index === 0 && option !== 'one')) {
continue
}
function visitor(node) {
var children = node.children
var expected = preferred === 'one' ? 1 : node.start == null ? 1 : node.start
var length = node.ordered ? children.length : 0
var index = -1
var child
var marker
// Increase the expected line number when in `ordered` mode.
if (option === 'ordered') {
expected++
}
while (++index < length) {
child = children[index]
const marker = Number(
value
.slice(
pointStart(child).offset,
pointStart(child.children[0]).offset
)
.replace(/[\s.)]/g, '')
.replace(/\[[x ]?]\s*$/i, '')
)
// Ignore generated nodes, first items.
if (generated(child) || (index === 0 && preferred !== 'one')) {
continue
if (marker !== expected) {
file.message(
'Marker should be `' + expected + '`, was `' + marker + '`',
child
)
}
}
})
}
)
// Increase the expected line number when in `ordered` mode.
if (preferred === 'ordered') {
expected++
}
marker = Number(
contents
.slice(start(child).offset, start(child.children[0]).offset)
.replace(/[\s.)]/g, '')
.replace(/\[[x ]?]\s*$/i, '')
)
if (marker !== expected) {
file.message(
'Marker should be `' + expected + '`, was `' + marker + '`',
child
)
}
}
}
}
export default remarkLintOrderedListMarkerValue
{
"name": "remark-lint-ordered-list-marker-value",
"version": "2.0.1",
"version": "3.1.1",
"description": "remark-lint rule to warn when the marker value of ordered lists violates a given style",

@@ -15,3 +15,7 @@ "license": "MIT",

],
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value",
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-ordered-list-marker-value"
},
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -26,12 +30,28 @@ "funding": {

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.0.0"
"@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"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -13,25 +13,30 @@ <!--This file is generated-->

Warn when the list item marker values of ordered lists violate a given
style.
[`remark-lint`][mono] rule to warn when ordered list values are inconsistent.
Options: `'single'`, `'one'`, or `'ordered'`, default: `'ordered'`.
## Contents
When set to `'ordered'`, list item bullets should increment by one,
relative to the starting point.
When set to `'single'`, bullets should be the same as the relative starting
point.
When set to `'one'`, bullets should always be `1`.
* [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(remarkLintOrderedListMarkerValue[, config])`](#unifieduseremarklintorderedlistmarkervalue-config)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## Fix
## What is this?
[`remark-stringify`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify)
retains the number of the first list item bullet, and by default
increments the other items.
Pass
[`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#optionsincrementlistmarker)
to not increment further list items.
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint`
rule.
Lint rules check markdown code style.
See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
on how to automatically fix warnings for this rule.
## When should I use this?
You can use this package to check that ordered list values are consistent.
## Presets

@@ -45,4 +50,109 @@

## Example
## Install
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
```sh
npm install remark-lint-ordered-list-marker-value
```
In Deno with [Skypack][]:
```js
import remarkLintOrderedListMarkerValue from 'https://cdn.skypack.dev/remark-lint-ordered-list-marker-value@3?dts'
```
In browsers with [Skypack][]:
```html
<script type="module">
import remarkLintOrderedListMarkerValue from 'https://cdn.skypack.dev/remark-lint-ordered-list-marker-value@3?min'
</script>
```
## Use
On the API:
```js
import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkLint from 'remark-lint'
import remarkLintOrderedListMarkerValue from 'remark-lint-ordered-list-marker-value'
main()
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintOrderedListMarkerValue)
.process(await read('example.md'))
console.error(reporter(file))
}
```
On the CLI:
```sh
remark --use remark-lint --use remark-lint-ordered-list-marker-value example.md
```
On the CLI in a config file (here a `package.json`):
```diff
…
"remarkConfig": {
"plugins": [
…
"remark-lint",
+ "remark-lint-ordered-list-marker-value",
…
]
}
…
```
## API
This package exports no identifiers.
The default export is `remarkLintOrderedListMarkerValue`.
### `unified().use(remarkLintOrderedListMarkerValue[, config])`
This rule supports standard configuration that all remark lint rules accept
(such as `false` to turn it off or `[1, options]` to configure it).
The following options (default: `'ordered'`) are accepted:
* `'ordered'`
β€” values should increment by one from the first item
* `'single'`
β€” values should stay the same as the first item
* `'one'`
β€” values should always be exactly `1`
## Recommendation
While `'single'` might be the smartest style, as it makes it easier to move
items around without having to renumber everything and doesn’t have
problems with aligning content of the 9th and the 10th item, it’s not used a
lot and arguably looks unnatural.
`'one'` is like `'single'` but forces every list to start at `1`.
While not often needed, starting lists at other values is sometimes useful.
Due to this, `'ordered'` is recommended, although `'single'` is also a viable
choice.
## Fix
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
retains the value of the first item and increments further items by default.
Pass
[`incrementListMarker: false`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsincrementlistmarker)
to not increment further items.
## Examples
##### `ok.md`

@@ -211,50 +321,12 @@

```text
1:1: Incorrect ordered list item marker value `πŸ’©`: use either `'ordered'` or `'one'`
1:1: Incorrect ordered list item marker value `πŸ’©`: use either `'ordered'`, `'one'`, or `'single'`
```
## Install
## Compatibility
[npm][]:
Projects maintained by the unified collective are compatible with all 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.
```sh
npm install remark-lint-ordered-list-marker-value
```
## Use
You probably want to use it on the CLI through a config file:
```diff
…
"remarkConfig": {
"plugins": [
…
"lint",
+ "lint-ordered-list-marker-value",
…
]
}
…
```
Or use it on the CLI directly
```sh
remark -u lint -u lint-ordered-list-marker-value readme.md
```
Or use this on the API:
```diff
var remark = require('remark')
var report = require('vfile-reporter')
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-ordered-list-marker-value'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
})
```
## Contribute

@@ -274,5 +346,5 @@

[build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[build]: https://travis-ci.org/remarkjs/remark-lint
[build]: https://github.com/remarkjs/remark-lint/actions

@@ -297,6 +369,16 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/remark
[chat]: https://github.com/remarkjs/remark/discussions
[unified]: https://github.com/unifiedjs/unified
[remark]: https://github.com/remarkjs/remark
[mono]: https://github.com/remarkjs/remark-lint
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[skypack]: https://www.skypack.dev
[npm]: https://docs.npmjs.com/cli/install

@@ -306,7 +388,7 @@

[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md

@@ -313,0 +395,0 @@ [license]: https://github.com/remarkjs/remark-lint/blob/main/license

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