Skip to content

fix(lint): Lint/UnusedBlockArgument is triggered by abstract def #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions spec/ameba/rule/lint/unused_block_argument_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/ameba/rule/lint/unused_block_argument.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down