Socket
Socket
Sign inDemoInstall

remark-lint-no-consecutive-blank-lines

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-no-consecutive-blank-lines - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

124

index.js

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

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

@@ -27,5 +28,7 @@ * Foo…

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

@@ -39,3 +42,4 @@ * Foo…

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

@@ -46,71 +50,75 @@ * 4:1: Remove 1 line before node

'use strict'
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('unist').Point} Point
*/
var rule = require('unified-lint-rule')
var plural = require('pluralize')
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 plural from 'pluralize'
import {visit} from 'unist-util-visit'
import {pointStart, pointEnd} from 'unist-util-position'
import {generated} from 'unist-util-generated'
module.exports = rule(
const remarkLintNoConsecutiveBlankLines = lintRule(
'remark-lint:no-consecutive-blank-lines',
noConsecutiveBlankLines
)
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
visit(tree, (node) => {
if (!generated(node) && 'children' in node) {
const head = node.children[0]
function noConsecutiveBlankLines(tree, file) {
visit(tree, visitor)
if (head && !generated(head)) {
// Compare parent and first child.
compare(pointStart(node), pointStart(head), 0)
function visitor(node) {
var children = node.children
var head
var tail
// Compare between each child.
let index = -1
if (!generated(node) && children) {
head = children[0]
while (++index < node.children.length) {
const previous = node.children[index - 1]
const child = node.children[index]
if (head && !generated(head)) {
// Compare parent and first child.
compare(position.start(node), position.start(head), 0)
if (previous && !generated(previous) && !generated(child)) {
compare(pointEnd(previous), pointStart(child), 2)
}
}
// Compare between each child.
children.forEach(visitChild)
const tail = node.children[node.children.length - 1]
tail = children[children.length - 1]
// Compare parent and last child.
if (tail !== head && !generated(tail)) {
compare(position.end(node), position.end(tail), 1)
// Compare parent and last child.
if (tail !== head && !generated(tail)) {
compare(pointEnd(node), pointEnd(tail), 1)
}
}
}
}
}
})
// Compare the difference between `start` and `end`, and warn when that
// difference exceeds `max`.
function compare(start, end, max) {
var diff = end.line - start.line
var lines = Math.abs(diff) - max
var reason
/**
* Compare the difference between `start` and `end`, and warn when that
* difference exceeds `max`.
*
* @param {Point} start
* @param {Point} end
* @param {0|1|2} max
*/
function compare(start, end, max) {
const diff = end.line - start.line
const lines = Math.abs(diff) - max
if (lines > 0) {
reason =
'Remove ' +
lines +
' ' +
plural('line', Math.abs(lines)) +
' ' +
(diff > 0 ? 'before' : 'after') +
' node'
file.message(reason, end)
if (lines > 0) {
file.message(
'Remove ' +
lines +
' ' +
plural('line', Math.abs(lines)) +
' ' +
(diff > 0 ? 'before' : 'after') +
' node',
end
)
}
}
}
)
function visitChild(child, index, all) {
var previous = all[index - 1]
if (previous && !generated(previous) && !generated(child)) {
compare(position.end(previous), position.start(child), 2)
}
}
}
export default remarkLintNoConsecutiveBlankLines
{
"name": "remark-lint-no-consecutive-blank-lines",
"version": "3.0.0",
"version": "4.0.0",
"description": "remark-lint rule to warn for too many consecutive blank lines",

@@ -24,13 +24,30 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/mdast": "^3.0.0",
"@types/unist": "^2.0.0",
"pluralize": "^8.0.0",
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.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
}
}

@@ -82,2 +82,5 @@ <!--This file is generated-->

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -89,2 +92,5 @@

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

@@ -116,10 +122,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 remarkLintNoConsecutiveBlankLines from 'remark-lint-no-consecutive-blank-lines'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-no-consecutive-blank-lines'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintNoConsecutiveBlankLines)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -142,5 +151,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

@@ -169,2 +178,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

@@ -171,0 +182,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