Ignore outer shadowing of throwaway variables

closes #67
This commit is contained in:
Vitalii Elenhaupt 2018-06-25 17:01:07 +03:00
parent 98f0aa71e9
commit dbac46b68a
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
2 changed files with 14 additions and 0 deletions

View file

@ -138,6 +138,19 @@ module Ameba::Rule::Lint
subject.catch(source).should be_valid
end
it "doesn't report if it shadows throwaway arguments" do
source = Source.new %(
data = [{1, "a"}, {2, "b"}, {3, "c"}]
data.each do |_, string|
data.each do |number, _|
puts string, number
end
end
)
subject.catch(source).should be_valid
end
it "reports rule, location and message" do
source = Source.new %(
foo = 1

View file

@ -53,6 +53,7 @@ module Ameba::Rule::Lint
private def find_shadowing(source, scope)
scope.arguments.each do |arg|
next if arg.ignored?
if scope.outer_scope.try &.find_variable(arg.name)
issue_for arg, MSG % arg.name
end