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

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

Overview

IRB::Inline expects annotations comments for parameters are separated 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



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

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

    next unless matched
    next if valid_rbs_inline_comment?(matched[:keyword])

    add_offense(invalid_location_for(comment, matched)) do |corrector|
      keyword = matched[:keyword] || raise
      corrector.replace(keyword_range(comment, matched), corrected_keyword(keyword))
    end
  end
end