Skip to content

Commit

Permalink
Support new type_member / type_template syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Apr 27, 2022
1 parent 2fce9e3 commit 30d8ac6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rubocop/cop/sorbet/binding_constants_without_type_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ class BindingConstantWithoutTypeAlias < RuboCop::Cop::Cop
)
PATTERN

def_node_matcher(:generic_parameter_decl?, <<-PATTERN)
def_node_matcher(:generic_parameter_decl_call?, <<-PATTERN)
(
send nil? {:type_template :type_member} ...
)
PATTERN

def_node_matcher(:generic_parameter_decl_block_call?, <<-PATTERN)
(block
(send nil? {:type_template :type_member}) ...
)
PATTERN

def_node_search(:method_needing_aliasing_on_t?, <<-PATTERN)
(
send
Expand All @@ -81,7 +87,7 @@ def not_dynamic_type_creation_with_block?(node)
end

def not_generic_parameter_decl?(node)
!generic_parameter_decl?(node)
!generic_parameter_decl_call?(node) && !generic_parameter_decl_block_call?(node)
end

def not_nil?(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ def deprecation
it("allows assigning type_member to a constant") do
expect_no_offenses(<<~RUBY)
A = type_member(fixed: T.untyped)
A = type_member { { fixed: T.class_of(::ActiveRecord::Base) } }
RUBY
end

it("allows assigning type_template to a constant") do
expect_no_offenses(<<~RUBY)
A = type_template(fixed: T.untyped)
A = type_template { { fixed: T.class_of(::ActiveRecord::Base) } }
RUBY
end

Expand Down

0 comments on commit 30d8ac6

Please sign in to comment.