Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-final-definition

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-final-definition - npm Package Compare versions

Comparing version 3.1.2 to 4.0.0

index.d.ts.map

15

index.d.ts

@@ -1,7 +0,8 @@

export default remarkLintFinalDefinition
export type Root = import('mdast').Root
declare const remarkLintFinalDefinition: import('unified').Plugin<
void[] | [unknown],
import('mdast').Root,
import('mdast').Root
>
export default remarkLintFinalDefinition;
export type Nodes = import('mdast').Nodes;
export type Root = import('mdast').Root;
declare const remarkLintFinalDefinition: {
(config?: unknown): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined;
readonly name: string;
};
//# sourceMappingURL=index.d.ts.map
/**
* remark-lint rule to warn when definitions are used *in* the
* document instead of at the end.
*
* ## What is this?
*
* This package checks where definitions are placed.
*
* ## When should I use this?
*
* You can use this package to check that definitions are placed at the end of
* the document.
* You can use this package to check that definitions are consistently at the
* end of the document.
*
* ## API
*
* ### `unified().use(remarkLintFinalDefinition)`
*
* Warn when definitions are used *in* the document instead of at the end.
*
* ###### Parameters
*
* There are no options.
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ## Recommendation

@@ -17,50 +34,87 @@ *

*
* [api-remark-lint-final-definition]: #unifieduseremarklintfinaldefinition
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module final-definition
* @summary
* remark-lint rule to warn when definitions are used *in* the document
* instead of at the end.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md"}
*
* Paragraph.
* Mercury.
*
* [example]: http://example.com "Example Domain"
* [venus]: http://example.com
*
* @example
* {"name": "not-ok.md", "label": "input"}
* {"name": "ok.md"}
*
* Paragraph.
* [mercury]: http://example.com/mercury/
* [venus]: http://example.com/venus/
*
* [example]: http://example.com "Example Domain"
* @example
* {"name": "ok-html-comments.md"}
*
* Another paragraph.
* Mercury.
*
* [venus]: http://example.com/venus/
*
* <!-- HTML comments in markdown are ignored. -->
*
* [earth]: http://example.com/earth/
*
* @example
* {"name": "not-ok.md", "label": "output"}
* {"name": "ok-mdx-comments.mdx", "mdx": true}
*
* 3:1-3:47: Move definitions to the end of the file (after the node at line `5`)
* Mercury.
*
* [venus]: http://example.com/venus/
*
* {/* Comments in expressions in MDX are ignored. *␀/}
*
* [earth]: http://example.com/earth/
*
* @example
* {"name": "ok-comments.md"}
* {"label": "input", "name": "not-ok.md"}
*
* Paragraph.
* Mercury.
*
* [example-1]: http://example.com/one/
* [venus]: https://example.com/venus/
*
* <!-- Comments are fine between and after definitions -->
* Earth.
* @example
* {"label": "output", "name": "not-ok.md"}
*
* [example-2]: http://example.com/two/
* 3:1-3:36: Unexpected definition before last content, expected definitions after line `5`
*
* @example
* {"gfm": true, "label": "input", "name": "gfm.md"}
*
* Mercury.
*
* [^venus]:
* **Venus** is the second planet from
* the Sun.
*
* Earth.
* @example
* {"gfm": true, "label": "output", "name": "gfm.md"}
*
* 3:1-5:13: Unexpected footnote definition before last content, expected definitions after line `7`
*/
/**
* @typedef {import('mdast').Nodes} Nodes
* @typedef {import('mdast').Root} Root
*/
/// <reference types="mdast-util-mdx" />
import {ok as assert} from 'devlop'
import {phrasing} from 'mdast-util-phrasing'
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart} from 'unist-util-position'
import {generated} from 'unist-util-generated'
import {pointEnd, pointStart} from 'unist-util-position'
import {SKIP, visitParents} from 'unist-util-visit-parents'
import {VFileMessage} from 'vfile-message'

