remark-lint/packages/unified-lint-rule
2023-12-15 12:57:49 +01:00
..
lib Refactor more code, improve small things 2023-12-15 12:57:49 +01:00
.npmrc Refactor docs 2023-12-13 16:54:41 +01:00
index.js Refactor docs 2023-12-13 16:54:41 +01:00
package.json Refactor docs 2023-12-13 16:54:41 +01:00
readme.md Refactor docs 2023-12-13 16:54:41 +01:00
tsconfig.json Refactor tsconfigs to improve build perf 2023-05-16 10:54:35 +02:00

unified-lint-rule

Build Coverage Downloads Size Sponsors Backers Chat

unified helper to help make lint rules.

Contents

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 only. In Node.js (version 16+), install with npm:

npm install unified-lint-rule

In Deno with esm.sh:

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

In browsers with esm.sh:

<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',
  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 lintRule. It exports the TypeScript types Meta and RuleMeta. There is no default export.

lintRule(meta, rule)

Create a plugin.

Parameters
  • meta (Meta or string) — info or origin
  • rule (Rule) — rule
Returns

Plugin (Plugin from unified).

Meta

Rule metadata (TypeScript type).

Fields
  • origin (string) — name of the lint rule
  • url (string, optional) — link to documentation

Rule

Rule (TypeScript type).

Parameters
Returns

Nothing (Promise<undefined> or undefined).

RuleMeta

Deprecated.

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@2, compatible with Node.js 12.

Contribute

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