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

Commit

Permalink
requireNewlineBeforeSingleStatementsInIf: correct it for 2.x branch
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Feb 27, 2016
1 parent 703cad3 commit f9f203b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/rules/require-newline-before-single-statements-in-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,32 @@ module.exports.prototype = {
function getToken(entity, tokenType, tokenProperty) {
if (entity.type === tokenType || !entity[tokenProperty]) {
return entity;
} else {
return getToken(entity[tokenProperty], tokenType, tokenProperty);
}

return getToken(entity[tokenProperty], tokenType, tokenProperty);
}

file.iterateNodesByType('IfStatement', function(node) {
var token;
var consequentNode = node.consequent;
var alternateNode = node.alternate;

if (isExpressionStatement(consequentNode)) {
assertDifferentLine(consequentNode, getToken(consequentNode, 'Keyword', 'previousSibling'));
token = file.getFirstNodeToken(consequentNode);

assertDifferentLine(
consequentNode,
file.findPrevToken(token, 'Keyword')
);
}

if (isExpressionStatement(alternateNode)) {
assertDifferentLine(alternateNode, getToken(alternateNode, 'Keyword', 'previousSibling'));
token = file.getFirstNodeToken(alternateNode);

assertDifferentLine(
alternateNode,
file.findPrevToken(token, 'Keyword')
);
}
});
}
Expand Down

0 comments on commit f9f203b

Please sign in to comment.