Incorrectly reporting shadowingOuterLocalVar within macro included

closes #129
This commit is contained in:
Vitalii Elenhaupt 2020-02-15 20:49:47 +02:00
parent 43b566a852
commit aff723b682
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
5 changed files with 45 additions and 2 deletions

View file

@ -84,4 +84,20 @@ module Ameba::AST
scope.block?.should be_false
end
end
describe "#macro?" do
it "returns true if Crystal::Macro" do
nodes = as_nodes %(
macro included
end
)
scope = Scope.new nodes.macro_nodes.first
scope.macro?.should be_true
end
it "returns false otherwise" do
scope = Scope.new as_node "a = 1"
scope.macro?.should be_false
end
end
end

View file

@ -174,5 +174,24 @@ module Ameba::Rule::Lint
issue.end_location.should be_nil
issue.message.should eq "Shadowing outer local variable `foo`"
end
context "macro" do
it "does not report shadowed vars A" do
source = Source.new %(
macro included
def foo
{% for ivar in instance_vars %}
{% ann = ivar.annotation(Name) %}
{% end %}
end
def bar
{% instance_vars.reject { |ivar| ivar } %}
end
end
)
subject.catch(source).should be_valid
end
end
end
end

View file

@ -139,6 +139,7 @@ module Ameba
Crystal::OpAssign,
Crystal::MultiAssign,
Crystal::Block,
Crystal::Macro,
Crystal::Def,
Crystal::If,
Crystal::While,