@@ -72,35 +126,69 @@ const remarkLintFinalDefinition = lintRule(

},
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
let last = 0
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
function (tree, file) {
/** @type {Array<Array<Nodes>>} */
const definitionStacks = []
/** @type {Array<Nodes> | undefined} */
let contentAncestors
visit(
tree,
(node) => {
// Ignore generated and HTML comment nodes.
if (
node.type === 'root' ||
generated(node) ||
(node.type === 'html' && /^\s*<!--/.test(node.value))
) {
return
}
visitParents(tree, function (node, parents) {
// Do not walk into phrasing.
if (phrasing(node)) {
return SKIP
}
const line = pointStart(node).line
if (node.type === 'definition' || node.type === 'footnoteDefinition') {
definitionStacks.push([...parents, node])
} else if (
node.type === 'root' ||
// Ignore HTML comments.
(node.type === 'html' && /^[\t ]*<!--/.test(node.value)) ||
// Ignore MDX comments.
(node.type === 'mdxFlowExpression' && /^\s*\/\*/.test(node.value))
) {
// Empty.
} else {
contentAncestors = [...parents, node]
}
})
if (node.type === 'definition') {
if (last && last > line) {
file.message(
'Move definitions to the end of the file (after the node at line `' +
last +
'`)',
node
)
}
} else if (last === 0) {
last = line
const content = contentAncestors ? contentAncestors.at(-1) : undefined
const contentEnd = pointEnd(content)
if (contentEnd) {
assert(content) // Always defined.
assert(contentAncestors) // Always defined.
for (const definitionAncestors of definitionStacks) {
const definition = definitionAncestors.at(-1)
assert(definition) // Always defined.
const definitionStart = pointStart(definition)
if (definitionStart && definitionStart.line < contentEnd.line) {
file.message(
'Unexpected ' +
(definition.type === 'footnoteDefinition' ? 'footnote ' : '') +
'definition before last content, expected definitions after line `' +
contentEnd.line +
'`',
{
ancestors: definitionAncestors,
cause: new VFileMessage('Last content defined here', {
ancestors: contentAncestors,
place: content.position,
ruleId: 'final-definition',
source: 'remark-lint'
}),
place: definition.position
}
)
}
},
true
)
}
}
}

@@ -107,0 +195,0 @@ )

{
"name": "remark-lint-final-definition",
"version": "3.1.2",
"version": "4.0.0",
"description": "remark-lint rule to warn when definitions are not placed at the end of the file",
"license": "MIT",
"keywords": [
"definition",
"final",
"lint",
"position",
"remark",
"lint",
"rule",
"remark-lint",
"remark-lint-rule",
"definition",
"position",
"final"
"rule"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-final-definition"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-final-definition",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -27,28 +24,35 @@ "funding": {

"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.d.ts.map",
"index.js"
],
"dependencies": {
"@types/mdast": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-generated": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"devlop": "^1.0.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-phrasing": "^4.0.0",
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.0.0",
"vfile-message": "^4.0.0"
},
"scripts": {},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"capitalized-comments": "off"
}
}
}

