Do not report unused block arguments in Lint/UnusedArgument rule

This commit is contained in:
Sijawusz Pur Rahnama 2022-12-13 21:30:44 +01:00
parent 858557bc07
commit 7f6bd2289e
2 changed files with 8 additions and 4 deletions

View file

@ -115,21 +115,21 @@ module Ameba::Rule::Lint
subject.catch(s).should be_valid
end
it "reports if block arg is not used" do
it "doesn't report if block arg is not used" do
s = Source.new %(
def method(&block)
end
)
subject.catch(s).should_not be_valid
subject.catch(s).should be_valid
end
it "reports if unused and there is yield" do
it "doesn't report if unused and there is yield" do
s = Source.new %(
def method(&block)
yield 1
end
)
subject.catch(s).should_not be_valid
subject.catch(s).should be_valid
end
it "doesn't report if it's an anonymous block" do

View file

@ -50,6 +50,10 @@ module Ameba::Rule::Lint
end
def test(source, node : Crystal::Def, scope : AST::Scope)
# `Lint/UnusedBlockArgument` rule covers this case explicitly
if block_arg = node.block_arg
scope.arguments.reject!(&.node.== block_arg)
end
ignore_defs? || find_unused_arguments source, scope
end