mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Include binary op node to redundant return
This commit is contained in:
parent
6a913be980
commit
946ec67fae
2 changed files with 25 additions and 0 deletions
|
@ -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 %(
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue