markdown/heading-increment

Enforce heading levels increment by one

A heading that jumps from level 1 to level 3 leaves a gap in the outline. Screen readers and generated tables of contents rely on the levels, so a reader can't tell whether a section is missing.

Going back up by any number of levels is fine.

Configure#

Off by default. It needs an ESLint config that says which files are in the language:

eslint.config.js
import markdown from "@eslint/markdown";

export default [
  {
    files: ["**/*.md"],
    plugins: { markdown },
    language: "markdown/commonmark",
    rules: { "markdown/heading-increment": "error" },
  },
];

It also works with markdown/gfm.

Examples#

example.md1 problem
# Install

### With Homebrew
example.mdNo problems
# Install

## With Homebrew

### On Apple silicon

# Usage

Options#

OptionDefaultWhat it does
frontmatterTitlea pattern that matches title:, title =, "title":A regular expression. If a line of the front matter matches it, the front matter counts as the level 1 heading. "" turns that off.

Front matter is only parsed if languageOptions.frontmatter is set to the format that the files use.

example.md1 problem
---
title: Install
---

### With Homebrew
example.mdwith { "frontmatterTitle": "" }No problems
---
title: Install
---

### With Homebrew