@@ -5,44 +5,42 @@ <!--This file is generated-->

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[![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]
[`remark-lint`][mono] rule to warn when definitions are used *in* the document
instead of at the end.
[`remark-lint`][github-remark-lint] rule to warn when definitions are used *in* the
document instead of at the end.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintFinalDefinition[, config])`](#unifieduseremarklintfinaldefinition-config)
* [Recommendation](#recommendation)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintFinalDefinition)`](#unifieduseremarklintfinaldefinition)
* [Recommendation](#recommendation)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint`
rule.
Lint rules check markdown code style.
This package checks where definitions are placed.
## When should I use this?
You can use this package to check that definitions are placed at the end of
the document.
You can use this package to check that definitions are consistently at the
end of the document.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

@@ -53,4 +51,5 @@ | [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | |

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
This package is [ESM only][github-gist-esm].
In Node.js (version 16+),
install with [npm][npm-install]:

@@ -61,13 +60,13 @@ ```sh

In Deno with [`esm.sh`][esmsh]:
In Deno with [`esm.sh`][esm-sh]:
```js
import remarkLintFinalDefinition from 'https://esm.sh/remark-lint-final-definition@3'
import remarkLintFinalDefinition from 'https://esm.sh/remark-lint-final-definition@4'
```
In browsers with [`esm.sh`][esmsh]:
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import remarkLintFinalDefinition from 'https://esm.sh/remark-lint-final-definition@3?bundle'
import remarkLintFinalDefinition from 'https://esm.sh/remark-lint-final-definition@4?bundle'
</script>

@@ -81,18 +80,20 @@ ```

```js
import remarkLint from 'remark-lint'
import remarkLintFinalDefinition from 'remark-lint-final-definition'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkLint from 'remark-lint'
import remarkLintFinalDefinition from 'remark-lint-final-definition'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintFinalDefinition)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintFinalDefinition)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

@@ -103,3 +104,3 @@

```sh
remark --use remark-lint --use remark-lint-final-definition example.md
remark --frail --use remark-lint --use remark-lint-final-definition .
```

@@ -125,11 +126,18 @@

This package exports no identifiers.
The default export is `remarkLintFinalDefinition`.
It exports no additional [TypeScript][typescript] types.
The default export is
[`remarkLintFinalDefinition`][api-remark-lint-final-definition].
### `unified().use(remarkLintFinalDefinition[, config])`
### `unified().use(remarkLintFinalDefinition)`
This rule supports standard configuration that all remark lint rules accept
(such as `false` to turn it off or `[1, options]` to configure it).
Warn when definitions are used *in* the document instead of at the end.
###### Parameters
There are no options.
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
## Recommendation

@@ -148,5 +156,5 @@

```markdown
Paragraph.
Mercury.
[example]: http://example.com "Example Domain"
[venus]: http://example.com
```

@@ -158,2 +166,54 @@

##### `ok.md`
###### In
```markdown
[mercury]: http://example.com/mercury/
[venus]: http://example.com/venus/
```
###### Out
No messages.
##### `ok-html-comments.md`
###### In
```markdown
Mercury.
[venus]: http://example.com/venus/
<!-- HTML comments in markdown are ignored. -->
[earth]: http://example.com/earth/
```
###### Out
No messages.
##### `ok-mdx-comments.mdx`
###### In
> 👉 **Note**: this example uses
> MDX ([`remark-mdx`][github-remark-mdx]).
```mdx
Mercury.
[venus]: http://example.com/venus/
{/* Comments in expressions in MDX are ignored. */}
[earth]: http://example.com/earth/
```
###### Out
No messages.
##### `not-ok.md`

@@ -164,7 +224,7 @@

```markdown
Paragraph.
Mercury.
[example]: http://example.com "Example Domain"
[venus]: https://example.com/venus/
Another paragraph.
Earth.
```

@@ -175,17 +235,20 @@

```text
3:1-3:47: Move definitions to the end of the file (after the node at line `5`)
3:1-3:36: Unexpected definition before last content, expected definitions after line `5`
```
##### `ok-comments.md`
##### `gfm.md`
###### In
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
Paragraph.
Mercury.
[example-1]: http://example.com/one/
[^venus]:
**Venus** is the second planet from
the Sun.
<!-- Comments are fine between and after definitions -->
[example-2]: http://example.com/two/
Earth.
```

@@ -195,18 +258,24 @@

No messages.
```text
3:1-5:13: Unexpected footnote definition before last content, expected definitions after line `7`
```
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with 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.
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-final-definition@4`,
compatible with Node.js 16.
## Contribute
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
See [`contributing.md`][github-dotfiles-contributing] in [`remarkjs/.github`][github-dotfiles-health] for ways
to get started.
See [`support.md`][support] for ways to get help.
See [`support.md`][github-dotfiles-support] for ways to get help.
This project has a [code of conduct][coc].
This project has a [code of conduct][github-dotfiles-coc].
By interacting with this repository, organization, or community you agree to

@@ -217,52 +286,58 @@ abide by its terms.

[MIT][license] © [Titus Wormer][author]
[MIT][file-license] © [Titus Wormer][author]
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[api-remark-lint-final-definition]: #unifieduseremarklintfinaldefinition
[build]: https://github.com/remarkjs/remark-lint/actions
[author]: https://wooorm.com
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[coverage]: https://codecov.io/github/remarkjs/remark-lint
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-final-definition.svg
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[downloads]: https://www.npmjs.com/package/remark-lint-final-definition
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-final-definition.svg
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[size]: https://bundlephobia.com/result?p=remark-lint-final-definition
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-final-definition.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-final-definition
[collective]: https://opencollective.com/unified
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg
[chat]: https://github.com/remarkjs/remark/discussions
[badge-funding-url]: https://opencollective.com/unified
[unified]: https://github.com/unifiedjs/unified
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-final-definition
[remark]: https://github.com/remarkjs/remark
[badge-size-url]: https://bundlejs.com/?q=remark-lint-final-definition
[mono]: https://github.com/remarkjs/remark-lint
[esm-sh]: https://esm.sh
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license
[esmsh]: https://esm.sh
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[npm]: https://docs.npmjs.com/cli/install
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[health]: https://github.com/remarkjs/.github
[github-dotfiles-health]: https://github.com/remarkjs/.github
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[github-remark-gfm]: https://github.com/remarkjs/remark-gfm
[license]: https://github.com/remarkjs/remark-lint/blob/main/license
[github-remark-lint]: https://github.com/remarkjs/remark-lint
[author]: https://wooorm.com
[github-remark-mdx]: https://mdxjs.com/packages/remark-mdx/
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
[npm-install]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc