remark-lint-checkbox-character-style
Advanced tools
Comparing version 4.1.2 to 5.0.0
@@ -1,36 +0,24 @@ | ||
export default remarkLintCheckboxCharacterStyle | ||
export type Root = import('mdast').Root | ||
export default remarkLintCheckboxCharacterStyle; | ||
export type Root = import('mdast').Root; | ||
/** | ||
* Configuration. | ||
*/ | ||
export type Options = Styles | 'consistent'; | ||
/** | ||
* Styles. | ||
*/ | ||
export type Styles = { | ||
/** | ||
* Preferred style to use for checked checkboxes (default: `'consistent'`). | ||
*/ | ||
checked?: 'x' | 'X' | 'consistent' | ||
/** | ||
* Preferred style to use for unchecked checkboxes (default: `'consistent'`). | ||
*/ | ||
unchecked?: ' ' | '\t' | 'consistent' | ||
} | ||
/** | ||
* Options. | ||
*/ | ||
export type Options = 'consistent' | Styles | ||
declare const remarkLintCheckboxCharacterStyle: 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 | ||
> | ||
/** | ||
* Preferred style to use for checked checkboxes (default: `'consistent'`). | ||
*/ | ||
checked?: 'X' | 'x' | 'consistent' | null | undefined; | ||
/** | ||
* Preferred style to use for unchecked checkboxes (default: `'consistent'`). | ||
*/ | ||
unchecked?: '\t' | ' ' | 'consistent' | null | undefined; | ||
}; | ||
declare const remarkLintCheckboxCharacterStyle: { | ||
(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 |
275
index.js
/** | ||
* remark-lint rule to warn when list item checkboxes violate a given | ||
* style. | ||
* | ||
* ## What is this? | ||
* | ||
* This package checks the character used in checkboxes. | ||
* | ||
* ## When should I use this? | ||
@@ -6,20 +13,47 @@ * | ||
* consistent. | ||
* Task lists are a GFM feature enabled with | ||
* [`remark-gfm`][github-remark-gfm]. | ||
* | ||
* ## API | ||
* | ||
* The following options (default: `'consistent'`) are accepted: | ||
* ### `unified().use(remarkLintCheckboxCharacterStyle[, options])` | ||
* | ||
* * `Object` with the following fields: | ||
* * `checked` (`'x'`, `'X'`, or `'consistent'`, default: `'consistent'`) | ||
* — preferred character to use for checked checkboxes | ||
* * `unchecked` (`'·'` (a space), `'»'` (a tab), or `'consistent'`, | ||
* default: `'consistent'`) | ||
* — preferred character to use for unchecked checkboxes | ||
* * `'consistent'` | ||
* — detect the first used styles and warn when further checkboxes differ | ||
* Warn when list item checkboxes violate a given style. | ||
* | ||
* ###### Parameters | ||
* | ||
* * `options` ([`Options`][api-options], default: `'consistent'`) | ||
* — either preferred values or whether to detect the first styles | ||
* and warn for further differences | ||
* | ||
* ###### Returns | ||
* | ||
* Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
* | ||
* ### `Options` | ||
* | ||
* Configuration (TypeScript type). | ||
* | ||
* ###### Type | ||
* | ||
* ```ts | ||
* type Options = Styles | 'consistent' | ||
* ``` | ||
* | ||
* ### `Styles` | ||
* | ||
* Styles (TypeScript type). | ||
* | ||
* ###### Fields | ||
* | ||
* * `checked` (`'X'`, `'x'`, or `'consistent'`, default: `'consistent'`) | ||
* — preferred style to use for checked checkboxes | ||
* * `unchecked` (`'␉'` (a tab), `'␠'` (a space), or `'consistent'`, default: | ||
* `'consistent'`) | ||
* — preferred style to use for unchecked checkboxes | ||
* | ||
* ## Recommendation | ||
* | ||
* It’s recommended to set `options.checked` to `'x'` (a lowercase X) as it | ||
* prevents an extra keyboard press and `options.unchecked` to `'·'` (a space) | ||
* prevents an extra keyboard press and `options.unchecked` to `'␠'` (a space) | ||
* to make all checkboxes align. | ||
@@ -29,62 +63,70 @@ * | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) | ||
* formats checked checkboxes using `'x'` (lowercase X) and unchecked checkboxes | ||
* using `'·'` (a space). | ||
* [`remark-stringify`][github-remark-stringify] formats checked checkboxes | ||
* using `'x'` (lowercase X) and unchecked checkboxes using `'␠'` (a space). | ||
* | ||
* [api-options]: #options | ||
* [api-remark-lint-checkbox-character-style]: #unifieduseremarklintcheckboxcharacterstyle-options | ||
* [api-styles]: #styles | ||
* [github-remark-gfm]: https://github.com/remarkjs/remark-gfm | ||
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify | ||
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
* | ||
* @module checkbox-character-style | ||
* @summary | ||
* remark-lint rule to warn when list item checkboxes violate a given | ||
* style. | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* | ||
* @example | ||
* {"name": "ok.md", "config": {"checked": "x"}, "gfm": true} | ||
* {"config": {"checked": "x"}, "gfm": true, "name": "ok-x.md"} | ||
* | ||
* - [x] List item | ||
* - [x] List item | ||
* - [x] Mercury. | ||
* - [x] Venus. | ||
* | ||
* @example | ||
* {"name": "ok.md", "config": {"checked": "X"}, "gfm": true} | ||
* {"config": {"checked": "X"}, "gfm": true, "name": "ok-x-upper.md"} | ||
* | ||
* - [X] List item | ||
* - [X] List item | ||
* - [X] Mercury. | ||
* - [X] Venus. | ||
* | ||
* @example | ||
* {"name": "ok.md", "config": {"unchecked": " "}, "gfm": true} | ||
* {"config": {"unchecked": " "}, "gfm": true, "name": "ok-space.md"} | ||
* | ||
* - [ ] List item | ||
* - [ ] List item | ||
* - [ ]·· | ||
* - [ ] Mercury. | ||
* - [ ] Venus. | ||
* - [ ]␠␠ | ||
* - [ ] | ||
* | ||
* @example | ||
* {"name": "ok.md", "config": {"unchecked": "\t"}, "gfm": true} | ||
* {"config": {"unchecked": "\t"}, "gfm": true, "name": "ok-tab.md"} | ||
* | ||
* - [»] List item | ||
* - [»] List item | ||
* - [␉] Mercury. | ||
* - [␉] Venus. | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "input", "gfm": true} | ||
* {"label": "input", "gfm": true, "name": "not-ok-default.md"} | ||
* | ||
* - [x] List item | ||
* - [X] List item | ||
* - [ ] List item | ||
* - [»] List item | ||
* - [x] Mercury. | ||
* - [X] Venus. | ||
* - [ ] Earth. | ||
* - [␉] Mars. | ||
* @example | ||
* {"label": "output", "gfm": true, "name": "not-ok-default.md"} | ||
* | ||
* 2:5: Unexpected checked checkbox value `X`, expected `x` | ||
* 4:5: Unexpected unchecked checkbox value `\t`, expected ` ` | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "output", "gfm": true} | ||
* {"config": "🌍", "label": "output", "name": "not-ok-option.md", "positionless": true} | ||
* | ||
* 2:5: Checked checkboxes should use `x` as a marker | ||
* 4:5: Unchecked checkboxes should use ` ` as a marker | ||
* 1:1: Unexpected value `🌍` for `options`, expected an object or `'consistent'` | ||
* | ||
* @example | ||
* {"config": {"unchecked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true} | ||
* {"config": {"unchecked": "🌍"}, "label": "output", "name": "not-ok-option-unchecked.md", "positionless": true} | ||
* | ||
* 1:1: Incorrect unchecked checkbox marker `💩`: use either `'\t'`, or `' '` | ||
* 1:1: Unexpected value `🌍` for `options.unchecked`, expected `'\t'`, `' '`, or `'consistent'` | ||
* | ||
* @example | ||
* {"config": {"checked": "💩"}, "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true} | ||
* {"config": {"checked": "🌍"}, "label": "output", "name": "not-ok-option-checked.md", "positionless": true} | ||
* | ||
* 1:1: Incorrect checked checkbox marker `💩`: use either `'x'`, or `'X'` | ||
* 1:1: Unexpected value `🌍` for `options.checked`, expected `'X'`, `'x'`, or `'consistent'` | ||
*/ | ||
@@ -97,16 +139,18 @@ | ||
/** | ||
* @typedef {Styles | 'consistent'} Options | ||
* Configuration. | ||
* | ||
* @typedef Styles | ||
* Styles. | ||
* @property {'x' | 'X' | 'consistent'} [checked='consistent'] | ||
* @property {'X' | 'x' | 'consistent' | null | undefined} [checked='consistent'] | ||
* Preferred style to use for checked checkboxes (default: `'consistent'`). | ||
* @property {' ' | '\t' | 'consistent'} [unchecked='consistent'] | ||
* @property {'\t' | ' ' | 'consistent' | null | undefined} [unchecked='consistent'] | ||
* Preferred style to use for unchecked checkboxes (default: `'consistent'`). | ||
* | ||
* @typedef {'consistent' | Styles} Options | ||
* Options. | ||
*/ | ||
import {phrasing} from 'mdast-util-phrasing' | ||
import {lintRule} from 'unified-lint-rule' | ||
import {visit} from 'unist-util-visit' | ||
import {pointStart} from 'unist-util-position' | ||
import {SKIP, visitParents} from 'unist-util-visit-parents' | ||
import {VFileMessage} from 'vfile-message' | ||
@@ -118,34 +162,61 @@ const remarkLintCheckboxCharacterStyle = lintRule( | ||
}, | ||
/** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
(tree, file, option = 'consistent') => { | ||
/** | ||
* @param {Root} tree | ||
* Tree. | ||
* @param {Options | null | undefined} [options] | ||
* Configuration (optional). | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function (tree, file, options) { | ||
const value = String(file) | ||
/** @type {'x' | 'X' | 'consistent'} */ | ||
let checked = 'consistent' | ||
/** @type {' ' | '\x09' | 'consistent'} */ | ||
let unchecked = 'consistent' | ||
/** @type {'X' | 'x' | undefined} */ | ||
let checkedExpected | ||
/** @type {VFileMessage | undefined} */ | ||
let checkedConsistentCause | ||
/** @type {'\t' | ' ' | undefined} */ | ||
let uncheckedExpected | ||
/** @type {VFileMessage | undefined} */ | ||
let uncheckedConsistentCause | ||
if (typeof option === 'object') { | ||
checked = option.checked || 'consistent' | ||
unchecked = option.unchecked || 'consistent' | ||
} | ||
if (options === null || options === undefined || options === 'consistent') { | ||
// Empty. | ||
} else if (typeof options === 'object') { | ||
if (options.checked === 'X' || options.checked === 'x') { | ||
checkedExpected = options.checked | ||
} else if (options.checked && options.checked !== 'consistent') { | ||
file.fail( | ||
'Unexpected value `' + | ||
options.checked + | ||
"` for `options.checked`, expected `'X'`, `'x'`, or `'consistent'`" | ||
) | ||
} | ||
if (unchecked !== 'consistent' && unchecked !== ' ' && unchecked !== '\t') { | ||
if (options.unchecked === '\t' || options.unchecked === ' ') { | ||
uncheckedExpected = options.unchecked | ||
} else if (options.unchecked && options.unchecked !== 'consistent') { | ||
file.fail( | ||
'Unexpected value `' + | ||
options.unchecked + | ||
"` for `options.unchecked`, expected `'\\t'`, `' '`, or `'consistent'`" | ||
) | ||
} | ||
} else { | ||
file.fail( | ||
'Incorrect unchecked checkbox marker `' + | ||
unchecked + | ||
"`: use either `'\\t'`, or `' '`" | ||
'Unexpected value `' + | ||
options + | ||
"` for `options`, expected an object or `'consistent'`" | ||
) | ||
} | ||
if (checked !== 'consistent' && checked !== 'x' && checked !== 'X') { | ||
file.fail( | ||
'Incorrect checked checkbox marker `' + | ||
checked + | ||
"`: use either `'x'`, or `'X'`" | ||
) | ||
} | ||
visitParents(tree, function (node, parents) { | ||
// Do not walk into phrasing. | ||
if (phrasing(node)) { | ||
return SKIP | ||
} | ||
visit(tree, 'listItem', (node) => { | ||
if (node.type !== 'listItem') return | ||
const head = node.children[0] | ||
const point = pointStart(head) | ||
const headStart = pointStart(head) | ||
@@ -155,5 +226,6 @@ // Exit early for items without checkbox. | ||
if ( | ||
!head || | ||
!headStart || | ||
typeof node.checked !== 'boolean' || | ||
!head || | ||
typeof point.offset !== 'number' | ||
typeof headStart.offset !== 'number' | ||
) { | ||
@@ -164,31 +236,56 @@ return | ||
// Move back to before `] `. | ||
point.offset -= 2 | ||
point.column -= 2 | ||
headStart.offset -= 2 | ||
headStart.column -= 2 | ||
// Assume we start with a checkbox, because well, `checked` is set. | ||
const match = /\[([\t Xx])]/.exec( | ||
value.slice(point.offset - 2, point.offset + 1) | ||
value.slice(headStart.offset - 2, headStart.offset + 1) | ||
) | ||
// Failsafe to make sure we don‘t crash if there actually isn’t a checkbox. | ||
/* c8 ignore next */ | ||
/* c8 ignore next 2 -- failsafe so we don’t crash if there actually isn’t | ||
* a checkbox. */ | ||
if (!match) return | ||
const style = node.checked ? checked : unchecked | ||
const actual = match[1] | ||
const actualDisplay = actual === '\t' ? '\\t' : actual | ||
const expected = node.checked ? checkedExpected : uncheckedExpected | ||
const expectedDisplay = expected === '\t' ? '\\t' : expected | ||
if (style === 'consistent') { | ||
if (!expected) { | ||
const cause = new VFileMessage( | ||
(node.checked ? 'C' : 'Unc') + | ||
"hecked checkbox style `'" + | ||
actualDisplay + | ||
"'` first defined for `'consistent'` here", | ||
{ | ||
ancestors: [...parents, node], | ||
place: headStart, | ||
ruleId: 'checkbox-character-style', | ||
source: 'remark-lint' | ||
} | ||
) | ||
if (node.checked) { | ||
// @ts-expect-error: valid marker. | ||
checked = match[1] | ||
checkedExpected = /** @type {'X' | 'x'} */ (actual) | ||
checkedConsistentCause = cause | ||
} else { | ||
// @ts-expect-error: valid marker. | ||
unchecked = match[1] | ||
uncheckedExpected = /** @type {'\t' | ' '} */ (actual) | ||
uncheckedConsistentCause = cause | ||
} | ||
} else if (match[1] !== style) { | ||
} else if (actual !== expected) { | ||
file.message( | ||
(node.checked ? 'Checked' : 'Unchecked') + | ||
' checkboxes should use `' + | ||
style + | ||
'` as a marker', | ||
point | ||
'Unexpected ' + | ||
(node.checked ? '' : 'un') + | ||
'checked checkbox value `' + | ||
actualDisplay + | ||
'`, expected `' + | ||
expectedDisplay + | ||
'`', | ||
{ | ||
ancestors: [...parents, node], | ||
cause: node.checked | ||
? checkedConsistentCause | ||
: uncheckedConsistentCause, | ||
place: headStart | ||
} | ||
) | ||
@@ -195,0 +292,0 @@ } |
{ | ||
"name": "remark-lint-checkbox-character-style", | ||
"version": "4.1.2", | ||
"version": "5.0.0", | ||
"description": "remark-lint rule to warn when list item checkboxes violate a given style", | ||
"license": "MIT", | ||
"keywords": [ | ||
"checkbox", | ||
"lint", | ||
"list", | ||
"remark", | ||
"lint", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"rule", | ||
"remark-lint-rule", | ||
"checkbox", | ||
"style", | ||
"task", | ||
"list" | ||
"task" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/remarkjs/remark-lint", | ||
"directory": "packages/remark-lint-checkbox-character-style" | ||
}, | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-checkbox-character-style", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
@@ -28,27 +25,33 @@ "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", | ||
"unified": "^10.0.0", | ||
"unified-lint-rule": "^2.0.0", | ||
"unist-util-position": "^4.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"@types/mdast": "^4.0.0", | ||
"mdast-util-phrasing": "^4.0.0", | ||
"unified-lint-rule": "^3.0.0", | ||
"unist-util-position": "^5.0.0", | ||
"unist-util-visit-parents": "^6.0.0", | ||
"vfile-message": "^4.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" | ||
} | ||
} | ||
} |
311
readme.md
@@ -5,11 +5,11 @@ <!--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 item checkboxes violate a given | ||
[`remark-lint`][github-remark-lint] rule to warn when list item checkboxes violate a given | ||
style. | ||
@@ -19,21 +19,21 @@ | ||
* [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(remarkLintCheckboxCharacterStyle[, config])`](#unifieduseremarklintcheckboxcharacterstyle-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(remarkLintCheckboxCharacterStyle[, options])`](#unifieduseremarklintcheckboxcharacterstyle-options) | ||
* [`Options`](#options) | ||
* [`Styles`](#styles) | ||
* [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 character used in checkboxes. | ||
@@ -44,8 +44,10 @@ ## When should I use this? | ||
consistent. | ||
Task lists are a GFM feature enabled with | ||
[`remark-gfm`][github-remark-gfm]. | ||
## Presets | ||
This rule is included in the following presets: | ||
This plugin is included in the following presets: | ||
| Preset | Setting | | ||
| Preset | Options | | ||
| - | - | | ||
@@ -56,4 +58,5 @@ | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` | | ||
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]: | ||
@@ -64,13 +67,13 @@ ```sh | ||
In Deno with [`esm.sh`][esmsh]: | ||
In Deno with [`esm.sh`][esm-sh]: | ||
```js | ||
import remarkLintCheckboxCharacterStyle from 'https://esm.sh/remark-lint-checkbox-character-style@4' | ||
import remarkLintCheckboxCharacterStyle from 'https://esm.sh/remark-lint-checkbox-character-style@5' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
In browsers with [`esm.sh`][esm-sh]: | ||
```html | ||
<script type="module"> | ||
import remarkLintCheckboxCharacterStyle from 'https://esm.sh/remark-lint-checkbox-character-style@4?bundle' | ||
import remarkLintCheckboxCharacterStyle from 'https://esm.sh/remark-lint-checkbox-character-style@5?bundle' | ||
</script> | ||
@@ -84,18 +87,20 @@ ``` | ||
```js | ||
import remarkLint from 'remark-lint' | ||
import remarkLintCheckboxCharacterStyle from 'remark-lint-checkbox-character-style' | ||
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 remarkLintCheckboxCharacterStyle from 'remark-lint-checkbox-character-style' | ||
main() | ||
const file = await read('example.md') | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintCheckboxCharacterStyle) | ||
.process(await read('example.md')) | ||
await unified() | ||
.use(remarkParse) | ||
.use(remarkLint) | ||
.use(remarkLintCheckboxCharacterStyle) | ||
.use(remarkStringify) | ||
.process(file) | ||
console.error(reporter(file)) | ||
} | ||
console.error(reporter(file)) | ||
``` | ||
@@ -106,3 +111,3 @@ | ||
```sh | ||
remark --use remark-lint --use remark-lint-checkbox-character-style example.md | ||
remark --frail --use remark-lint --use remark-lint-checkbox-character-style . | ||
``` | ||
@@ -128,24 +133,48 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintCheckboxCharacterStyle`. | ||
It exports the [TypeScript][typescript] types | ||
[`Options`][api-options] and | ||
[`Styles`][api-styles]. | ||
The default export is | ||
[`remarkLintCheckboxCharacterStyle`][api-remark-lint-checkbox-character-style]. | ||
### `unified().use(remarkLintCheckboxCharacterStyle[, config])` | ||
### `unified().use(remarkLintCheckboxCharacterStyle[, 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 list item checkboxes violate a given style. | ||
The following options (default: `'consistent'`) are accepted: | ||
###### Parameters | ||
* `Object` with the following fields: | ||
* `checked` (`'x'`, `'X'`, or `'consistent'`, default: `'consistent'`) | ||
— preferred character to use for checked checkboxes | ||
* `unchecked` (`'·'` (a space), `'»'` (a tab), or `'consistent'`, | ||
default: `'consistent'`) | ||
— preferred character to use for unchecked checkboxes | ||
* `'consistent'` | ||
— detect the first used styles and warn when further checkboxes differ | ||
* `options` ([`Options`][api-options], default: `'consistent'`) | ||
— either preferred values or whether to detect the first styles | ||
and warn for further differences | ||
###### Returns | ||
Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Type | ||
```ts | ||
type Options = Styles | 'consistent' | ||
``` | ||
### `Styles` | ||
Styles (TypeScript type). | ||
###### Fields | ||
* `checked` (`'X'`, `'x'`, or `'consistent'`, default: `'consistent'`) | ||
— preferred style to use for checked checkboxes | ||
* `unchecked` (`'␉'` (a tab), `'␠'` (a space), or `'consistent'`, default: | ||
`'consistent'`) | ||
— preferred style to use for unchecked checkboxes | ||
## Recommendation | ||
It’s recommended to set `options.checked` to `'x'` (a lowercase X) as it | ||
prevents an extra keyboard press and `options.unchecked` to `'·'` (a space) | ||
prevents an extra keyboard press and `options.unchecked` to `'␠'` (a space) | ||
to make all checkboxes align. | ||
@@ -155,9 +184,8 @@ | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify) | ||
formats checked checkboxes using `'x'` (lowercase X) and unchecked checkboxes | ||
using `'·'` (a space). | ||
[`remark-stringify`][github-remark-stringify] formats checked checkboxes | ||
using `'x'` (lowercase X) and unchecked checkboxes using `'␠'` (a space). | ||
## Examples | ||
##### `ok.md` | ||
##### `ok-x.md` | ||
@@ -168,7 +196,8 @@ When configured with `{ checked: 'x' }`. | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
```markdown | ||
- [x] List item | ||
- [x] List item | ||
- [x] Mercury. | ||
- [x] Venus. | ||
``` | ||
@@ -180,3 +209,3 @@ | ||
##### `ok.md` | ||
##### `ok-x-upper.md` | ||
@@ -187,7 +216,8 @@ When configured with `{ checked: 'X' }`. | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
```markdown | ||
- [X] List item | ||
- [X] List item | ||
- [X] Mercury. | ||
- [X] Venus. | ||
``` | ||
@@ -199,3 +229,3 @@ | ||
##### `ok.md` | ||
##### `ok-space.md` | ||
@@ -206,10 +236,9 @@ When configured with `{ unchecked: ' ' }`. | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
> 👉 **Note**: `·` represents a space. | ||
```markdown | ||
- [ ] List item | ||
- [ ] List item | ||
- [ ]·· | ||
- [ ] Mercury. | ||
- [ ] Venus. | ||
- [ ]␠␠ | ||
- [ ] | ||
@@ -222,3 +251,3 @@ ``` | ||
##### `ok.md` | ||
##### `ok-tab.md` | ||
@@ -229,9 +258,8 @@ When configured with `{ unchecked: '\t' }`. | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
> 👉 **Note**: `»` represents a tab. | ||
```markdown | ||
- [»] List item | ||
- [»] List item | ||
- [␉] Mercury. | ||
- [␉] Venus. | ||
``` | ||
@@ -243,15 +271,14 @@ | ||
##### `not-ok.md` | ||
##### `not-ok-default.md` | ||
###### In | ||
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]). | ||
> 👉 **Note**: this example uses | ||
> GFM ([`remark-gfm`][github-remark-gfm]). | ||
> 👉 **Note**: `»` represents a tab. | ||
```markdown | ||
- [x] List item | ||
- [X] List item | ||
- [ ] List item | ||
- [»] List item | ||
- [x] Mercury. | ||
- [X] Venus. | ||
- [ ] Earth. | ||
- [␉] Mars. | ||
``` | ||
@@ -262,9 +289,9 @@ | ||
```text | ||
2:5: Checked checkboxes should use `x` as a marker | ||
4:5: Unchecked checkboxes should use ` ` as a marker | ||
2:5: Unexpected checked checkbox value `X`, expected `x` | ||
4:5: Unexpected unchecked checkbox value `\t`, expected ` ` | ||
``` | ||
##### `not-ok.md` | ||
##### `not-ok-option.md` | ||
When configured with `{ unchecked: '💩' }`. | ||
When configured with `'🌍'`. | ||
@@ -274,8 +301,8 @@ ###### Out | ||
```text | ||
1:1: Incorrect unchecked checkbox marker `💩`: use either `'\t'`, or `' '` | ||
1:1: Unexpected value `🌍` for `options`, expected an object or `'consistent'` | ||
``` | ||
##### `not-ok.md` | ||
##### `not-ok-option-unchecked.md` | ||
When configured with `{ checked: '💩' }`. | ||
When configured with `{ unchecked: '🌍' }`. | ||
@@ -285,19 +312,33 @@ ###### Out | ||
```text | ||
1:1: Incorrect checked checkbox marker `💩`: use either `'x'`, or `'X'` | ||
1:1: Unexpected value `🌍` for `options.unchecked`, expected `'\t'`, `' '`, or `'consistent'` | ||
``` | ||
##### `not-ok-option-checked.md` | ||
When configured with `{ checked: '🌍' }`. | ||
###### Out | ||
```text | ||
1:1: Unexpected value `🌍` for `options.checked`, expected `'X'`, `'x'`, or `'consistent'` | ||
``` | ||
## 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-checkbox-character-style@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 | ||
@@ -308,54 +349,62 @@ 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-checkbox-character-style]: #unifieduseremarklintcheckboxcharacterstyle-options | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[api-styles]: #styles | ||
[coverage]: https://codecov.io/github/remarkjs/remark-lint | ||
[author]: https://wooorm.com | ||
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-checkbox-character-style.svg | ||
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
[downloads]: https://www.npmjs.com/package/remark-lint-checkbox-character-style | ||
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-checkbox-character-style.svg | ||
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[size]: https://bundlephobia.com/result?p=remark-lint-checkbox-character-style | ||
[badge-chat-url]: https://github.com/remarkjs/remark/discussions | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint | ||
[collective]: https://opencollective.com/unified | ||
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-checkbox-character-style.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-checkbox-character-style | ||
[chat]: https://github.com/remarkjs/remark/discussions | ||
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg | ||
[unified]: https://github.com/unifiedjs/unified | ||
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg | ||
[remark]: https://github.com/remarkjs/remark | ||
[badge-funding-url]: https://opencollective.com/unified | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-checkbox-character-style | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[badge-size-url]: https://bundlejs.com/?q=remark-lint-checkbox-character-style | ||
[esmsh]: https://esm.sh | ||
[esm-sh]: https://esm.sh | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[health]: https://github.com/remarkjs/.github | ||
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[github-dotfiles-health]: https://github.com/remarkjs/.github | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[license]: https://github.com/remarkjs/remark-lint/blob/main/license | ||
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[author]: https://wooorm.com | ||
[github-remark-gfm]: https://github.com/remarkjs/remark-gfm | ||
[gfm]: https://github.com/remarkjs/remark-gfm | ||
[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 |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
20634
5
298
390
6
1
1
+ Addedmdast-util-phrasing@^4.0.0
+ Addedvfile-message@^4.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)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedunified@11.0.5(transitive)
+ Addedunified-lint-rule@3.0.0(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-position@5.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(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-position@4.0.4(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
Updatedunist-util-position@^5.0.0