Skip to content

Commit bab9670

Browse files
authored
fix: ensure ATX headings follow spec for space after hash characters (#421)
* fix: ensure ATX headings follow spec for space after hash characters * test: use \u00A0 for non-breaking spaces
1 parent fdf559e commit bab9670

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/rules/no-missing-atx-heading-space.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// Helpers
1717
//-----------------------------------------------------------------------------
1818

19-
const headingPattern = /^(#{1,6})(?:[^#\s]|$)/u;
19+
const headingPattern = /^(#{1,6})(?:[^# \t]|$)/u;
2020
const newLinePattern = /\r?\n/u;
2121

2222
//-----------------------------------------------------------------------------

tests/rules/no-missing-atx-heading-space.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ const validHeadings = [
106106

107107
// 12. Content starting with more than 4 spaces(turn to codeblock)
108108
" #Heading 1",
109+
110+
// 13. Valid Spaces
111+
"## \u00A0Normal outer non-breaking inner space",
112+
"## Normal space (both) ##",
113+
"## \u00A0Normal outer non-breaking inner space (both)\u00A0 ##",
114+
"##\tTab",
115+
"##\tTab (left) ##",
116+
"## Tab (right)\t##",
109117
];
110118

111119
//------------------------------------------------------------------------------
@@ -475,6 +483,34 @@ const invalidTests = [
475483
},
476484
],
477485
},
486+
487+
// 8. Invalid Spaces
488+
{
489+
code: "##\u00A0Non-breaking space",
490+
output: "## \u00A0Non-breaking space",
491+
errors: [
492+
{
493+
messageId: "missingSpace",
494+
column: 1,
495+
line: 1,
496+
endLine: 1,
497+
endColumn: 4,
498+
},
499+
],
500+
},
501+
{
502+
code: "##\u00A0\u00A0Extra non-breaking space",
503+
output: "## \u00A0\u00A0Extra non-breaking space",
504+
errors: [
505+
{
506+
messageId: "missingSpace",
507+
column: 1,
508+
line: 1,
509+
endLine: 1,
510+
endColumn: 4,
511+
},
512+
],
513+
},
478514
];
479515

480516
ruleTester.run("no-missing-atx-heading-space", rule, {

0 commit comments

Comments
 (0)