Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
requireNewlineBeforeSingleStatementsInIf: don't blow on single if branch
Browse files Browse the repository at this point in the history
Fixes #2174
  • Loading branch information
markelog committed Mar 11, 2016
1 parent bbde83c commit fbe9bf4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/require-newline-before-single-statements-in-if.js
Expand Up @@ -82,6 +82,10 @@ module.exports.prototype = {
var consequentNode = node.consequent;
var alternateNode = node.alternate;

if (!alternateNode) {
return;
}

if (isExpressionStatement(consequentNode)) {
assertDifferentLine(consequentNode, getToken(consequentNode, 'Keyword', 'previousSibling'));
}
Expand Down
Expand Up @@ -14,6 +14,10 @@ describe('rules/require-newline-before-single-statements-in-if', function() {
checker.configure({ requireNewlineBeforeSingleStatementsInIf: true });
});

it('should not blow up for single branch `if`', function() {
expect(checker.checkString('if (x) true')).to.have.no.errors();
});

it('should ignore if in a block statment', function() {
expect(checker.checkString('if (x) {\n doX();\n} else {\n doY();\n}')).to.have.no.errors();
});
Expand Down

0 comments on commit fbe9bf4

Please sign in to comment.