Do not report type declarations within generic records

This commit is contained in:
Sijawusz Pur Rahnama 2024-01-16 02:04:41 +01:00
parent b56d34715d
commit f2677d68f6
2 changed files with 18 additions and 4 deletions

View File

@ -394,6 +394,12 @@ module Ameba::Rule::Lint
CRYSTAL
end
it "doesn't report if this is a record declaration (generics)" do
expect_no_issues subject, <<-CRYSTAL
record Foo(T), foo : T
CRYSTAL
end
it "doesn't report if this is an accessor declaration" do
accessor_macros = %w[setter class_setter]
%w[getter class_getter property class_property].each do |name|

View File

@ -173,9 +173,10 @@ module Ameba::AST
scope = @current_scope
case
when scope.top_level? && record_macro?(node) then return false
when scope.type_definition? && record_macro?(node) then return false
when scope.type_definition? && accessor_macro?(node) then return false
when (scope.top_level? || scope.type_definition?) && record_macro?(node)
return false
when scope.type_definition? && accessor_macro?(node)
return false
when scope.def? && special_node?(node)
scope.arguments.each do |arg|
ref = arg.variable.reference(scope)
@ -194,7 +195,14 @@ module Ameba::AST
end
private def record_macro?(node)
node.name == "record" && node.args.first?.is_a?(Crystal::Path)
return false unless node.name == "record"
case node.args.first?
when Crystal::Path, Crystal::Generic
true
else
false
end
end
private def skip?(node)