unified-message-control

Enable, disable, and ignore messages from unified processors

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
unified-message-control
504.0.0a year ago5 years agoMinified + gzip package size for unified-message-control in KB

Readme

unified-message-control
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Enable, disable, and ignore messages with unifiedunified.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm install unified-message-control
## Use

Say we have the following file, `example.md`:

```markdown
<!--foo ignore-->

## Heading

And our script, example.js, looks as follows:
import {toVFile} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {commentMarker} from 'mdast-comment-marker'
import {unified} from 'unified'
import unifiedMessageControl from 'unified-message-control'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'

toVFile.read('example.md').then((file) => {
  unified()
    .use(remarkParse)
    .use(remarkStringify)
    .use(() => (tree, file) => {
      file.message('Whoops!', tree.children[1], 'foo:thing')
    })
    .use(unifiedMessageControl, {
      name: 'foo',
      marker: commentMarker,
      test: 'html'
    })
    .process(file)
    .then((file) => {
      console.error(reporter(file))
    })
})

Now, running node example yields:
example.md: no issues found

API

This package exports the following identifiers: messageControl. There is no default export.

unified().use(messageControl, options)

Let comment markers control messages from certain sources.
options
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-istest.
options.marker
Parse a possible marker to a comment marker objectmarker (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__

Contribute

See contributing.mdcontributing in unifiedjs/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor