Socket
Socket
Sign inDemoInstall

remark-lint-unordered-list-marker-style

Package Overview
Dependencies
17
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 3.0.0

index.d.ts

116

index.js

@@ -26,3 +26,4 @@ /**

*
* @example {"name": "ok.md"}
* @example
* {"name": "ok.md"}
*

@@ -42,15 +43,19 @@ * By default (`'consistent'`), if the file uses only one marker,

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

@@ -61,3 +66,4 @@ * * Foo

*
* @example {"name": "not-ok.md", "label": "output"}
* @example
* {"name": "not-ok.md", "label": "output"}
*

@@ -67,3 +73,4 @@ * 2:1-2:6: Marker style should be `*`

*
* @example {"name": "not-ok.md", "label": "output", "setting": "💩", "config": {"positionless": true}}
* @example
* {"name": "not-ok.md", "label": "output", "setting": "💩", "positionless": true}
*

@@ -73,64 +80,59 @@ * 1:1: Incorrect unordered list item marker style `💩`: use either `'-'`, `'*'`, or `'+'`

'use strict'
/**
* @typedef {import('mdast').Root} Root
* @typedef {'-'|'*'|'+'} Marker
* @typedef {'consistent'|Marker} 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(
const markers = new Set(['-', '*', '+'])
const remarkLintUnorderedListMarkerStyle = lintRule(
'remark-lint:unordered-list-marker-style',
unorderedListMarkerStyle
)
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
const value = String(file)
var start = position.start
if (option !== 'consistent' && !markers.has(option)) {
file.fail(
'Incorrect unordered list item marker style `' +
option +
"`: use either `'-'`, `'*'`, or `'+'`"
)
}
var styles = {
'-': true,
'*': true,
'+': true,
null: true
}
visit(tree, 'list', (node) => {
if (node.ordered) return
function unorderedListMarkerStyle(tree, file, option) {
var contents = String(file)
var preferred =
typeof option === 'string' && option !== 'consistent' ? option : null
let index = -1
if (styles[preferred] !== true) {
file.fail(
'Incorrect unordered list item marker style `' +
preferred +
"`: use either `'-'`, `'*'`, or `'+'`"
)
}
while (++index < node.children.length) {
const child = node.children[index]
visit(tree, 'list', visitor)
if (!generated(child)) {
const marker = /** @type {Marker} */ (
value
.slice(
pointStart(child).offset,
pointStart(child.children[0]).offset
)
.replace(/\[[x ]?]\s*$/i, '')
.replace(/\s/g, '')
)
function visitor(node) {
var children = node.children
var length = node.ordered ? 0 : children.length
var index = -1
var child
var marker
while (++index < length) {
child = children[index]
if (!generated(child)) {
marker = contents
.slice(start(child).offset, start(child.children[0]).offset)
.replace(/\[[x ]?]\s*$/i, '')
.replace(/\s/g, '')
if (preferred) {
if (marker !== preferred) {
file.message('Marker style should be `' + preferred + '`', child)
if (option === 'consistent') {
option = marker
} else if (marker !== option) {
file.message('Marker style should be `' + option + '`', child)
}
} else {
preferred = marker
}
}
}
})
}
}
)
export default remarkLintUnorderedListMarkerStyle
{
"name": "remark-lint-unordered-list-marker-style",
"version": "2.0.1",
"version": "3.0.0",
"description": "remark-lint rule to warn when markers of unordered lists violate a given style",

@@ -25,12 +25,28 @@ "license": "MIT",

],
"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
}
}

@@ -136,2 +136,5 @@ <!--This file is generated-->

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -143,2 +146,5 @@

This package exports no identifiers.
The default export is `remarkLintUnorderedListMarkerStyle`.
## Use

@@ -170,10 +176,13 @@

```diff
var remark = require('remark')
var report = require('vfile-reporter')
import {remark} from 'remark'
import {reporter} from 'vfile-reporter'
import remarkLint from 'remark-lint'
import remarkLintUnorderedListMarkerStyle from 'remark-lint-unordered-list-marker-style'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-unordered-list-marker-style'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintUnorderedListMarkerStyle)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -196,5 +205,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

@@ -219,6 +228,8 @@ [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
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -225,0 +236,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc