Sha256: d8d573d3a1be11896979011f7be7053e2228a7c1d950c423cdebb7d0a97e2825

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

require "rubocop"

module RuboCop
  module Cop
    module Sorbet
      # 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)
      # ```

      class ForbidSuperclassConstLiteral < RuboCop::Cop::Base
        MSG = "Superclasses must only contain constant literals"

        # @!method dynamic_superclass?(node)
        def_node_matcher :dynamic_superclass?, <<-PATTERN
          (class (const ...) $(send ...) ...)
        PATTERN

        def on_class(node)
          dynamic_superclass?(node) do |superclass|
            add_offense(superclass)
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rubocop-sorbet-0.8.7 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.6 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.5 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.4 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.3 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.2 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.1 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.8.0 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.8 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.7 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.6 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.5 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.4 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.3 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.2 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb
rubocop-sorbet-0.7.1 lib/rubocop/cop/sorbet/forbid_superclass_const_literal.rb