Sha256: c784926757aa1b42a2938ea79a3260bb14e4a378c2b8af16377ee7962eb46e60

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

require 'rubocop'

# 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[ShopIdentity::ShopId]
# ```
# or
# ```ruby
# class ApiClientEligibility < Struct.new(:api_client, :match_results, :shop)
# ```
module RuboCop
  module Cop
    module Sorbet
      class ForbidSuperclassConstLiteral < RuboCop::Cop::Cop
        MSG = 'Superclasses must only contain constant literals'

        def_node_matcher :not_lit_const_superclass?, <<-PATTERN
          (class
            (const ...)
            (send ...)
            ...
          )
        PATTERN

        def on_class(node)
          return unless not_lit_const_superclass?(node)
          add_offense(node.child_nodes[1])
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-sorbet-0.6.2 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.1 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.0 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.5.1 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.5.0 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb