Skip to content

Remove naive solution for #447 #452

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
Jan 22, 2024
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
5 changes: 3 additions & 2 deletions spec/ameba/rule/lint/useless_assign_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,12 @@ module Ameba::Rule::Lint
CRYSTAL
end

it "doesn't report type declaration as a call argument" do
pending "doesn't report type declaration as a call argument" do
expect_no_issues subject, <<-CRYSTAL
foo Foo(T), foo : T
foo Foo, foo : Nil
foo foo : String, bar : Int32?
foo foo : String
foo foo : String, bar : Int32?, baz : Bool
CRYSTAL
end

Expand Down
10 changes: 1 addition & 9 deletions src/ameba/rule/lint/useless_assign.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,14 @@ module Ameba::Rule::Lint

scope.variables.each do |var|
next if var.ignored? || var.used_in_macro? || var.captured_by_block?

if scope.assigns_type_dec?(var.name)
next if exclude_type_declarations? || expressions_with_call?(node)
end
next if exclude_type_declarations? && scope.assigns_type_dec?(var.name)

var.assignments.each do |assign|
check_assignment(source, assign, var)
end
end
end

private def expressions_with_call?(node)
node.is_a?(Crystal::Expressions) &&
node.expressions.first?.is_a?(Crystal::Call)
end

private def check_assignment(source, assign, var)
return if assign.referenced?

Expand Down