mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Handle raise, exit, abort in unreachable code
This commit is contained in:
parent
67d76116f7
commit
eca0f3f350
2 changed files with 160 additions and 7 deletions
|
@ -33,13 +33,46 @@ module Ameba::Rule::Lint
|
|||
it "doesn't report if there are returns in if-then-else" do
|
||||
s = Source.new %(
|
||||
if a > 0
|
||||
return :positivie
|
||||
return :positive
|
||||
else
|
||||
return :negative
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
it "doesn't report if return is used in a block" do
|
||||
s = Source.new %(
|
||||
def foo
|
||||
bar = obj.try do
|
||||
if something
|
||||
a = 1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
bar
|
||||
end
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
|
||||
pending "reports if there is unreachable code after if-then-else" do
|
||||
s = Source.new %(
|
||||
def foo
|
||||
if a > 0
|
||||
return :positive
|
||||
else
|
||||
return :negative
|
||||
end
|
||||
|
||||
:unreachable
|
||||
end
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":8:4"
|
||||
end
|
||||
end
|
||||
|
||||
context "break" do
|
||||
|
@ -98,5 +131,98 @@ module Ameba::Rule::Lint
|
|||
subject.catch(s).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "raise" do
|
||||
it "reports if there is unreachable code after raise" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
raise "exception"
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:1"
|
||||
end
|
||||
|
||||
it "doesn't report if raise is in a condition" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
raise "exception" if a > 0
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "exit" do
|
||||
it "reports if there is unreachable code after exit without args" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
exit
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:1"
|
||||
end
|
||||
|
||||
it "reports if there is unreachable code after exit with exit code" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
exit 1
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:1"
|
||||
end
|
||||
|
||||
it "doesn't report if exit is in a condition" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
exit if a > 0
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "abort" do
|
||||
it "reports if there is unreachable code after abort with one argument" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
abort "abort"
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:1"
|
||||
end
|
||||
|
||||
it "reports if there is unreachable code after abort with two args" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
abort "abort", 1
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should_not be_valid
|
||||
|
||||
issue = s.issues.first
|
||||
issue.location.to_s.should eq ":3:1"
|
||||
end
|
||||
|
||||
it "doesn't report if abort is in a condition" do
|
||||
s = Source.new %(
|
||||
a = 1
|
||||
abort "abort" if a > 0
|
||||
b = 2
|
||||
)
|
||||
subject.catch(s).should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue