mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
parent
d843afd962
commit
429f76f8b6
3 changed files with 21 additions and 11 deletions
|
@ -39,6 +39,22 @@ module Ameba::AST
|
||||||
flow_expression.unreachable_nodes.should eq nodes.assign_nodes
|
flow_expression.unreachable_nodes.should eq nodes.assign_nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns nil if there is no unreachable node after loop" do
|
||||||
|
nodes = as_nodes %(
|
||||||
|
def run
|
||||||
|
idx = items.size - 1
|
||||||
|
while 0 <= idx
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "foo"
|
||||||
|
end
|
||||||
|
)
|
||||||
|
node = nodes.expressions_nodes.first
|
||||||
|
flow_expression = FlowExpression.new node, false
|
||||||
|
flow_expression.unreachable_nodes.empty?.should eq true
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if there is no unreachable node" do
|
it "returns nil if there is no unreachable node" do
|
||||||
nodes = as_nodes %(
|
nodes = as_nodes %(
|
||||||
def foobar
|
def foobar
|
||||||
|
|
|
@ -420,7 +420,7 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
|
|
||||||
context "while/until" do
|
context "while/until" do
|
||||||
it "reports if there is unreachable code after while" do
|
it "does not report if there is no unreachable code after while" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
def method
|
def method
|
||||||
while something
|
while something
|
||||||
|
@ -434,13 +434,10 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should be_valid
|
||||||
|
|
||||||
issue = s.issues.first
|
|
||||||
issue.location.to_s.should eq ":9:3"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports if there is unreachable code after until" do
|
it "does not report if there is no unreachable code after until" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
def method
|
def method
|
||||||
until something
|
until something
|
||||||
|
@ -454,10 +451,7 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should be_valid
|
||||||
|
|
||||||
issue = s.issues.first
|
|
||||||
issue.location.to_s.should eq ":9:3"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't report if there is reachable code after while with break" do
|
it "doesn't report if there is reachable code after while with break" do
|
||||||
|
|
|
@ -55,7 +55,7 @@ module Ameba::AST
|
||||||
control_flow_found = false
|
control_flow_found = false
|
||||||
current_node.expressions.each do |exp|
|
current_node.expressions.each do |exp|
|
||||||
unreachable_nodes << exp if control_flow_found
|
unreachable_nodes << exp if control_flow_found
|
||||||
control_flow_found ||= flow_expression?(exp, in_loop?)
|
control_flow_found ||= !loop?(exp) && flow_expression?(exp, in_loop?)
|
||||||
end
|
end
|
||||||
when Crystal::BinaryOp
|
when Crystal::BinaryOp
|
||||||
unreachable_nodes << current_node.right if flow_expression?(current_node.left, in_loop?)
|
unreachable_nodes << current_node.right if flow_expression?(current_node.left, in_loop?)
|
||||||
|
|
Loading…
Reference in a new issue