mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Merge pull request #449 from crystal-ameba/fix-issue-446
Do not report type declarations within generic records
This commit is contained in:
commit
28fafea19f
2 changed files with 18 additions and 4 deletions
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue