Class: RuboCop::Cop::Sorbet::ForbidTSig

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sorbet/forbid_t_sig.rb

Overview

Forbids ‘extend T::Sig` and `include T::Sig` in classes and modules.

This is useful when using RBS or RBS-inline syntax for type signatures, where ‘T::Sig` is not needed and including it is redundant.

Examples:


# bad
class Example
  extend T::Sig
end

# bad
module Example
  include T::Sig
end

# good
class Example
end

Constant Summary collapse

MSG =
"Do not use `%<method>s T::Sig`."
RESTRICT_ON_SEND =
[:extend, :include].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object Also known as: on_csend



35
36
37
38
39
# File 'lib/rubocop/cop/sorbet/forbid_t_sig.rb', line 35

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

  add_offense(node, message: format(MSG, method: node.method_name))
end

#t_sig?(node) ⇒ Object



31
32
33
# File 'lib/rubocop/cop/sorbet/forbid_t_sig.rb', line 31

def_node_matcher :t_sig?, "(send _ {:extend :include} (const (const {nil? | cbase} :T) :Sig))\n"