From aa92f0821912ab02392914a5bc13bf3864175336 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 4 Sep 2017 18:50:03 +0100 Subject: [PATCH] Fix: support `else if` in return-else-if --- lib/rules/no-else-return.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/rules/no-else-return.js b/lib/rules/no-else-return.js index 36bfc26b3d43..53c7b7c1582b 100644 --- a/lib/rules/no-else-return.js +++ b/lib/rules/no-else-return.js @@ -197,9 +197,6 @@ module.exports = { */ function IfStatement(node) { const parent = context.getAncestors().pop(); - let consequents, - alternate; - /* * Fixing this would require splitting one statement into two, so no error should * be reported if this node is in a position where only one statement is allowed. @@ -208,15 +205,9 @@ module.exports = { return; } - for (consequents = []; node.type === "IfStatement"; node = node.alternate) { - if (!node.alternate) { - return; - } - consequents.push(node.consequent); - alternate = node.alternate; - } + const alternate = node.alternate; - if (consequents.every(alwaysReturns)) { + if (alternate && alwaysReturns(node.consequent)) { displayReport(alternate); } }