diff --git a/spec/ameba/rule/lint/useless_assign_spec.cr b/spec/ameba/rule/lint/useless_assign_spec.cr index b80501fd1..e8fe41d54 100644 --- a/spec/ameba/rule/lint/useless_assign_spec.cr +++ b/spec/ameba/rule/lint/useless_assign_spec.cr @@ -513,6 +513,20 @@ module Ameba::Rule::Lint CRYSTAL end + it "doesn't report if assignment is referenced within a method call" do + expect_no_issues subject, <<-CRYSTAL + if v = rand + puts(v = 1) + end + v + CRYSTAL + + expect_no_issues subject, <<-CRYSTAL + puts v = 1 unless v = rand + v + CRYSTAL + end + it "reports if assignment is useless in the branch" do expect_issue subject, <<-CRYSTAL def method(a) diff --git a/src/ameba/ast/branch.cr b/src/ameba/ast/branch.cr index 309298801..3c958f7d1 100644 --- a/src/ameba/ast/branch.cr +++ b/src/ameba/ast/branch.cr @@ -181,6 +181,8 @@ module Ameba::AST if loop?(node) && (block = node.block) on_branchable_start node, block.body end + + true end def end_visit(node : Crystal::Call)