Class: RuboCop::Cop::Style::RbsInline::InvalidComment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/style/rbs_inline/invalid_comment.rb

Overview

IRB::Inline expects annotations comments to start with ‘#:` or `# @rbs`. This cop checks for comments that do not match the expected pattern.

Examples:

# bad
# () -> void
# : () -> void
# rbs param: String

# good
#: () -> void
# @rbs param: String

Constant Summary collapse

MSG =
'Invalid RBS annotation comment found.'
RBS_INLINE_KEYWORDS =
%w[inherits override use module-self generic skip module class].freeze
RBS_INLINE_KEYWORD_PATTERN =

: Array

RBS_INLINE_KEYWORDS.join('|')
SIGNATURE_PATTERN =
'\(.*\)\s*(\??\s*{.*?}\s*)?->\s*.*'
MISSING_HASH_COLON =
/\A#\s+#{SIGNATURE_PATTERN}/
SPACE_BEFORE_COLON =
/\A#\s+:\s*#{SIGNATURE_PATTERN}/
MIXED_ANNOTATION =
/\A#:\s+@rbs\s+/
MISSING_AT_SIGN =
/\A#\s*rbs\s+(#{RBS_INLINE_KEYWORD_PATTERN}|\S+:|%a\{.*\}|#{SIGNATURE_PATTERN})/

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject

: void



38
39
40
41
42
# File 'lib/rubocop/cop/style/rbs_inline/invalid_comment.rb', line 38

def on_new_investigation #: void
  consume_embedded_rbs(processed_source.comments).each do |comment|
    check_comment(comment)
  end
end