New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-maximum-heading-length

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-maximum-heading-length - npm Package Compare versions

Comparing version 3.1.2 to 4.0.0

index.d.ts.map

30

index.d.ts

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

export default remarkLintMaximumHeadingLength
export type Root = import('mdast').Root
/**
* Options.
*/
export type Options = number
declare const remarkLintMaximumHeadingLength: import('unified').Plugin<
| void[]
| [
| number
| [
(
| boolean
| import('unified-lint-rule/lib/index.js').Label
| import('unified-lint-rule/lib/index.js').Severity
),
(number | undefined)?
]
| undefined
],
import('mdast').Root,
import('mdast').Root
>
export default remarkLintMaximumHeadingLength;
export type Root = import('mdast').Root;
declare const remarkLintMaximumHeadingLength: {
(config?: number | "error" | "on" | "off" | "warn" | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: number | null | undefined] | null | undefined): ((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 headings are too long.
*
* ## What is this?
*
* This package checks the length of heading text.
*
* ## When should I use this?

@@ -8,20 +14,28 @@ *

*
* The following options (default: `60`) are accepted:
* ### `unified().use(remarkLintMaximumHeadingLength[, options])`
*
* * `number` (example: `72`)
* — max number of characters to accept in heading text
* Warn when headings are too long.
*
* Ignores syntax, only checks the plain text content.
* ###### Parameters
*
* * `options` (`number`, default: `60`)
* — preferred max size
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ## Recommendation
*
* While this rule is sometimes annoying, reasonable size headings
* do help SEO purposes (bots prefer reasonable headings), visual users
* (headings are typically displayed quite large), and users of screen readers
* (who typically use “jump to heading” features to navigate within a page,
* which reads every heading out loud).
* While this rule is sometimes annoying,
* reasonable size headings do help SEO purposes (bots prefer reasonable
* headings),
* visual users (headings are typically displayed quite large),
* and users of screen readers (who use “jump to heading” features that read
* every heading out loud to navigate within a page).
*
* [api-remark-lint-maximum-heading-length]: #unifieduseremarklintmaximumheadinglength-options
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module maximum-heading-length
* @summary
* remark-lint rule to warn when headings are too long.
* @author Titus Wormer

@@ -33,15 +47,27 @@ * @copyright 2015 Titus Wormer

*
* # Alpha bravo charlie delta echo foxtrot golf hotel
* # Mercury is the first planet from the Sun
*
* # ![Alpha bravo charlie delta echo foxtrot golf hotel](http://example.com/nato.png)
* @example
* {"config": 30, "label": "input", "name": "not-ok.md"}
*
* # Mercury is the first planet from the Sun
*
* @example
* {"name": "not-ok.md", "config": 40, "label": "input"}
* {"config": 30, "label": "output", "name": "not-ok.md"}
*
* # Alpha bravo charlie delta echo foxtrot golf hotel
* 1:1-1:43: Unexpected `40` characters in heading, expected at most `30` characters
*
* @example
* {"name": "not-ok.md", "config": 40, "label": "output"}
* {"config": 30, "label": "input", "mdx": true, "name": "mdx.mdx"}
*
* 1:1-1:52: Use headings shorter than `40`
* <h1>Mercury is the first planet from the Sun</h1>
* @example
* {"config": 30, "label": "output", "mdx": true, "name": "mdx.mdx"}
*
* 1:1-1:50: Unexpected `40` characters in heading, expected at most `30` characters
*
* @example
* {"config": "🌍", "label": "output", "name": "not-ok.md", "positionless": true}
*
* 1:1: Unexpected value `🌍` for `options`, expected `number`
*/

@@ -53,12 +79,11 @@

/**
* @typedef {number} Options
* Options.
*/
/// <reference types="mdast-util-mdx" />
import {toString} from 'mdast-util-to-string'
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {generated} from 'unist-util-generated'
import {toString} from 'mdast-util-to-string'
import {position} from 'unist-util-position'
import {visitParents} from 'unist-util-visit-parents'
const jsxNameRe = /^h([1-6])$/
const remarkLintMaximumHeadingLength = lintRule(

@@ -69,7 +94,47 @@ {

},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 60) => {
visit(tree, 'heading', (node) => {
if (!generated(node) && toString(node).length > option) {
file.message('Use headings shorter than `' + option + '`', node)
/**
* @param {Root} tree
* Tree.
* @param {number | null | undefined} [options=60]
* Configuration (default: `60`).
* @returns {undefined}
* Nothing.
*/
function (tree, file, options) {
let expected = 60
if (options === null || options === undefined) {
// Empty.
} else if (typeof options === 'number') {
expected = options
} else {
file.fail(
'Unexpected value `' + options + '` for `options`, expected `number`'
)
}
// Note: HTML headings cannot properly be checked,
// because for markdown, blocks are one single raw string.
visitParents(tree, function (node, parents) {
if (
node.type === 'heading' ||
((node.type === 'mdxJsxFlowElement' ||
node.type === 'mdxJsxTextElement') &&
node.name &&
jsxNameRe.test(node.name))
) {
const place = position(node)
const actual = Array.from(toString(node, {includeHtml: false})).length
if (place && actual > expected) {
file.message(
'Unexpected `' +
actual +
'` characters in heading, expected at most `' +
expected +
'` characters',
{ancestors: [...parents, node], place}
)
}
}

@@ -76,0 +141,0 @@ })

{
"name": "remark-lint-maximum-heading-length",
"version": "3.1.2",
"version": "4.0.0",
"description": "remark-lint rule to warn when headings are too long",
"license": "MIT",
"keywords": [
"heading",
"length",
"lint",
"remark",
"lint",
"rule",
"remark-lint",
"remark-lint-rule",
"heading",
"length"
"rule"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-maximum-heading-length"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-maximum-heading-length",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -26,28 +23,34 @@ "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-to-string": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-generated": "^2.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-to-string": "^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-default-parameters": "off"
}
}
}

@@ -5,32 +5,30 @@ <!--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 headings are too long.
[`remark-lint`][github-remark-lint] rule to warn when headings are too long.
## 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(remarkLintMaximumHeadingLength[, config])`](#unifieduseremarklintmaximumheadinglength-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(remarkLintMaximumHeadingLength[, options])`](#unifieduseremarklintmaximumheadinglength-options)
* [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 the length of heading text.

@@ -43,5 +41,5 @@ ## When should I use this?

This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

@@ -52,4 +50,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]:

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

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

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

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

@@ -102,3 +103,3 @@

```sh
remark --use remark-lint --use remark-lint-maximum-heading-length example.md
remark --frail --use remark-lint --use remark-lint-maximum-heading-length .
```

@@ -124,23 +125,27 @@

This package exports no identifiers.
The default export is `remarkLintMaximumHeadingLength`.
It exports no additional [TypeScript][typescript] types.
The default export is
[`remarkLintMaximumHeadingLength`][api-remark-lint-maximum-heading-length].
### `unified().use(remarkLintMaximumHeadingLength[, config])`
### `unified().use(remarkLintMaximumHeadingLength[, options])`
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 headings are too long.
The following options (default: `60`) are accepted:
###### Parameters
* `number` (example: `72`)
— max number of characters to accept in heading text
* `options` (`number`, default: `60`)
— preferred max size
Ignores syntax, only checks the plain text content.
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
## Recommendation
While this rule is sometimes annoying, reasonable size headings
do help SEO purposes (bots prefer reasonable headings), visual users
(headings are typically displayed quite large), and users of screen readers
(who typically use “jump to heading” features to navigate within a page,
which reads every heading out loud).
While this rule is sometimes annoying,
reasonable size headings do help SEO purposes (bots prefer reasonable
headings),
visual users (headings are typically displayed quite large),
and users of screen readers (who use “jump to heading” features that read
every heading out loud to navigate within a page).

@@ -154,5 +159,3 @@ ## Examples

```markdown
# Alpha bravo charlie delta echo foxtrot golf hotel
# ![Alpha bravo charlie delta echo foxtrot golf hotel](http://example.com/nato.png)
# Mercury is the first planet from the Sun
```

@@ -166,3 +169,3 @@

When configured with `40`.
When configured with `30`.

@@ -172,3 +175,3 @@ ###### In

```markdown
# Alpha bravo charlie delta echo foxtrot golf hotel
# Mercury is the first planet from the Sun
```

@@ -179,19 +182,52 @@

```text
1:1-1:52: Use headings shorter than `40`
1:1-1:43: Unexpected `40` characters in heading, expected at most `30` characters
```
##### `mdx.mdx`
When configured with `30`.
###### In
> 👉 **Note**: this example uses
> MDX ([`remark-mdx`][github-remark-mdx]).
```mdx
<h1>Mercury is the first planet from the Sun</h1>
```
###### Out
```text
1:1-1:50: Unexpected `40` characters in heading, expected at most `30` characters
```
##### `not-ok.md`
When configured with `'🌍'`.
###### Out
```text
1:1: Unexpected value `🌍` for `options`, expected `number`
```
## 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-maximum-heading-length@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

@@ -202,52 +238,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-maximum-heading-length]: #unifieduseremarklintmaximumheadinglength-options
[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-maximum-heading-length.svg
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[downloads]: https://www.npmjs.com/package/remark-lint-maximum-heading-length
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-maximum-heading-length.svg
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[size]: https://bundlephobia.com/result?p=remark-lint-maximum-heading-length
[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-maximum-heading-length.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-maximum-heading-length
[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-maximum-heading-length
[remark]: https://github.com/remarkjs/remark
[badge-size-url]: https://bundlejs.com/?q=remark-lint-maximum-heading-length
[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-mdx]: https://mdxjs.com/packages/remark-mdx/
[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