Lint/UnusedArgument: fails to recognized used argument inside macro

closes #117
This commit is contained in:
Vitalii Elenhaupt 2019-10-27 21:32:55 +02:00
parent 677c75716f
commit 904b5beec2
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
2 changed files with 16 additions and 1 deletions

View file

@ -228,6 +228,21 @@ module Ameba::Rule::Lint
)
subject.catch(s).should be_valid
end
it "doesn't report used args in macro literals" do
s = Source.new %(
def print(f : Array(U)) forall U
f.size.times do |i|
{% if U == Float64 %}
puts f[i].round(3)
{% else %}
puts f[i]
{% end %}
end
end
)
subject.catch(s).should be_valid
end
end
context "properties" do

View file

@ -55,7 +55,7 @@ module Ameba::Rule::Lint
private def find_unused_arguments(source, scope)
scope.arguments.each do |argument|
next if argument.ignored? || scope.references?(argument.variable)
next if argument.ignored? || scope.references?(argument.variable) || argument.variable.used_in_macro?
name_suggestion = scope.node.is_a?(Crystal::Block) ? '_' : "_#{argument.name}"
issue_for argument.node, MSG % {argument.name, name_suggestion}