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
3
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 4.1.2 to 5.0.0

index.d.ts.map

14

index.d.ts

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

export default remarkLintNoHeadingContentIndent
export type Root = import('mdast').Root
declare const remarkLintNoHeadingContentIndent: import('unified').Plugin<
void[] | [unknown],
import('mdast').Root,
import('mdast').Root
>
export default remarkLintNoHeadingContentIndent;
export type Root = import('mdast').Root;
declare const remarkLintNoHeadingContentIndent: {
(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 extra whitespace is used between hashes and
* content in headings.
*
* ## What is this?
*
* This package checks whitespace between hashes and content.
*
* ## When should I use this?
*
* You can use this package to check that there is on space between `#`
* characters and the content in headings.
* You can use this package to check that headings are consistent.
*
* ## API
*
* ### `unified().use(remarkLintNoHeadingContentIndent)`
*
* Warn when extra whitespace is used between hashes and content in headings.
*
* ###### Parameters
*
* There are no options.
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ## Recommendation

@@ -18,46 +34,53 @@ *

*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
* formats headings with exactly one space.
* [`remark-stringify`][github-remark-stringify] formats headings with one space.
*
* [api-remark-lint-no-heading-content-indent]: #unifieduseremarklintnoheadingcontentindent
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module no-heading-content-indent
* @summary
* remark-lint rule to warn when there are too many spaces between
* hashes and content in headings.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md"}
*
* #·Foo
* #␠Mercury
*
* ## Bar·##
* ##␠Venus␠##
*
* ##·Baz
* ␠␠##␠Earth
*
* Setext headings are not affected.
* Setext headings are not affected:
*
* Baz
* ===
* ␠Mars
* =====
*
* ␠Jupiter
* --------
*
* @example
* {"name": "not-ok.md", "label": "input"}
* {"label": "input", "name": "not-ok.md"}
*
* #··Foo
* #␠␠Mercury
*
* ## Bar··##
* ##␠Venus␠␠##
*
* ##··Baz
*
* ␠␠##␠␠␠Earth
* @example
* {"name": "not-ok.md", "label": "output"}
* {"label": "output", "name": "not-ok.md"}
*
* 1:4: Remove 1 space before this heading’s content
* 3:7: Remove 1 space after this heading’s content
* 5:7: Remove 1 space before this heading’s content
* 1:4: Unexpected `2` spaces between hashes and content, expected `1` space, remove `1` space
* 3:11: Unexpected `2` spaces between content and hashes, expected `1` space, remove `1` space
* 5:8: Unexpected `3` spaces between hashes and content, expected `1` space, remove `2` spaces
*
* @example
* {"name": "empty-heading.md"}
* {"label": "input", "name": "empty-heading.md"}
*
* #··
* #␠␠
* @example
* {"label": "output", "name": "empty-heading.md"}
*
* 1:4: Unexpected `2` spaces between hashes and content, expected `1` space, remove `1` space
*/

@@ -69,8 +92,7 @@

import {phrasing} from 'mdast-util-phrasing'
import pluralize from 'pluralize'
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'
import {pointEnd, pointStart} from 'unist-util-position'
import {SKIP, visitParents} from 'unist-util-visit-parents'

@@ -82,50 +104,126 @@ const remarkLintNoHeadingContentIndent = lintRule(

},
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
visit(tree, 'heading', (node) => {
if (generated(node)) {
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
function (tree, file) {
const value = String(file)
visitParents(tree, function (node, parents) {
// Do not walk into phrasing.
if (phrasing(node)) {
return SKIP
}
if (node.type !== 'heading') return
const start = pointStart(node)
const end = pointEnd(node)
if (
!end ||
!start ||
typeof end.offset !== 'number' ||
typeof start.offset !== 'number'
) {
return
}
const type = headingStyle(node, 'atx')
let index = start.offset
let code = value.charCodeAt(index)
// Node positional info starts after whitespace,
// so we don’t need to walk past it.
let found = false
if (type === 'atx' || type === 'atx-closed') {
const head = pointStart(node.children[0]).column
while (value.charCodeAt(index) === 35 /* `#` */) {
index++
found = true
continue
}
// Ignore empty headings.
if (!head) {
return
}
const from = index
const diff = head - pointStart(node).column - 1 - node.depth
code = value.charCodeAt(index)
if (diff) {
file.message(
'Remove ' +
Math.abs(diff) +
' ' +
plural('space', Math.abs(diff)) +
' before this heading’s content',
pointStart(node.children[0])
)
}
while (code === 9 /* `\t` */ || code === 32 /* ` ` */) {
code = value.charCodeAt(++index)
continue
}
// 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
const size = index - from
if (diff) {
file.message(
'Remove ' +
diff +
' ' +
plural('space', diff) +
' after this heading’s content',
final
)
}
// Not ATX / fine.
if (found && size > 1) {
file.message(
'Unexpected `' +
size +
'` ' +
pluralize('space', size) +
' between hashes and content, expected `1` space, remove `' +
(size - 1) +
'` ' +
pluralize('space', size - 1),
{
ancestors: [...parents, node],
place: {
line: start.line,
column: start.column + (index - start.offset),
offset: start.offset + (index - start.offset)
}
}
)
}
const contentStart = index
index = end.offset
code = value.charCodeAt(index - 1)
while (code === 9 /* `\t` */ || code === 32 /* ` ` */) {
index--
code = value.charCodeAt(index - 1)
continue
}
let endFound = false
while (value.charCodeAt(index - 1) === 35 /* `#` */) {
index--
endFound = true
continue
}
const endFrom = index
code = value.charCodeAt(index - 1)
while (code === 9 /* `\t` */ || code === 32 /* ` ` */) {
index--
code = value.charCodeAt(index - 1)
continue
}
const endSize = endFrom - index
if (endFound && index > contentStart && endSize > 1) {
file.message(
'Unexpected `' +
endSize +
'` ' +
pluralize('space', endSize) +
' between content and hashes, expected `1` space, remove `' +
(endSize - 1) +
'` ' +
pluralize('space', endSize - 1),
{
ancestors: [...parents, node],
place: {
line: end.line,
column: end.column - (end.offset - endFrom),
offset: end.offset - (end.offset - endFrom)
}
}
)
}
})

@@ -132,0 +230,0 @@ }

{
"name": "remark-lint-no-heading-content-indent",
"version": "4.1.2",
"version": "5.0.0",
"description": "remark-lint rule to warn when heading content is indented",
"license": "MIT",
"keywords": [
"content",
"heading",
"indent",
"lint",
"remark",
"lint",
"rule",
"remark-lint",
"remark-lint-rule",
"heading",
"content",
"indent"
"rule"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-no-heading-content-indent"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-heading-content-indent",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -27,30 +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",
"mdast-util-heading-style": "^2.0.0",
"@types/mdast": "^4.0.0",
"mdast-util-phrasing": "^4.0.0",
"pluralize": "^8.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"
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.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",
"unicorn/prefer-at": "off",
"unicorn/prefer-code-point": "off"
}
}
}

@@ -5,45 +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 there are too many spaces between
hashes and content in headings.
[`remark-lint`][github-remark-lint] rule to warn when extra whitespace is used between hashes and
content in headings.
## 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(remarkLintNoHeadingContentIndent[, config])`](#unifieduseremarklintnoheadingcontentindent-config)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [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(remarkLintNoHeadingContentIndent)`](#unifieduseremarklintnoheadingcontentindent)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [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 whitespace between hashes and content.
## When should I use this?
You can use this package to check that there is on space between `#`
characters and the content in headings.
You can use this package to check that headings are consistent.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

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

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]:

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

In Deno with [`esm.sh`][esmsh]:
In Deno with [`esm.sh`][esm-sh]:
```js
import remarkLintNoHeadingContentIndent from 'https://esm.sh/remark-lint-no-heading-content-indent@4'
import remarkLintNoHeadingContentIndent from 'https://esm.sh/remark-lint-no-heading-content-indent@5'
```
In browsers with [`esm.sh`][esmsh]:
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import remarkLintNoHeadingContentIndent from 'https://esm.sh/remark-lint-no-heading-content-indent@4?bundle'
import remarkLintNoHeadingContentIndent from 'https://esm.sh/remark-lint-no-heading-content-indent@5?bundle'
</script>

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

```js
import remarkLint from 'remark-lint'
import remarkLintNoHeadingContentIndent from 'remark-lint-no-heading-content-indent'
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 remarkLintNoHeadingContentIndent from 'remark-lint-no-heading-content-indent'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintNoHeadingContentIndent)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintNoHeadingContentIndent)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

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

```sh
remark --use remark-lint --use remark-lint-no-heading-content-indent example.md
remark --frail --use remark-lint --use remark-lint-no-heading-content-indent .
```

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

This package exports no identifiers.
The default export is `remarkLintNoHeadingContentIndent`.
It exports no additional [TypeScript][typescript] types.
The default export is
[`remarkLintNoHeadingContentIndent`][api-remark-lint-no-heading-content-indent].
### `unified().use(remarkLintNoHeadingContentIndent[, config])`
### `unified().use(remarkLintNoHeadingContentIndent)`
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 extra whitespace is used between hashes and content in headings.
###### Parameters
There are no options.
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
## Recommendation

@@ -143,4 +150,3 @@

[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
formats headings with exactly one space.
[`remark-stringify`][github-remark-stringify] formats headings with one space.

@@ -153,15 +159,16 @@ ## Examples

> 👉 **Note**: `·` represents a space.
```markdown
#·Foo
#␠Mercury
## Bar·##
##␠Venus␠##
##·Baz
␠␠##␠Earth
Setext headings are not affected.
Setext headings are not affected:
Baz
===
␠Mars
=====
␠Jupiter
--------
```

@@ -177,10 +184,8 @@

> 👉 **Note**: `·` represents a space.
```markdown
#··Foo
#␠␠Mercury
## Bar··##
##␠Venus␠␠##
##··Baz
␠␠##␠␠␠Earth
```

@@ -191,5 +196,5 @@

```text
1:4: Remove 1 space before this heading’s content
3:7: Remove 1 space after this heading’s content
5:7: Remove 1 space before this heading’s content
1:4: Unexpected `2` spaces between hashes and content, expected `1` space, remove `1` space
3:11: Unexpected `2` spaces between content and hashes, expected `1` space, remove `1` space
5:8: Unexpected `3` spaces between hashes and content, expected `1` space, remove `2` spaces
```

@@ -201,6 +206,4 @@

> 👉 **Note**: `·` represents a space.
```markdown
#··
#␠␠
```

@@ -210,18 +213,24 @@

No messages.
```text
1:4: Unexpected `2` spaces between hashes and content, expected `1` space, remove `1` space
```
## 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-no-heading-content-indent@5`,
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

@@ -232,52 +241,56 @@ 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-no-heading-content-indent]: #unifieduseremarklintnoheadingcontentindent
[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-no-heading-content-indent.svg
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[downloads]: https://www.npmjs.com/package/remark-lint-no-heading-content-indent
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-no-heading-content-indent.svg
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[size]: https://bundlephobia.com/result?p=remark-lint-no-heading-content-indent
[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-no-heading-content-indent.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-no-heading-content-indent
[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-no-heading-content-indent
[remark]: https://github.com/remarkjs/remark
[badge-size-url]: https://bundlejs.com/?q=remark-lint-no-heading-content-indent
[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-lint]: https://github.com/remarkjs/remark-lint
[license]: https://github.com/remarkjs/remark-lint/blob/main/license
[github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
[author]: https://wooorm.com
[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