Sha256: 59b73c803eba693af09d2647782e6715f21fefa59f47a89cbb0a7267f6d8a749

Contents?: true

Size: 1.02 KB

Versions: 10

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

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-sorbet-0.7.0 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.11 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.10 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.9 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.8 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.7 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.6 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.5 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.4 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.6.3 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb