remark-lint-first-heading-level

raw JSON →
4.0.1 verified Fri May 01 auth: no javascript

remark-lint rule to enforce that the first heading in a Markdown document has a specific rank (1-6). Part of the remark-lint ecosystem. Current stable version 4.0.1, released as part of remark-lint monorepo with coordinated version bumps. Ships TypeScript types. ESM-only since v3. Works with unified, remark-parse, and remark-stringify.

error ERR_REQUIRE_ESM: require() of ES Module
cause Using require() to import an ESM-only package.
fix
Change to import statement or use dynamic import().
error SyntaxError: Unexpected token 'export'
cause Running an ESM script with CommonJS module system.
fix
Add "type": "module" to package.json or use .mjs extension.
breaking Package is ESM-only since v3. CommonJS require() is not supported.
fix Use import syntax or dynamic import().
deprecated Options can be a number (1-6), but in future versions might be an object.
fix Pass a number or check future releases for object config.
npm install remark-lint-first-heading-level
yarn add remark-lint-first-heading-level
pnpm add remark-lint-first-heading-level

Checks that the first heading in example.md is rank 1, warns otherwise.

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import remarkLint from 'remark-lint'
import remarkLintFirstHeadingLevel from 'remark-lint-first-heading-level'
import { reporter } from 'vfile-reporter'
import { read } from 'to-vfile'

const file = await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintFirstHeadingLevel, 1) // expect first heading level 1
  .use(remarkStringify)
  .process(await read('example.md'))

console.error(reporter(file))