unified-lint-rule

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

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
unified-lint-rule
3.0.017 days ago7 years agoMinified + gzip package size for unified-lint-rule in KB

Readme

unified-lint-rule
!Buildbadge-build-imagebadge-build-url !Coveragebadge-coverage-imagebadge-coverage-url !Downloadsbadge-downloads-imagebadge-downloads-url !Sizebadge-size-imagebadge-size-url !Sponsorsbadge-funding-sponsors-imagebadge-funding-url !Backersbadge-funding-backers-imagebadge-funding-url !Chatbadge-chat-imagebadge-chat-url
unifiedgithub-unified helper to help make lint rules.

Contents

lintRule(meta, rule)
Label Meta Rule Severity

What is this?

This package is a helper that makes it a bit easier to create linting rules.

When should I use this?

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

Install

This package is ESM onlygithub-gist-esm. In Node.js (version 16+), install with npmnpm-install:
npm install unified-lint-rule

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

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

Use

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

API

This package exports the identifier lintRuleapi-lint-rule. It exports the TypeScripttypescript types Labelapi-label, Metaapi-meta, and Severityapi-severity. There is no default export.

lintRule(meta, rule)

Create a plugin.
Parameters
— info or origin — rule
Returns
Plugin (Plugin from unifiedgithub-unified-plugin).

Label

Severity label (TypeScript type); 'off': 0, 'on' and warn: 1, 'error': 2.
Type
type Label = 'error' | 'on' | 'off' | 'warn'

Meta

Rule metadata (TypeScript type).
Fields
  • origin (string)
— name of the lint rule
  • url (string, optional)
— link to documentation

Rule

Rule (TypeScript type).
Parameters
— tree — file
  • options (any, optional)
— parameter
Returns
Nothing (Promise<undefined> or undefined).

Severity

Severity number (TypeScript type); 0: 'off', 1: 'on' and warn, 2: 'error'.
Type
type Severity = 0 | 1 | 2

Compatibility

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.

Contribute

See contributing.mdgithub-dotfiles-contributing in remarkjs/.githubgithub-dotfiles-health for ways to get started. See support.mdgithub-dotfiles-support for ways to get help.
This project has a code of conductgithub-dotfiles-coc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITfile-license © Titus Wormerauthor