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
2
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 2.1.0 to 3.0.0

index.d.ts

86

index.js

@@ -10,3 +10,4 @@ /**

*
* @example {"name": "ok.md"}
* @example
* {"name": "ok.md"}
*

@@ -17,3 +18,4 @@ * Paragraph.

*
* @example {"name": "not-ok.md", "label": "input"}
* @example
* {"name": "not-ok.md", "label": "input"}
*

@@ -26,7 +28,9 @@ * Paragraph.

*
* @example {"name": "not-ok.md", "label": "output"}
* @example
* {"name": "not-ok.md", "label": "output"}
*
* 3:1-3:47: Move definitions to the end of the file (after the node at line `5`)
*
* @example {"name": "ok-comments.md"}
* @example
* {"name": "ok-comments.md"}
*

@@ -42,39 +46,49 @@ * Paragraph.

'use strict'
/**
* @typedef {import('mdast').Root} Root
*/
var rule = require('unified-lint-rule')
var visit = require('unist-util-visit')
var position = require('unist-util-position')
var generated = require('unist-util-generated')
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart} from 'unist-util-position'
import {generated} from 'unist-util-generated'
module.exports = rule('remark-lint:final-definition', finalDefinition)
const remarkLintFinalDefinition = lintRule(
'remark-lint:final-definition',
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
let last = 0
var start = position.start
visit(
tree,
(node) => {
// Ignore generated and HTML comment nodes.
if (
node.type === 'root' ||
generated(node) ||
(node.type === 'html' && /^\s*<!--/.test(node.value))
) {
return
}
function finalDefinition(tree, file) {
var last = null
const line = pointStart(node).line
visit(tree, visitor, true)
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
}
},
true
)
}
)
function visitor(node) {
var line = start(node).line
// Ignore generated and HTML comment nodes.
if (node.type === 'root' || generated(node) || (node.type === 'html' && /^\s*<!--/.test(node.value))) {
return
}
if (node.type === 'definition') {
if (last !== null && last > line) {
file.message(
'Move definitions to the end of the file (after the node at line `' +
last +
'`)',
node
)
}
} else if (last === null) {
last = line
}
}
}
export default remarkLintFinalDefinition
{
"name": "remark-lint-final-definition",
"version": "2.1.0",
"version": "3.0.0",
"description": "remark-lint rule to warn when definitions are not placed at the end of the file",

@@ -25,12 +25,28 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.0.0"
"@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"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -58,4 +58,25 @@ <!--This file is generated-->

##### `ok-comments.md`
###### In
```markdown
Paragraph.
[example-1]: http://example.com/one/
<!-- Comments are fine between and after definitions -->
[example-2]: http://example.com/two/
```
###### Out
No messages.
## Install
This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -67,2 +88,5 @@

This package exports no identifiers.
The default export is `remarkLintFinalDefinition`.
## Use

@@ -94,10 +118,13 @@

```diff
var remark = require('remark')
var report = require('vfile-reporter')
import {remark} from 'remark'
import {reporter} from 'vfile-reporter'
import remarkLint from 'remark-lint'
import remarkLintFinalDefinition from 'remark-lint-final-definition'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-final-definition'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintFinalDefinition)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -120,5 +147,5 @@ ```

[build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[build]: https://travis-ci.org/remarkjs/remark-lint
[build]: https://github.com/remarkjs/remark-lint/actions

@@ -147,2 +174,4 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -149,0 +178,0 @@

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