Socket
Socket
Sign inDemoInstall

remark-lint-checkbox-character-style

Package Overview
Dependencies
16
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 4.0.0

index.d.ts

178

index.js

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

*
* @example {"name": "ok.md", "setting": {"checked": "x"}, "gfm": true}
* @example
* {"name": "ok.md", "setting": {"checked": "x"}, "gfm": true}
*

@@ -35,3 +36,4 @@ * - [x] List item

*
* @example {"name": "ok.md", "setting": {"checked": "X"}, "gfm": true}
* @example
* {"name": "ok.md", "setting": {"checked": "X"}, "gfm": true}
*

@@ -41,3 +43,4 @@ * - [X] List item

*
* @example {"name": "ok.md", "setting": {"unchecked": " "}, "gfm": true}
* @example
* {"name": "ok.md", "setting": {"unchecked": " "}, "gfm": true}
*

@@ -49,3 +52,4 @@ * - [ ] List item

*
* @example {"name": "ok.md", "setting": {"unchecked": "\t"}, "gfm": true}
* @example
* {"name": "ok.md", "setting": {"unchecked": "\t"}, "gfm": true}
*

@@ -55,3 +59,4 @@ * - [»] List item

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

@@ -63,3 +68,4 @@ * - [x] List item

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

@@ -69,7 +75,9 @@ * 2:5: Checked checkboxes should use `x` as a marker

*
* @example {"setting": {"unchecked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true}
* @example
* {"setting": {"unchecked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true}
*
* 1:1: Incorrect unchecked checkbox marker `💩`: use either `'\t'`, or `' '`
*
* @example {"setting": {"checked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true}
* @example
* {"setting": {"checked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true}
*

@@ -79,91 +87,97 @@ * 1:1: Incorrect checked checkbox marker `💩`: use either `'x'`, or `'X'`

'use strict'
/**
* @typedef {import('mdast').Root} Root
*
* @typedef Styles
* @property {'x'|'X'|'consistent'} [checked='consistent']
* @property {' '|'\x09'|'consistent'} [unchecked='consistent']
*
* @typedef {'consistent'|Styles} 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'
module.exports = rule(
const remarkLintCheckboxCharacterStyle = lintRule(
'remark-lint:checkbox-character-style',
checkboxCharacterStyle
)
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
const value = String(file)
/** @type {'x'|'X'|'consistent'} */
let checked = 'consistent'
/** @type {' '|'\x09'|'consistent'} */
let unchecked = 'consistent'
var start = position.start
var end = position.end
if (typeof option === 'object') {
checked = option.checked || 'consistent'
unchecked = option.unchecked || 'consistent'
}
var checked = {x: true, X: true}
var unchecked = {' ': true, '\t': true}
var types = {true: 'checked', false: 'unchecked'}
if (unchecked !== 'consistent' && unchecked !== ' ' && unchecked !== '\t') {
file.fail(
'Incorrect unchecked checkbox marker `' +
unchecked +
"`: use either `'\\t'`, or `' '`"
)
}
function checkboxCharacterStyle(tree, file, option) {
var contents = String(file)
var preferred = typeof option === 'object' ? option : {}
if (preferred.unchecked && unchecked[preferred.unchecked] !== true) {
file.fail(
'Incorrect unchecked checkbox marker `' +
preferred.unchecked +
"`: use either `'\\t'`, or `' '`"
)
}
if (preferred.checked && checked[preferred.checked] !== true) {
file.fail(
'Incorrect checked checkbox marker `' +
preferred.checked +
"`: use either `'x'`, or `'X'`"
)
}
visit(tree, 'listItem', visitor)
function visitor(node) {
var type
var point
var value
var style
var reason
// Exit early for items without checkbox.
if (typeof node.checked !== 'boolean' || generated(node)) {
return
if (checked !== 'consistent' && checked !== 'x' && checked !== 'X') {
file.fail(
'Incorrect checked checkbox marker `' +
checked +
"`: use either `'x'`, or `'X'`"
)
}
type = types[node.checked]
visit(tree, 'listItem', (node) => {
const head = node.children[0]
const point = pointStart(head)
/* istanbul ignore next - a list item cannot be checked and empty, according
* to GFM, but theoretically it makes sense to get the end if that were
* possible. */
point = node.children.length === 0 ? end(node) : start(node.children[0])
// Move back to before `] `.
point.offset -= 2
point.column -= 2
// Exit early for items without checkbox.
// A list item cannot be checked and empty, according to GFM.
if (
typeof node.checked !== 'boolean' ||
!head ||
typeof point.offset !== 'number'
) {
return
}
// Assume we start with a checkbox, because well, `checked` is set.
value = /\[([\t Xx])]/.exec(
contents.slice(point.offset - 2, point.offset + 1)
)
// Move back to before `] `.
point.offset -= 2
point.column -= 2
/* istanbul ignore if - failsafe to make sure we don‘t crash if there
* actually isn’t a checkbox. */
if (!value) return
// Assume we start with a checkbox, because well, `checked` is set.
const match = /\[([\t Xx])]/.exec(
value.slice(point.offset - 2, point.offset + 1)
)
style = preferred[type]
// Failsafe to make sure we don‘t crash if there actually isn’t a checkbox.
/* c8 ignore next */
if (!match) return
if (style) {
if (value[1] !== style) {
reason =
type.charAt(0).toUpperCase() +
type.slice(1) +
' checkboxes should use `' +
style +
'` as a marker'
const style = node.checked ? checked : unchecked
file.message(reason, point)
if (style === 'consistent') {
if (node.checked) {
// @ts-expect-error: valid marker.
checked = match[1]
} else {
// @ts-expect-error: valid marker.
unchecked = match[1]
}
} else if (match[1] !== style) {
file.message(
(node.checked ? 'Checked' : 'Unchecked') +
' checkboxes should use `' +
style +
'` as a marker',
point
)
}
} else {
preferred[type] = value[1]
}
})
}
}
)
export default remarkLintCheckboxCharacterStyle
{
"name": "remark-lint-checkbox-character-style",
"version": "3.0.0",
"version": "4.0.0",
"description": "remark-lint rule to warn when list item checkboxes violate a given style",

@@ -26,12 +26,27 @@ "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-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
}
}

@@ -163,2 +163,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][]:

@@ -170,2 +173,5 @@

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

@@ -197,10 +203,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 remarkLintCheckboxCharacterStyle from 'remark-lint-checkbox-character-style'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-checkbox-character-style'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintCheckboxCharacterStyle)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -223,5 +232,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

@@ -250,2 +259,4 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -252,0 +263,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