Typeof scope

This commit is contained in:
Vitalii Elenhaupt 2019-10-27 21:22:33 +02:00
parent 2704a0d8b1
commit 677c75716f
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
2 changed files with 23 additions and 0 deletions

View file

@ -831,6 +831,24 @@ module Ameba::Rule::Lint
end end
end end
context "typeof" do
it "reports useless assigments in typeof" do
s = Source.new %(
typeof(begin
foo = 1
bar = 2
end)
)
subject.catch(s).should_not be_valid
s.issues.size.should eq 2
s.issues.first.location.to_s.should eq ":2:3"
s.issues.first.message.should eq "Useless assignment to variable `foo`"
s.issues.last.location.to_s.should eq ":3:3"
s.issues.last.message.should eq "Useless assignment to variable `bar`"
end
end
context "macro" do context "macro" do
it "doesn't report if assignment is referenced in macro" do it "doesn't report if assignment is referenced in macro" do
s = Source.new %( s = Source.new %(

View file

@ -65,6 +65,11 @@ module Ameba::AST
on_scope_enter(node) on_scope_enter(node)
end end
# :nodoc:
def visit(node : Crystal::TypeOf)
on_scope_enter(node)
end
# :nodoc: # :nodoc:
def visit(node : Crystal::CStructOrUnionDef) def visit(node : Crystal::CStructOrUnionDef)
on_scope_enter(node) on_scope_enter(node)