Skip to content

no-trailing-heading-punctuation

🎨 Stylistic 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Disallow trailing punctuation in headings.

Rule Details

This rule disallows configured punctuation characters at the end of ATX, closed ATX, and Setext headings.

By default, the following punctuation characters are not allowed:

txt
. , ; : !     

Question marks (? and ) are allowed by default. The trailing semicolon of HTML entity references such as © and the trailing colon of GitHub emoji codes such as :smile: are ignored by this rule.

Examples

❌ Incorrect

Examples of incorrect code for this rule:

Default

md
<!-- eslint md/no-trailing-heading-punctuation: 'error' -->

# ATX heading
.
# Heading
!
## Closed ATX heading
!
##
Setext heading
:
---------------

With { punctuation: ['?'] } Option

md
<!-- eslint md/no-trailing-heading-punctuation: ['error', { punctuation: ['?'] }] -->

# Heading
?

✅ Correct

Examples of correct code for this rule:

Default

md
<!-- eslint md/no-trailing-heading-punctuation: 'error' -->

# ATX heading

## Closed ATX heading ##

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

# Question?

# Copyright &copy;

# Heading :smile:

With { punctuation: ['?'] } Option

md
<!-- eslint md/no-trailing-heading-punctuation: ['error', { punctuation: ['?'] }] -->

# Heading!

Options

js
'md/no-trailing-heading-punctuation': ['error', {
  punctuation: ['.', ',', ';', ':', '!', '。', ',', ';', ':', '!'],
}]

punctuation

Type: string[] / Default: ['.', ',', ';', ':', '!', '。', ',', ';', ':', '!']

Specifies the characters that are not allowed at the end of headings.

The configured array replaces the default punctuation characters. Each item must be a single character, and at least one character is required.

Fix

This rule fixes trailing punctuation by removing it and any whitespace immediately before it.

For example, # Heading ! is fixed to # Heading.

When Not To Use It

If you intentionally use punctuation at the end of headings, you should disable this rule.

Prior Art