Class: RuboCop::Cop::Style::RbsInline::KeywordSeparator
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Style::RbsInline::KeywordSeparator
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, CommentParser
- Defined in:
- lib/rubocop/cop/style/rbs_inline/keyword_separator.rb
Overview
IRB::Inline expects annotations comments for keywords are not separeted with ‘:`. This cop checks for comments that do not match the expected pattern.
Constant Summary collapse
- MSG =
'Do not use `:` after the keyword.'- RBS_INLINE_KEYWORDS =
%w[inherits override use module-self generic skip module class].freeze
- NO_ARGUMENT_KEYWORDS =
‘override` and `skip` are standalone markers that take no arguments. Even before a method definition they may not be followed by `:` alone, because `# @rbs override:` (no type) is not a valid parameter annotation. Only `# @rbs override: SomeType` (with a type) is valid as a parameter annotation.
%w[override skip].freeze
Instance Attribute Summary
Attributes included from CommentParser
Instance Method Summary collapse
- #on_def(node) ⇒ Object
- #on_defs(node) ⇒ Object
-
#on_investigation_end ⇒ Object
: void.
- #on_new_investigation ⇒ Object
Methods included from CommentParser
#find_doc_style_param_annotations, #find_doc_style_return_annotation, #find_last_consecutive_comment, #find_leading_annotation, #find_method_type_signature_comments, #find_trailing_comment, #overload_type_signatures?, #parse_comments
Instance Method Details
#on_def(node) ⇒ Object
41 42 43 |
# File 'lib/rubocop/cop/style/rbs_inline/keyword_separator.rb', line 41 def on_def(node) #: void collect_method_annotation_comments(node.loc.line) end |
#on_defs(node) ⇒ Object
46 47 48 |
# File 'lib/rubocop/cop/style/rbs_inline/keyword_separator.rb', line 46 def on_defs(node) #: void collect_method_annotation_comments(node.loc.line) end |
#on_investigation_end ⇒ Object
: void
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rubocop/cop/style/rbs_inline/keyword_separator.rb', line 50 def on_investigation_end #: void processed_source.comments.each do |comment| matched = comment.text.match(/\A#\s+@rbs\s+(#{RBS_INLINE_KEYWORDS.join('|')}):/) next unless matched next if valid_method_annotation?(comment) range = invalid_location_for(comment, matched) add_offense(range) do |corrector| corrector.remove(range) end end super end |
#on_new_investigation ⇒ Object
34 35 36 37 38 |
# File 'lib/rubocop/cop/style/rbs_inline/keyword_separator.rb', line 34 def on_new_investigation #: void super parse_comments @method_annotation_lines = Set.new #: Set[Integer] end |