mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Support of Crystal::UnitializedVar
This commit is contained in:
parent
415432713a
commit
efe67212b0
2 changed files with 38 additions and 1 deletions
|
@ -852,5 +852,33 @@ module Ameba::Rule
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should_not be_valid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "uninitialized" do
|
||||||
|
it "reports if uninitialized assignment is not referenced at a top level" do
|
||||||
|
s = Source.new %(
|
||||||
|
a = uninitialized U
|
||||||
|
)
|
||||||
|
subject.catch(s).should_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports if uninitialized assignment is not referenced in a method" do
|
||||||
|
s = Source.new %(
|
||||||
|
def foo
|
||||||
|
a = uninitialized U
|
||||||
|
end
|
||||||
|
)
|
||||||
|
subject.catch(s).should_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't report if uninitialized assignment is referenced" do
|
||||||
|
s = Source.new %(
|
||||||
|
def foo
|
||||||
|
a = uninitialized U
|
||||||
|
a
|
||||||
|
end
|
||||||
|
)
|
||||||
|
subject.catch(s).should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@ module Ameba::AST
|
||||||
@current_assign : Crystal::ASTNode?
|
@current_assign : Crystal::ASTNode?
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def visit(node : Crystal::Assign | Crystal::OpAssign | Crystal::MultiAssign)
|
def visit(node : Crystal::Assign | Crystal::OpAssign | Crystal::MultiAssign | Crystal::UninitializedVar)
|
||||||
@current_assign = node
|
@current_assign = node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -89,12 +89,21 @@ module Ameba::AST
|
||||||
def end_visit(node : Crystal::Assign | Crystal::OpAssign)
|
def end_visit(node : Crystal::Assign | Crystal::OpAssign)
|
||||||
@current_scope.assign_variable(node.target)
|
@current_scope.assign_variable(node.target)
|
||||||
@current_assign = nil
|
@current_assign = nil
|
||||||
|
on_scope_end(node) if @current_scope.eql?(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def end_visit(node : Crystal::MultiAssign)
|
def end_visit(node : Crystal::MultiAssign)
|
||||||
node.targets.each { |target| @current_scope.assign_variable(target) }
|
node.targets.each { |target| @current_scope.assign_variable(target) }
|
||||||
@current_assign = nil
|
@current_assign = nil
|
||||||
|
on_scope_end(node) if @current_scope.eql?(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
# :nodoc:
|
||||||
|
def end_visit(node : Crystal::UninitializedVar)
|
||||||
|
@current_scope.assign_variable(node.var)
|
||||||
|
@current_assign = nil
|
||||||
|
on_scope_end(node) if @current_scope.eql?(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
Loading…
Reference in a new issue