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

remark-lint-no-heading-content-indent

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-no-heading-content-indent - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

131

index.js

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

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

@@ -31,3 +32,4 @@ * #·Foo

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

@@ -40,3 +42,4 @@ * #··Foo

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

@@ -47,3 +50,4 @@ * 1:4: Remove 1 space before this heading’s content

*
* @example {"name": "empty-heading.md"}
* @example
* {"name": "empty-heading.md"}
*

@@ -53,82 +57,67 @@ * #··

'use strict'
/**
* @typedef {import('mdast').Root} Root
*/
var rule = require('unified-lint-rule')
var visit = require('unist-util-visit')
var style = require('mdast-util-heading-style')
var plural = require('pluralize')
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 {headingStyle} from 'mdast-util-heading-style'
import plural from 'pluralize'
import {pointStart, pointEnd} from 'unist-util-position'
import {generated} from 'unist-util-generated'
module.exports = rule(
const remarkLintNoHeadingContentIndent = lintRule(
'remark-lint:no-heading-content-indent',
noHeadingContentIndent
)
var start = position.start
var end = position.end
function noHeadingContentIndent(tree, file) {
visit(tree, 'heading', visitor)
function visitor(node) {
var depth
var children
var type
var head
var final
var diff
var reason
var abs
if (generated(node)) {
return
}
depth = node.depth
children = node.children
type = style(node, 'atx')
if (type === 'atx' || type === 'atx-closed') {
head = start(children[0]).column
// Ignore empty headings.
if (!head) {
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
visit(tree, 'heading', (node) => {
if (generated(node)) {
return
}
diff = head - start(node).column - 1 - depth
const type = headingStyle(node, 'atx')
if (diff) {
abs = Math.abs(diff)
if (type === 'atx' || type === 'atx-closed') {
const head = pointStart(node.children[0]).column
reason =
'Remove ' +
abs +
' ' +
plural('space', abs) +
' before this heading’s content'
// Ignore empty headings.
if (!head) {
return
}
file.message(reason, start(children[0]))
const diff = head - pointStart(node).column - 1 - node.depth
if (diff) {
file.message(
'Remove ' +
Math.abs(diff) +
' ' +
plural('space', Math.abs(diff)) +
' before this heading’s content',
pointStart(node.children[0])
)
}
}
}
// Closed ATX headings always must have a space between their content and
// the final hashes, thus, there is no `add x spaces`.
if (type === 'atx-closed') {
final = end(children[children.length - 1])
diff = end(node).column - final.column - 1 - depth
// Closed ATX headings always must have a space between their content and
// the final hashes, thus, there is no `add x spaces`.
if (type === 'atx-closed') {
const final = pointEnd(node.children[node.children.length - 1])
const diff = pointEnd(node).column - final.column - 1 - node.depth
if (diff) {
reason =
'Remove ' +
diff +
' ' +
plural('space', diff) +
' after this heading’s content'
file.message(reason, final)
if (diff) {
file.message(
'Remove ' +
diff +
' ' +
plural('space', diff) +
' after this heading’s content',
final
)
}
}
}
})
}
}
)
export default remarkLintNoHeadingContentIndent
{
"name": "remark-lint-no-heading-content-indent",
"version": "3.0.0",
"version": "4.0.0",
"description": "remark-lint rule to warn when heading content is indented",

@@ -25,14 +25,30 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"mdast-util-heading-style": "^1.0.2",
"@types/mdast": "^3.0.0",
"mdast-util-heading-style": "^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
}
}

@@ -94,2 +94,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][]:

@@ -101,2 +104,5 @@

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

@@ -128,10 +134,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 remarkLintNoHeadingContentIndent from 'remark-lint-no-heading-content-indent'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-no-heading-content-indent'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintNoHeadingContentIndent)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -154,5 +163,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

@@ -181,2 +190,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

@@ -183,0 +194,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