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

Commit f9f203b

Browse files
committed
requireNewlineBeforeSingleStatementsInIf: correct it for 2.x branch
1 parent 703cad3 commit f9f203b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/rules/require-newline-before-single-statements-in-if.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,32 @@ module.exports.prototype = {
7373
function getToken(entity, tokenType, tokenProperty) {
7474
if (entity.type === tokenType || !entity[tokenProperty]) {
7575
return entity;
76-
} else {
77-
return getToken(entity[tokenProperty], tokenType, tokenProperty);
7876
}
77+
78+
return getToken(entity[tokenProperty], tokenType, tokenProperty);
7979
}
8080

8181
file.iterateNodesByType('IfStatement', function(node) {
82+
var token;
8283
var consequentNode = node.consequent;
8384
var alternateNode = node.alternate;
8485

8586
if (isExpressionStatement(consequentNode)) {
86-
assertDifferentLine(consequentNode, getToken(consequentNode, 'Keyword', 'previousSibling'));
87+
token = file.getFirstNodeToken(consequentNode);
88+
89+
assertDifferentLine(
90+
consequentNode,
91+
file.findPrevToken(token, 'Keyword')
92+
);
8793
}
8894

8995
if (isExpressionStatement(alternateNode)) {
90-
assertDifferentLine(alternateNode, getToken(alternateNode, 'Keyword', 'previousSibling'));
96+
token = file.getFirstNodeToken(alternateNode);
97+
98+
assertDifferentLine(
99+
alternateNode,
100+
file.findPrevToken(token, 'Keyword')
101+
);
91102
}
92103
});
93104
}

0 commit comments

Comments
 (0)