Skip to content

Commit

Permalink
fix: some problems with detecting if statements by ifstatements rule
Browse files Browse the repository at this point in the history
FossilOrigin-Name: a759d49586613bd8369ba958d70adde1957f83b99dd665e7b6c7320b13103a40
  • Loading branch information
thindil committed Mar 17, 2024
1 parent f2bbde9 commit ea8c27b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/rules/ifstatements.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit ea8c27b

Please sign in to comment.