Skip to content

no-irregular-dash

✅ Recommended 🔧 Fixable ⭐ CommonMark 🌟 GFM

🔗 Rule Source 🔗 Test Source

Disallow irregular dash.

Rule Details ​

This rule is aimed at identifying and preventing the use of irregular dash characters in Markdown documents. Irregular dashes can cause issues with Markdown parsers, create inconsistencies in document formatting, and lead to potential rendering problems across different platforms.

In particular, when irregular dash characters are used in place of the standard ASCII hyphen-minus (-, \u002D), especially in syntactically meaningful contexts like list items or horizontal rules, they can lead to rendering errors or formatting inconsistencies.

The rule helps ensure that only standard ASCII hyphen-minus characters (-, \u002D) are used instead of their Unicode lookalikes, which improves document consistency and prevents potential parsing problems.

This rule disallows the following characters except where the options allow:

txt
\u2010 - Hyphen - <HYPH>
\u2011 - Non-Breaking Hyphen - <NBHY>
\u2012 - Figure Dash - <FIGDASH>
\u2013 - En Dash - <ENDASH>
\u2014 - Em Dash - <EMDASH>
\u2015 - Horizontal Bar - <HYPHBAR>
\u2043 - Hyphen Bullet - <HYPHBUL>
\u2212 - Minus Sign - <MINUS>
\u23AF - Horizontal Line Extension - <HLINE>
\u2E3A - Two Em Dash - <2EMDASH>
\u2E3B - Three Em Dash - <3EMDASH>
\u30FC - Katakana-Hiragana Prolonged Sound Mark - <KHPROLSND>
\uFE58 - Small Em Dash - <SMEMDASH>
\uFE63 - Small Hyphen Minus - <SMHYPMINUS>
\uFF0D - Fullwidth Hyphen-Minus - <FWHYPHMNUS>

Examples ​

❌ Incorrect ​

Examples of incorrect code for this rule:

Default ​

md
<!-- eslint md/no-irregular-dash: 'error' -->

\u2010 - Hyphen - <HYPH> 
‐
<= Here
\u2011 - Non-Breaking Hyphen - <NBHY>
‑
<= Here
\u2012 - Figure Dash - <FIGDASH>
‒
<= Here
\u2013 - En Dash - <ENDASH>
–
<= Here
\u2014 - Em Dash - <EMDASH>
—
<= Here
\u2015 - Horizontal Bar - <HYPHBAR>
―
<= Here
\u2043 - Hyphen Bullet - <HYPHBUL>
⁃
<= Here
\u2212 - Minus Sign - <MINUS>
−
<= Here
\u23AF - Horizontal Line Extension - <HLINE>
⎯
<= Here
\u2E3A - Two Em Dash - <2EMDASH>
⸺
<= Here
\u2E3B - Three Em Dash - <3EMDASH>
⸻
<= Here
\u30FC - Katakana-Hiragana Prolonged Sound Mark - <KHPROLSND>
ー
<= Here
\uFE58 - Small Em Dash - <SMEMDASH>
﹘
<= Here
\uFE63 - Small Hyphen Minus - <SMHYPMINUS>
﹣
<= Here
\uFF0D - Fullwidth Hyphen-Minus - <FWHYPHMNUS>
-
<= Here

With { override: { '\u2013': '--', '\u2014': '---' } } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { override: { '\u2013': '--', '\u2014': '---' } }] -->

\u2013 - En Dash - <ENDASH> 
–
<= Here
\u2014 - Em Dash - <EMDASH>
—
<= Here

With { skipCode: false } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipCode: false }] -->

```md
\u2010 - Hyphen - <HYPH> 
‐
<= Here
\u2011 - Non-Breaking Hyphen - <NBHY>
‑
<= Here
``` ````md \u2012 - Figure Dash - <FIGDASH>
‒
<= Here
\u2013 - En Dash - <ENDASH>
–
<= Here
```` ~~~txt \u2014 - Em Dash - <EMDASH>
—
<= Here
\u2015 - Horizontal Bar - <HYPHBAR>
―
<= Here
~~~ \u2043 - Hyphen Bullet - <HYPHBUL>
⁃
<= Here
\u2212 - Minus Sign - <MINUS>
−
<= Here

With { skipCode: ['js', 'ts'] } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipCode: ['js', 'ts'] }] -->

```md
\u2010 - Hyphen - <HYPH> 
‐
<= Here
\u2011 - Non-Breaking Hyphen - <NBHY>
‑
<= Here
``` ```txt \u2012 - Figure Dash - <FIGDASH>
‒
<= Here
\u2013 - En Dash - <ENDASH>
–
<= Here
``` \u2043 - Hyphen Bullet - <HYPHBUL>
⁃
<= Here
\u2212 - Minus Sign - <MINUS>
−
<= Here

