Skip to content

no-multiple-atx-heading-space

🎨 Stylistic 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Disallow multiple spaces around ATX heading markers.

Rule Details ​

This rule disallows multiple consecutive spaces or tabs around the hash characters (#) of ATX headings.

By default, the rule checks the whitespace after the opening hash characters and before the closing hash characters in closed ATX headings. Set checkClosedHeading to false to disable checks before the closing hash characters.

NOTE

This rule does not enforce missing spaces. Use markdown/no-missing-atx-heading-space to check missing spaces, and enable its checkClosedHeadings option to check closed ATX headings.

Examples ​

❌ Incorrect ​

Examples of incorrect code for this rule:

Default ​

md
<!-- eslint md/no-multiple-atx-heading-space: 'error' -->

# 
ATX heading 1
##
ATX Heading 2
#
Closed ATX heading 1 #
## Closed ATX heading 2
##

✅ Correct ​

Examples of correct code for this rule:

Default ​

md
<!-- eslint md/no-multiple-atx-heading-space: 'error' -->

# ATX heading 1

## ATX Heading 2

# Closed ATX heading 1 #

## Closed ATX heading 2 ##

Setext heading
---------------

With { checkClosedHeading: false } Option ​

md
<!-- eslint md/no-multiple-atx-heading-space: ['error', { checkClosedHeading: false }] -->

# Closed ATX heading 1  #

## Closed ATX heading 2   ##

Options ​

js
'md/no-multiple-atx-heading-space': ['error', {
  checkClosedHeading: true,
}]

checkClosedHeading ​

Type: boolean / Default: true

When checkClosedHeading is set to false, this rule stops checking for multiple consecutive spaces or tabs before the closing hash characters in closed ATX headings.

Fix ​

This rule fixes multiple consecutive spaces or tabs by keeping the first whitespace character and removing the rest.

For example, # Heading 1 is fixed to # Heading 1. ## Heading 2 ## is fixed to ## Heading 2 ##.

When the heading has neither content nor a closing sequence, all of the whitespace is removed.

When Not To Use It ​

If you intentionally use multiple spaces or tabs next to ATX heading markers, you can disable this rule.

Prior Art ​