Skip to content

Commit 1f2e9a8

Browse files
committed
Fix incorrect error in no-heading-content-indent
Fix an error in `no-heading-content-indent` which occurred if said heading had no content. Closes wooorm/remark@177.
1 parent 31f5069 commit 1f2e9a8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/no-heading-content-indent.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function noHeadingContentIndent(ast, file, preferred, done) {
5959
var depth = node.depth;
6060
var children = node.children;
6161
var type = style(node, 'atx');
62+
var head;
6263
var initial;
6364
var final;
6465
var diff;
@@ -78,7 +79,17 @@ function noHeadingContentIndent(ast, file, preferred, done) {
7879
}
7980

8081
index = depth + (index - initial.offset);
81-
diff = start(children[0]).column - initial.column - 1 - index;
82+
head = start(children[0]).column;
83+
84+
/*
85+
* Ignore empty headings.
86+
*/
87+
88+
if (!head) {
89+
return;
90+
}
91+
92+
diff = head - initial.column - 1 - index;
8293

8394
if (diff) {
8495
word = diff > 0 ? 'Remove' : 'Add';

test/fixtures/no-heading-indent-valid.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Foo
77

88
Bar
99
=====
10+
11+
<!-- Empty headers are fine -->
12+
13+
#####

0 commit comments

Comments
 (0)