Properly detect if scope references a variable

This commit is contained in:
Vitalii Elenhaupt 2019-10-27 21:53:07 +02:00
parent 904b5beec2
commit 19d9223ec1
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
2 changed files with 4 additions and 3 deletions

View file

@ -90,8 +90,9 @@ module Ameba::AST
# false if not.
def references?(variable : Variable)
variable.references.any? do |reference|
reference.scope == self || inner_scopes.any?(&.references? variable)
end
reference.scope == self ||
inner_scopes.any?(&.references? variable)
end || variable.used_in_macro?
end
# Returns true if current scope is a def, false if not.

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) || argument.variable.used_in_macro?
next if argument.ignored? || scope.references?(argument.variable)
name_suggestion = scope.node.is_a?(Crystal::Block) ? '_' : "_#{argument.name}"
issue_for argument.node, MSG % {argument.name, name_suggestion}