remark-lint/packages/remark-lint-no-undefined-references
2023-12-15 12:57:49 +01:00
..
.npmrc Refactor docs 2023-12-13 16:54:41 +01:00
index.js Refactor more code, improve small things 2023-12-15 12:57:49 +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 tsconfig.jsons 2023-11-09 15:58:43 +01:00

remark-lint-no-undefined-references

Build Coverage Downloads Size Sponsors Backers Chat

remark-lint rule to warn when undefined definitions are referenced.

Contents

What is this?

This package checks that referenced definitions are defined.

When should I use this?

You can use this package to check for broken references.

Presets

This plugin is included in the following presets:

Preset Options
remark-preset-lint-recommended

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-lint-no-undefined-references

In Deno with esm.sh:

import remarkLintNoUndefinedReferences from 'https://esm.sh/remark-lint-no-undefined-references@4'

In browsers with esm.sh:

<script type="module">
  import remarkLintNoUndefinedReferences from 'https://esm.sh/remark-lint-no-undefined-references@4?bundle'
</script>

Use

On the API:

import remarkLint from 'remark-lint'
import remarkLintNoUndefinedReferences from 'remark-lint-no-undefined-references'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintNoUndefinedReferences)
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))

On the CLI:

remark --frail --use remark-lint --use remark-lint-no-undefined-references .

On the CLI in a config file (here a package.json):

 …
 "remarkConfig": {
   "plugins": [
     …
     "remark-lint",
+    "remark-lint-no-undefined-references",
     …
   ]
 }
 …

API

This package exports no identifiers. It exports the TypeScript type Options. The default export is remarkLintNoUndefinedReferences.

unified().use(remarkLintNoUndefinedReferences[, options])

Warn when undefined definitions are referenced.

Parameters
  • options (Options, optional) — configuration
Returns

Transform (Transformer from unified).

Options

Configuration (TypeScript type).

Fields
  • allow (Array<RegExp | string>, optional) — list of values to allow between [ and ]

Recommendation

Shortcut references use an implicit syntax that could also occur as plain text. To illustrate, it is reasonable to expect an author adding […] to abbreviate some text somewhere in a document:

> Some […] quote.

This isnt a problem, but it might become one when an author later adds a definition:

Some new text […][]

[…]: #read-more

The second author might expect only their newly added text to form a link, but their changes also result in a link for the text by the first author.

Examples

ok.md
In
[foo][]

Just a [ bracket.

Typically, youd want to use escapes (with a backslash: \\) to escape what
could turn into a \[reference otherwise].

Just two braces cant link: [].

[foo]: https://example.com
Out

No messages.

ok-allow.md

When configured with { allow: [ '...', '…' ] }.

In
> Eliding a portion of a quoted passage […] is acceptable.
Out

No messages.

ok-allow.md

When configured with { allow: [ 'a', { source: '^b\\.' } ] }.

In
[foo][b.c]

[bar][a]

Matching is case-insensitive: [bar][B.C]
Out

No messages.

not-ok.md
In
[bar]

[baz][]

[text][qux]

Spread [over
lines][]

> in [a
> block quote][]

[asd][a

Can include [*emphasis*].

Multiple pairs: [a][b][c].
Out
1:1-1:6: Found reference to undefined definition
3:1-3:8: Found reference to undefined definition
5:1-5:12: Found reference to undefined definition
7:8-8:9: Found reference to undefined definition
10:6-11:17: Found reference to undefined definition
13:1-13:6: Found reference to undefined definition
15:13-15:25: Found reference to undefined definition
17:17-17:23: Found reference to undefined definition
17:23-17:26: Found reference to undefined definition
not-ok.md

When configured with { allow: [ 'a', { source: '^b\\.' } ] }.

In
[foo][a.c]

[bar][b]
Out
1:1-1:11: Found reference to undefined definition
3:1-3:9: Found reference to undefined definition

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, remark-lint-no-undefined-references@4, 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