unified-lint-rule

unified plugin to make it a bit easier to create linting rules

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
unified-lint-rule
905152.1.210 months ago7 years agoMinified + gzip package size for unified-lint-rule in KB

Readme

unified-lint-rule
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
unified plugin to help make lint rules.
See the monorepo readme
mono for more info on remark lint.

Contents

*   [`lintRule(origin|meta, rule)`](#lintruleoriginmeta-rule)

What is this?

This package is a unified plugin that makes it a bit easier to create linting rules.
unified is a project that transforms content with abstract syntax trees (ASTs). This is a plugin that make it easier to inspect trees.

When should I use this?

You can use this package when you want to make custom lint rules.

Install

This package is ESM onlyesm. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
npm install unified-lint-rule

In Deno with esm.shesmsh:
import {lintRule} from 'https://esm.sh/unified-lint-rule@2'

In browsers with esm.shesmsh:
<script type="module">
  import {lintRule} from 'https://esm.sh/unified-lint-rule@2?bundle'
</script>

Use

import {lintRule} from 'unified-lint-rule'

const remarkLintFileExtension = lintRule(
  'remark-lint:file-extension',
  (tree, file, option = 'md') => {
    var ext = file.extname

    if (ext && ext.slice(1) !== option) {
      file.message('Incorrect extension: use `' + option + '`')
    }
  }
)

export default remarkLintFileExtension

API

This package exports the following identifier: lintRule. There is no default export.

lintRule(origin|meta, rule)

Create a plugin.
Parameters
  • origin (string)
— treated as a `meta` of `{origin}`
  • meta (Object)
— rule metadata
  • meta.origin (string)
— message origin, either a rule name (`'file-extension'`) or both
a rule source and name joined with `:` (`'remark-lint:file-extension'`)
  • meta.url (string, optional)
— URL to documentation for messages
  • rule (Function, optional)
— your code, like a transform function, except that an extra `option` is
passed
Returns
A unified plugin that handles all kinds of options (see Configureconfigure in the monorepo readme for how them).

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

Contribute

See contributing.mdcontributing in remarkjs/.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