Class: RuboCop::Cop::Sorbet::RedundantExtendTSig

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb

Overview

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.

Examples:

# bad
class Example
  extend T::Sig
  sig { void }
  def no_op; end
end

# good
class Example
  sig { void }
  def no_op; end
end

Cop Safety Information:

  • This cop should not be enabled in applications that have not monkey patched ‘Module`.

Constant Summary collapse

MSG =
"Do not redundantly `extend T::Sig` when it is already included in all modules."
RESTRICT_ON_SEND =
[:extend].freeze

Instance Method Summary collapse

Instance Method Details

#extend_t_sig?(node) ⇒ Object



36
37
38
# File 'lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb', line 36

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

#on_send(node) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rubocop/cop/sorbet/redundant_extend_t_sig.rb', line 40

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

  add_offense(node) do |corrector|
    corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
  end
end