unified plugin to make it a bit easier to create linting rules
npm install unified-lint-rule[![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]
[unified][github-unified] helper to help make lint rules.
* What is this?
* When should I use this?
* Install
* Use
* API
* lintRule(meta, rule)
* Label
* Meta
* Next
* Rule
* Severity
* Compatibility
* Contribute
* License
This package is a helper that makes it a bit easier to create linting rules.
You can use this package when you want to make custom lint rules.
This package is [ESM only][github-gist-esm].
In Node.js (version 16+),
install with [npm][npm-install]:
``sh`
npm install unified-lint-rule
In Deno with [esm.sh][esm-sh]:
`js`
import {lintRule} from 'https://esm.sh/unified-lint-rule@3'
In browsers with [esm.sh][esm-sh]:
`html`
`js
import {lintRule} from 'unified-lint-rule'
const remarkLintFileExtension = lintRule(
'remark-lint:file-extension',
function (tree, file, options) {
const ext = file.extname
const option = options || 'md'
if (ext && ext.slice(1) !== option) {
file.message('Incorrect extension: use ' + option + '')
}
}
)
export default remarkLintFileExtension
`
This package exports the identifier
[lintRule][api-lint-rule].Label
It exports the [TypeScript][typescript] types
[][api-label],Meta
[][api-meta],Next
[][api-next], andSeverity
[][api-severity].
There is no default export.
Create a plugin.
###### Parameters
* meta ([Meta][api-meta] or string)rule
— info or origin
* ([Rule][api-rule])
— rule
###### Returns
Plugin ([Plugin from unified][github-unified-plugin]).
Severity label (TypeScript type);
'off': 0, 'on' and warn: 1, 'error': 2.
###### Type
`ts`
type Label = 'error' | 'on' | 'off' | 'warn'
Rule metadata (TypeScript type).
###### Fields
* origin (string)url
— name of the lint rule
* (string, optional)
— link to documentation
Callback passed to rules (TypeScript type).
If the signature of a rule accepts a fourth argument,
the rule may perform asynchronous operations,
and must call it.
###### Parameters
* error (Error, optional)
— fatal error to stop linting
###### Returns
Nothing (undefined).
Rule (TypeScript type).
###### Parameters
* tree ([Node from unist][github-unist-node])file
— tree
* ([VFile][github-vfile])options
— file
* (unknown, optional)
— parameter
###### Returns
Nothing (Promise or undefined).
Severity number (TypeScript type);
0: 'off', 1: 'on' and warn, 2: 'error'.
###### Type
`ts`
type Severity = 0 | 1 | 2
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
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,
unified-lint-rule@3,
compatible with Node.js 16.
See [contributing.md][github-dotfiles-contributing] in [remarkjs/.github][github-dotfiles-health] for wayssupport.md`][github-dotfiles-support] for ways to get help.
to get started.
See [
This project has a [code of conduct][github-dotfiles-coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
[MIT][file-license] © [Titus Wormer][author]
[api-label]: #label
[api-lint-rule]: #lintrulemeta-rule
[api-meta]: #meta
[api-next]: #next
[api-rule]: #rule
[api-severity]: #severity
[author]: https://wooorm.com
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint
[badge-downloads-image]: https://img.shields.io/npm/dm/unified-lint-rule.svg
[badge-downloads-url]: https://www.npmjs.com/package/unified-lint-rule
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg
[badge-funding-url]: https://opencollective.com/unified
[badge-size-image]: https://img.shields.io/bundlejs/size/unified-lint-rule
[badge-size-url]: https://bundlejs.com/?q=unified-lint-rule
[esm-sh]: https://esm.sh
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[github-dotfiles-health]: https://github.com/remarkjs/.github
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[github-unified]: https://github.com/unifiedjs/unified
[github-unified-plugin]: https://github.com/unifiedjs/unified#plugin
[github-unist-node]: https://github.com/syntax-tree/unist#node
[github-vfile]: https://github.com/vfile/vfile
[npm-install]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org