Class: RuboCop::Cop::Momocop::RbiMissingExtendTSig

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

Overview

Ensures that Sorbet signature declarations are accompanied by ‘extend T::Sig`.

sig calls must be block-form invocations that appear immediately above a method definition to be considered.

Examples:

# bad
class User
  sig { void }
  def call; end
end

# good
class User
  extend T::Sig

  sig { void }
  def call; end
end

Constant Summary collapse

MSG =
'Add `extend T::Sig` when using `sig` to type methods.'

Instance Method Summary collapse

Instance Method Details

#on_class(node) ⇒ Object



39
40
41
# File 'lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb', line 39

def on_class(node)
  check_node(node, body_nodes(node), node.loc.keyword)
end

#on_module(node) ⇒ Object



43
44
45
# File 'lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb', line 43

def on_module(node)
  check_node(node, body_nodes(node), node.loc.keyword)
end

#on_new_investigationObject



51
52
53
54
55
56
# File 'lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb', line 51

def on_new_investigation
  return unless processed_source.ast

  top_level_nodes = top_level_body_nodes(processed_source.ast)
  check_node(nil, top_level_nodes, top_level_offense_location(top_level_nodes))
end

#on_sclass(node) ⇒ Object



47
48
49
# File 'lib/rubocop/cop/momocop/rbi_missing_extend_t_sig.rb', line 47

def on_sclass(node)
  check_node(node, body_nodes(node), node.loc.keyword)
end