Class: RuboCop::Cop::Sorbet::ForbidSuperclassConstLiteral
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sorbet::ForbidSuperclassConstLiteral
- Defined in:
- lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
Overview
Correct superclass ‘send` expressions by constant literals.
Sorbet, the static checker, is not (yet) able to support constructs on the following form:
“‘ruby class Foo < send_expr; end “`
Multiple occurences of this can be found in Shopify’s code base like:
“‘ruby class ShopScope < Component::TrustedIdScope “` or “`ruby class ApiClientEligibility < Struct.new(:api_client, :match_results, :shop) “`
Constant Summary collapse
- MSG =
"Superclasses must only contain constant literals"
Instance Method Summary collapse
Instance Method Details
#dynamic_superclass?(node) ⇒ Object
32 33 34 |
# File 'lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb', line 32 def_node_matcher :dynamic_superclass?, <<-PATTERN (class (const ...) $(send ...) ...) PATTERN |
#on_class(node) ⇒ Object
36 37 38 39 40 |
# File 'lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb', line 36 def on_class(node) dynamic_superclass?(node) do |superclass| add_offense(superclass) end end |