With { skipInlineCode: false } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipInlineCode: false }] -->

\u2010 - Hyphen - <HYPH> `
‐
` <= Here
\u2011 - Non-Breaking Hyphen - <NBHY> `
‑
` <= Here

With { skipMath: false } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipMath: false }] -->

$$
\u2212 - Minus Sign - <MINUS> 
−
<= Here
$$

With { skipInlineMath: false } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipInlineMath: false }] -->

\u2212 - Minus Sign - <MINUS> $
−
$ <= Here

✅ Correct ​

Examples of correct code for this rule:

Default ​

md
<!-- eslint md/no-irregular-dash: 'error' -->

\u002D - Hyphen Minus - <HYPHMNUS> - <= Here

With { allow: ['\u2013', '\u2014'] } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { allow: ['\u2013', '\u2014'] }] -->

\u2013 - En Dash - <ENDASH> – <= Here
\u2014 - Em Dash - <EMDASH> — <= Here

With { skipCode: true } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipCode: true }] -->

```md
\u2010 - Hyphen - <HYPH> ‐ <= Here
\u2011 - Non-Breaking Hyphen - <NBHY> ‑ <= Here
```

````md
\u2012 - Figure Dash - <FIGDASH> ‒ <= Here
\u2013 - En Dash - <ENDASH> – <= Here
````

~~~txt
\u2014 - Em Dash - <EMDASH> — <= Here
\u2015 - Horizontal Bar - <HYPHBAR> ― <= Here
~~~

    \u2043 - Hyphen Bullet - <HYPHBUL> ⁃ <= Here
    \u2212 - Minus Sign - <MINUS> − <= Here

With { skipCode: ['md', 'txt'] } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipCode: ['md', 'txt'] }] -->

```md
\u2010 - Hyphen - <HYPH> ‐ <= Here
\u2011 - Non-Breaking Hyphen - <NBHY> ‑ <= Here
```

```txt
\u2012 - Figure Dash - <FIGDASH> ‒ <= Here
\u2013 - En Dash - <ENDASH> – <= Here
```

With { skipInlineCode: true } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipInlineCode: true }] -->

\u2010 - Hyphen - <HYPH> `‐` <= Here
\u2011 - Non-Breaking Hyphen - <NBHY> `‑` <= Here

With { skipMath: true } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipMath: true }] -->

$$
\u2212 - Minus Sign - <MINUS> − <= Here
$$

With { skipInlineMath: true } Option ​

md
<!-- eslint md/no-irregular-dash: ['error', { skipInlineMath: true }] -->

\u2212 - Minus Sign - <MINUS> $−$ <= Here

Options ​

js
'md/no-irregular-dash': ['error', {
  allow: [],
  override: {},
  skipCode: true,
  skipInlineCode: true,
  skipMath: true,
  skipInlineMath: true,
}]

allow ​

Type: string[] / Default: []

When specified, specific irregular dash characters are allowed if they match one of the characters in this array. This is useful for ignoring certain irregular dashes that are intentionally used in the document.

override ​

Type: Record<string, string> / Default: {}

An object where the key is an irregular dash character and the value is the string that replaces it. Only the characters listed in Rule Details can be used as keys.

Overriding a default replacement ​

For example, to replace an en dash with -- and an em dash with ---:

js
'md/no-irregular-dash': ['error', {
  override: {
    '\u2013': '--',
    '\u2014': '---',
  },
}]

Fixing can change the Markdown structure

If a dash stands alone on a line, the fixed line can be parsed differently. For example, – below a paragraph becomes a Setext heading underline, and with '\u2014': '---', — on its own line becomes a thematic break.

skipCode ​

Type: boolean | string[] / Default: true

true allows irregular dashes in all code blocks, while string[] allows irregular dashes only in code blocks for the specified languages.

skipInlineCode ​

Type: boolean / Default: true

true allows irregular dashes in all inline code.

skipMath ​

Type: boolean / Default: true

true allows irregular dashes in all math blocks.

NOTE

This option requires enabling math parsing with languageOptions: { math: true }.

skipInlineMath ​

Type: boolean / Default: true

true allows irregular dashes in all inline math.

NOTE

This option requires enabling math parsing with languageOptions: { math: true }.

Fix ​

This rule fixes the irregular dashes by replacing them with the ASCII hyphen-minus (-), or with the value configured through the override option.

When Not To Use It ​

If you deliberately want to use typographically correct dash characters in your Markdown documents, such as em dashes for parenthetical statements or en dashes for ranges, you may want to disable this rule.