Class: RuboCop::Cop::Sorbet::ForbidTHelpers

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

Overview

Forbids extend T::Helpers and include T::Helpers in classes and modules.

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

Examples:


# bad
class Example
  extend T::Helpers
end

# bad
module Example
  include T::Helpers
end

# good
class Example
end

Constant Summary collapse

MSG =
"Do not use `%<method>s T::Helpers`."
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_helpers.rb', line 35

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

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

#t_helpers?(node) ⇒ Object



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

def_node_matcher :t_helpers?, <<~PATTERN
  (send _ {:extend :include} (const (const {nil? | cbase} :T) :Helpers))
PATTERN