Sha256: 6b315db3b35cc79f29cc25dfc5ffe89fe34b449ed04c718a69237f5e31f964ed

Contents?: true

Size: 1019 Bytes

Versions: 11

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

require "rubocop"

module RuboCop
  module Cop
    module Sorbet
      # Disallows defining type aliases that contain shapes
      #
      # @example
      #
      #  # bad
      #  Foo = T.type_alias { { foo: Integer } }
      #
      #  # good
      #  class Foo
      #    extend T::Sig
      #
      #    sig { params(foo: Integer).void }
      #    def initialize(foo)
      #      @foo = foo
      #    end
      #  end
      class ForbidTypeAliasedShapes < RuboCop::Cop::Base
        MSG = "Type aliases shouldn't contain shapes because of significant performance overhead"

        # @!method shape_type_alias?(node)
        def_node_matcher(:shape_type_alias?, <<-PATTERN)
          (block
            (send (const {nil? cbase} :T) :type_alias)
            (args)
            `hash
          )
        PATTERN

        def on_block(node)
          add_offense(node) if shape_type_alias?(node)
        end

        alias_method :on_numblock, :on_block
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubocop-sorbet-0.8.7 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.6 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.5 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.4 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.3 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.2 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.1 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.8.0 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.7.8 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.7.7 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb
rubocop-sorbet-0.7.6 lib/rubocop/cop/sorbet/forbid_type_aliased_shapes.rb