Class: RuboCop::Cop::Style::RbsInline::UnmatchedAnnotations

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

Overview

IRB::Inline annotations comments for parameters should be matched to the parameters.

Examples:

# bad
# @rbs unknown: String
def method(arg); end

# good
# @rbs arg: String
def method(arg); end

Constant Summary collapse

MSG =
'target parameter not found.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject (readonly)

: Array



25
26
27
# File 'lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb', line 25

def result
  @result
end

Instance Method Details

#on_def(node) ⇒ Object



33
34
35
# File 'lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb', line 33

def on_def(node) #: void
  process(node)
end

#on_defs(node) ⇒ Object



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

def on_defs(node) #: void
  process(node)
end

#on_investigation_endObject

: void



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb', line 42

def on_investigation_end #: void
  result.each do |comment|
    comment.each_annotation do |annotation|
      case annotation
      when RBS::Inline::AST::Annotations::BlockType,
           RBS::Inline::AST::Annotations::ReturnType,
           RBS::Inline::AST::Annotations::VarType
        add_offense_for(annotation)
      end
    end
  end

  super
end

#on_new_investigationObject

: void



27
28
29
30
# File 'lib/rubocop/cop/style/rbs_inline/unmatched_annotations.rb', line 27

def on_new_investigation #: void
  super
  @result = parse_comments
end