Skip to content

Commit

Permalink
Fix incorrect error in no-heading-content-indent
Browse files Browse the repository at this point in the history
Fix an error in `no-heading-content-indent` which occurred if
said heading had no content.

Closes wooorm/remark@177.
  • Loading branch information
wooorm committed Apr 26, 2016
1 parent 31f5069 commit 1f2e9a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rules/no-heading-content-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function noHeadingContentIndent(ast, file, preferred, done) {
var depth = node.depth;
var children = node.children;
var type = style(node, 'atx');
var head;
var initial;
var final;
var diff;
Expand All @@ -78,7 +79,17 @@ function noHeadingContentIndent(ast, file, preferred, done) {
}

index = depth + (index - initial.offset);
diff = start(children[0]).column - initial.column - 1 - index;
head = start(children[0]).column;

/*
* Ignore empty headings.
*/

if (!head) {
return;
}

diff = head - initial.column - 1 - index;

if (diff) {
word = diff > 0 ? 'Remove' : 'Add';
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/no-heading-indent-valid.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ Foo

Bar
=====

<!-- Empty headers are fine -->

#####

0 comments on commit 1f2e9a8

Please sign in to comment.