From ea8c27bd8aa95b84ddf127733d7e405c96362d48 Mon Sep 17 00:00:00 2001 From: thindil Date: Sun, 17 Mar 2024 06:08:49 +0000 Subject: [PATCH] fix: some problems with detecting if statements by ifstatements rule FossilOrigin-Name: a759d49586613bd8369ba958d70adde1957f83b99dd665e7b6c7320b13103a40 --- src/rules/ifstatements.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rules/ifstatements.nim b/src/rules/ifstatements.nim index 300fa37..84f5d92 100644 --- a/src/rules/ifstatements.nim +++ b/src/rules/ifstatements.nim @@ -280,11 +280,11 @@ checkRule: for child in node: if child.kind in {nkIfStmt, nkElifBranch, nkWhenStmt}: var oldAmount: int = rule.amount - if node.len > 1: + if child.len > 1: # Check if the if statement starts with negative condition and has else branch if rule.options[0].toLowerAscii in ["all", "negative"]: try: - checkNegativeCondition(node = node, parent = parentNode, + checkNegativeCondition(node = child, parent = node, messagePrefix = messagePrefix, rule = rule) except Exception as e: rule.amount = errorMessage( @@ -293,12 +293,12 @@ checkRule: # Check if the last if branch can be moved outside the if statement if rule.options[0].toLowerAscii in ["all", "moveable"] and rule.amount == oldAmount: - checkMoveableBranch(node = node, parent = parentNode, + checkMoveableBranch(node = child, parent = node, messagePrefix = messagePrefix, rule = rule, negation = negation) # Check if the if statement contains empty branches (with discard only) if rule.options[0].toLowerAscii in ["all", "empty"] and rule.amount == oldAmount: var checkResult: bool = true - checkEmptyBranch(node = node, parent = parentNode, + checkEmptyBranch(node = child, parent = node, messagePrefix = messagePrefix, rule = rule, checkResult = checkResult) if rule.ruleType == fix and not checkResult: return