Sha256: fb1cd12f6fdb351c48ad06aa85bf5c3f388b37fad2faaddad61dd0676c3dfa81

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Sorbet
      # Forbids the use of redundant `extend T::Sig`. Only for use in
      # applications that monkey patch `Module.include(T::Sig)` globally,
      # which would make it redundant.
      #
      # @safety
      #   This cop should not be enabled in applications that have not monkey
      #   patched `Module`.
      #
      # @example
      #   # bad
      #   class Example
      #     extend T::Sig
      #     sig { void }
      #     def no_op; end
      #   end
      #
      #   # good
      #   class Example
      #     sig { void }
      #     def no_op; end
      #   end
      #
      class RedundantExtendTSig < RuboCop::Cop::Cop
        MSG = "Do not redundantly `extend T::Sig` when it is already included in all modules."
        RESTRICT_ON_SEND = [:extend].freeze

        def_node_matcher :extend_t_sig?, <<~PATTERN
          (send _ :extend (const (const {nil? | cbase} :T) :Sig))
        PATTERN

        def on_send(node)
          return unless extend_t_sig?(node)

          add_offense(node)
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(node)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-sorbet-0.7.0 lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb