From 7f6bd2289e52e41431bbb71c460b8f2557f4eed6 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 13 Dec 2022 21:30:44 +0100 Subject: [PATCH] Do not report unused block arguments in `Lint/UnusedArgument` rule --- spec/ameba/rule/lint/unused_argument_spec.cr | 8 ++++---- src/ameba/rule/lint/unused_argument.cr | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/ameba/rule/lint/unused_argument_spec.cr b/spec/ameba/rule/lint/unused_argument_spec.cr index 125ff5f8..47be8ce9 100644 --- a/spec/ameba/rule/lint/unused_argument_spec.cr +++ b/spec/ameba/rule/lint/unused_argument_spec.cr @@ -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 diff --git a/src/ameba/rule/lint/unused_argument.cr b/src/ameba/rule/lint/unused_argument.cr index 66879d27..c42668a5 100644 --- a/src/ameba/rule/lint/unused_argument.cr +++ b/src/ameba/rule/lint/unused_argument.cr @@ -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