Class: RuboCop::Cop::Style::RbsInline::ParametersSeparator

Inherits:
Base
  • Object
show all
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/style/rbs_inline/parameters_separator.rb

Overview

IRB::Inline expects annotations comments for parameters are separeted with ‘:`or allows annotation comments. This cop checks for comments that do not match the expected pattern.

Examples:

# bad
# @rbs param String

# bad
# @rbs :param String

# good
# @rbs param: String

# good
# @rbs %a{pure}

Constant Summary collapse

MSG =
'Use `:` as a separator between parameter name and type.'
RBS_INLINE_KEYWORDS =
%w[inherits override use module-self generic skip module class].freeze
RBS_INLINE_REGEXP_KEYWORDS =

: Array

[/%a{(\w|-)+}/, /%a\((\w|-)+\)/, /%a\[(\w|-)+\]/].freeze

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject

: void



31
32
33
34
35
36
37
38
39
40
# File 'lib/rubocop/cop/style/rbs_inline/parameters_separator.rb', line 31

def on_new_investigation #: void
  processed_source.comments.each do |comment|
    matched = comment.text.match(/\A#\s+@rbs\s+(\S+)/)

    next unless matched
    next if valid_rbs_inline_comment?(matched[1])

    add_offense(invalid_location_for(comment))
  end
end