diff --git a/spec/ameba/rule/lint/useless_assign_spec.cr b/spec/ameba/rule/lint/useless_assign_spec.cr index 7c7310de..1ea3d3ba 100644 --- a/spec/ameba/rule/lint/useless_assign_spec.cr +++ b/spec/ameba/rule/lint/useless_assign_spec.cr @@ -998,6 +998,16 @@ module Ameba::Rule::Lint CRYSTAL end + it "doesn't report if it's referenced in a lib" do + expect_no_issues subject, <<-CRYSTAL + lib LibFoo + struct Foo + a : Int32 + end + end + CRYSTAL + end + it "doesn't report if it's referenced" do expect_no_issues subject, <<-CRYSTAL def foo diff --git a/src/ameba/rule/lint/useless_assign.cr b/src/ameba/rule/lint/useless_assign.cr index ed7d536d..900e5d5e 100644 --- a/src/ameba/rule/lint/useless_assign.cr +++ b/src/ameba/rule/lint/useless_assign.cr @@ -39,6 +39,8 @@ module Ameba::Rule::Lint end def test(source, node, scope : AST::Scope) + return if scope.lib_def?(check_outer_scopes: true) + scope.variables.each do |var| next if var.ignored? || var.used_in_macro? || var.captured_by_block? next if exclude_type_declarations? && scope.assigns_type_dec?(var.name)