Class: RuboCop::Cop::Sorbet::EnforceSignatures::RBSSignatureChecker

Inherits:
SignatureChecker
  • Object
show all
Defined in:
lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb

Constant Summary collapse

RBS_COMMENT_REGEX =
/^#\s*:.*$/

Instance Method Summary collapse

Methods inherited from SignatureChecker

#initialize

Constructor Details

This class inherits a constructor from RuboCop::Cop::Sorbet::EnforceSignatures::SignatureChecker

Instance Method Details

#signature_node(node) ⇒ Object



212
213
214
215
216
217
218
219
220
221
# File 'lib/rubocop/cop/sorbet/signatures/enforce_signatures.rb', line 212

def signature_node(node)
  node = find_non_send_ancestor(node)
  comments = preceding_comments(node)
  return if comments.empty?

  last_comment = comments.last
  return if last_comment.loc.line + 1 < node.loc.line

  comments.find { |comment| RBS_COMMENT_REGEX.match?(comment.text) }
end