diff --git a/spec/ameba/rule/lint/unused_argument_spec.cr b/spec/ameba/rule/lint/unused_argument_spec.cr index df533c52..69bac6ea 100644 --- a/spec/ameba/rule/lint/unused_argument_spec.cr +++ b/spec/ameba/rule/lint/unused_argument_spec.cr @@ -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 diff --git a/src/ameba/rule/lint/unused_argument.cr b/src/ameba/rule/lint/unused_argument.cr index 6abadca8..d4d9a1b9 100644 --- a/src/ameba/rule/lint/unused_argument.cr +++ b/src/ameba/rule/lint/unused_argument.cr @@ -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}