Module: RuboCop::Cop::Sorbet::SignatureHelp

Extended by:
NodePattern::Macros
Included in:
CheckedTrueInSignature, EmptyLineAfterSig, EnforceSignatures, KeywordArgumentOrdering, SignatureBuildOrder, VoidCheckedTests
Defined in:
lib/rubocop/cop/sorbet/mixin/signature_help.rb

Overview

Mixin for writing cops for signatures, providing a ‘signature?` node matcher and an `on_signature` trigger.

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object Also known as: on_numblock



29
30
31
# File 'lib/rubocop/cop/sorbet/mixin/signature_help.rb', line 29

def on_block(node)
  on_signature(node) if signature?(node)
end

#on_signature(_node) ⇒ Object



35
36
37
# File 'lib/rubocop/cop/sorbet/mixin/signature_help.rb', line 35

def on_signature(_node)
  # To be defined by cop class as needed
end

#signature?(node) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rubocop/cop/sorbet/mixin/signature_help.rb', line 11

def_node_matcher(:signature?, <<~PATTERN)
  (block (send
    {nil? #with_runtime? #without_runtime?}
    :sig
    (sym :final)?
  ) (args) ...)
PATTERN

#with_runtime?(node) ⇒ Object



20
21
22
# File 'lib/rubocop/cop/sorbet/mixin/signature_help.rb', line 20

def_node_matcher(:with_runtime?, <<~PATTERN)
  (const (const {nil? cbase} :T) :Sig)
PATTERN

#without_runtime?(node) ⇒ Object



25
26
27
# File 'lib/rubocop/cop/sorbet/mixin/signature_help.rb', line 25

def_node_matcher(:without_runtime?, <<~PATTERN)
  (const (const (const {nil? cbase} :T) :Sig) :WithoutRuntime)
PATTERN