Class: RuboCop::Cop::Sorbet::CheckedTrueInSignature

Inherits:
Base
  • Object
show all
Includes:
RangeHelp, SignatureHelp
Defined in:
lib/rubocop/cop/sorbet/signatures/checked_true_in_signature.rb

Overview

Disallows the usage of ‘checked(true)`. This usage could cause confusion; it could lead some people to believe that a method would be checked even if runtime checks have not been enabled on the class or globally. Additionally, in the event where checks are enabled, `checked(true)` would be redundant; only `checked(false)` or `soft` would change the behaviour.

Examples:


# bad
sig { void.checked(true) }

# good
sig { void }

Instance Method Summary collapse

Methods included from SignatureHelp

#on_block, #signature?, #with_runtime?, #without_runtime?

Instance Method Details

#offending_node(node) ⇒ Object



24
25
26
# File 'lib/rubocop/cop/sorbet/signatures/checked_true_in_signature.rb', line 24

def_node_search(:offending_node, <<~PATTERN)
  (send _ :checked (true))
PATTERN

#on_signature(node) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rubocop/cop/sorbet/signatures/checked_true_in_signature.rb', line 35

def on_signature(node)
  error = offending_node(node).first
  return unless error

  add_offense(
    source_range(
      processed_source.buffer,
      error.location.line,
      (error.location.selector.begin_pos)..(error.location.end.begin_pos),
    ),
    message: MESSAGE,
  )
end