diff --git a/spec/ameba/rule/style/redundant_return_spec.cr b/spec/ameba/rule/style/redundant_return_spec.cr index 77ddbab1..4638dfc9 100644 --- a/spec/ameba/rule/style/redundant_return_spec.cr +++ b/spec/ameba/rule/style/redundant_return_spec.cr @@ -104,6 +104,26 @@ module Ameba::Rule::Style end end + context "binary op" do + it "doesn't report if there is no return in the right binary op node" do + s = Source.new %( + def can_create?(a) + valid? && a > 0 + end + ) + subject.catch(s).should be_valid + end + + it "reports if there is return in the right binary op node" do + s = Source.new %( + def can_create?(a) + valid? && return a > 0 + end + ) + subject.catch(s).should_not be_valid + end + end + context "case" do it "reports if there are returns in whens" do s = Source.new %( diff --git a/src/ameba/rule/style/redundant_return.cr b/src/ameba/rule/style/redundant_return.cr index 00202151..ba1b869b 100644 --- a/src/ameba/rule/style/redundant_return.cr +++ b/src/ameba/rule/style/redundant_return.cr @@ -119,6 +119,7 @@ module Ameba::Rule::Style when Crystal::Expressions then check_expressions node when Crystal::If, Crystal::Unless then check_condition node when Crystal::Case then check_case node + when Crystal::BinaryOp then check_binary_op node when Crystal::ExceptionHandler then check_exception_handler node end end @@ -146,6 +147,10 @@ module Ameba::Rule::Style check_node(node.else) end + private def check_binary_op(node) + check_node(node.right) + end + private def check_exception_handler(node) check_node node.body check_node node.else