From 17e9566c7eeb491757ff527f9bc3f0f7cc6ddcb9 Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Sun, 19 Feb 2023 09:21:37 +0200 Subject: [PATCH] fix(lint): Lint/UnusedBlockArgument is triggered by abstract def closes #352 --- spec/ameba/rule/lint/unused_block_argument_spec.cr | 7 +++++++ src/ameba/rule/lint/unused_block_argument.cr | 2 ++ 2 files changed, 9 insertions(+) diff --git a/spec/ameba/rule/lint/unused_block_argument_spec.cr b/spec/ameba/rule/lint/unused_block_argument_spec.cr index d5ad799c..2a577dab 100644 --- a/spec/ameba/rule/lint/unused_block_argument_spec.cr +++ b/spec/ameba/rule/lint/unused_block_argument_spec.cr @@ -89,6 +89,13 @@ module Ameba::Rule::Lint CRYSTAL end + it "doesn't report if used in abstract def" do + expect_no_issues subject, <<-CRYSTAL + abstract def debug(id : String, &on_message: Callback) + abstract def info(&on_message: Callback) + CRYSTAL + end + context "super" do it "reports if variable is not referenced implicitly by super" do source = expect_issue subject, <<-CRYSTAL diff --git a/src/ameba/rule/lint/unused_block_argument.cr b/src/ameba/rule/lint/unused_block_argument.cr index 7fdb0f67..a3497b02 100644 --- a/src/ameba/rule/lint/unused_block_argument.cr +++ b/src/ameba/rule/lint/unused_block_argument.cr @@ -47,6 +47,8 @@ module Ameba::Rule::Lint end def test(source, node : Crystal::Def, scope : AST::Scope) + return if node.abstract? + return unless block_arg = node.block_arg return unless block_arg = scope.arguments.find(&.node.== block_arg)