unified

Project: unifiedjs/unified-message-control

Package: unified-message-control@4.0.0

  1. Dependents: 0
  2. Enable, disable, and ignore messages from unified processors
  1. unified 169
  2. marker 12
  3. comment 7
  4. unified-plugin 6
  5. message 6
  6. control 2

unified-message-control

Build Coverage Downloads Size Sponsors Backers Chat

unified utility to enable, disable, and ignore messages.

Contents

What is this?

This is a lego block that is meant to be extended, such as is done by remark-message-control, so that lint messages can be controlled from content.

When should I use this?

You can use this if you’re building an ecosystem like remark for some different content type, and want to let authors control messages from that content.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:

npm install unified-message-control

In Deno with esm.sh:

import messageControl from 'https://esm.sh/unified-message-control@4'

In browsers with esm.sh:

<script type="module">
  import messageControl from 'https://esm.sh/unified-message-control@4?bundle'
</script>

Use

Say our document example.md contains:

<!--foo ignore-->

## Heading

…and our module example.js looks as follows:

import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {commentMarker} from 'mdast-comment-marker'
import {unified} from 'unified'
import messageControl from 'unified-message-control'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkStringify)
  .use(() => (tree, file) => {
    file.message('Whoops!', tree.children[1], 'foo:thing')
  })
  .use(messageControl, {
    name: 'foo',
    marker: commentMarker,
    test: 'html'
  })
  .process(file)

console.error(reporter(file))

…now running node example.js yields:

example.md: no issues found

API

This package exports no identifiers. The default export is messageControl.

unified().use(messageControl, options)

Let comment markers control messages from certain sources.

options

Configuration.

options.name

Name of markers that can control the message sources (string).

For example, {name: 'alpha'} controls alpha markers:

<!--alpha ignore-->
options.test

Test for possible markers (Function, string, Object, or Array<Test>). See unist-util-is.

options.marker

Parse a possible marker to a comment marker object (Function). If the possible marker actually isn’t a marker, should return null.

options.known

List of allowed ruleIds (Array<string>, optional). When given, a warning is shown when someone tries to control an unknown rule.

For example, {name: 'alpha', known: ['bravo']} results in a warning if charlie is configured:

<!--alpha ignore charlie-->
options.reset

Whether to treat all messages as turned off initially (boolean, default: false).

options.enable

List of ruleIds to initially turn on if reset: true (Array<string>, optional). By default (reset: false), all rules are turned on.

options.disable

List of ruleIds to turn on if reset: false (Array<string>, optional).

options.sources

Sources that can be controlled with name markers (string or Array<string>, default: options.name)

Markers

disable

The disable keyword turns off all messages of the given rule identifiers. When without identifiers, all messages are turned off.

For example, to turn off certain messages:

<!--lint disable list-item-bullet-indent strong-marker-->

*   **foo**

A paragraph, and now another list.

  * __bar__
enable

The enable keyword turns on all messages of the given rule identifiers. When without identifiers, all messages are turned on.

For example, to enable certain messages:

<!--lint enable strong-marker-->

**foo** and __bar__.
ignore

The ignore keyword turns off all messages of the given ruleIds occurring in the following node. When without ruleIds, all messages are ignored.

After the end of the following node, messages are turned on again.

For example, to turn off certain messages for the next node:

<!--lint ignore list-item-bullet-indent strong-marker-->

*   **foo**
    * __bar__

Types

This package is fully typed with TypeScript. It exports the additional types Marker, MarkerParser, and Options.

Compatibility

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+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.

Contribute

See contributing.md in unifiedjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer