Lint/UselessAssign: ignore transformed assignemnts by the compiler

closes #127
This commit is contained in:
Vitalii Elenhaupt 2020-01-11 23:50:42 +02:00
parent 976f9729d5
commit 74dfa0b934
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
4 changed files with 82 additions and 1 deletions

View file

@ -87,5 +87,32 @@ module Ameba::AST
assignment.branch.should be_nil
end
end
describe "#transformed?" do
it "returns false if the assignment is not transformed by the compiler" do
nodes = as_nodes %(
def method(a)
a = 2
end
)
scope = Scope.new nodes.def_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable)
assignment.transformed?.should be_false
end
it "returns true if the assignment is transformed by the compiler" do
nodes = as_nodes %(
array.each do |(a, b)|
end
)
scope = Scope.new nodes.block_nodes.first
variable = Variable.new(nodes.var_nodes.first, scope)
assignment = Assignment.new(nodes.assign_nodes.first, variable)
assignment.transformed?.should be_true
end
end
end
end