Include binary op node to redundant return

This commit is contained in:
Vitalii Elenhaupt 2020-03-22 20:12:24 +02:00
parent 6a913be980
commit 946ec67fae
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
2 changed files with 25 additions and 0 deletions

View file

@ -104,6 +104,26 @@ module Ameba::Rule::Style
end end
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 context "case" do
it "reports if there are returns in whens" do it "reports if there are returns in whens" do
s = Source.new %( s = Source.new %(

View file

@ -119,6 +119,7 @@ module Ameba::Rule::Style
when Crystal::Expressions then check_expressions node when Crystal::Expressions then check_expressions node
when Crystal::If, Crystal::Unless then check_condition node when Crystal::If, Crystal::Unless then check_condition node
when Crystal::Case then check_case node when Crystal::Case then check_case node
when Crystal::BinaryOp then check_binary_op node
when Crystal::ExceptionHandler then check_exception_handler node when Crystal::ExceptionHandler then check_exception_handler node
end end
end end
@ -146,6 +147,10 @@ module Ameba::Rule::Style
check_node(node.else) check_node(node.else)
end end
private def check_binary_op(node)
check_node(node.right)
end
private def check_exception_handler(node) private def check_exception_handler(node)
check_node node.body check_node node.body
check_node node.else check_node node.else