Class: RuboCop::Cop::Style::RbsInline::RedundantAnnotationWithSkip

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

Overview

Checks for redundant type annotations when ‘@rbs skip` or `@rbs override` is present.

‘@rbs skip` tells RBS::Inline to skip RBS generation for this method entirely. `@rbs override` tells RBS::Inline to inherit the type signature from the parent class. In both cases, any additional type annotations (method type signatures, parameter annotations, return type annotations) are redundant and will be ignored by RBS::Inline.

Examples:

# bad - redundant method type signature with @rbs skip
# @rbs skip
#: (Integer) -> void
def method(a)
end

# bad - redundant doc-style method type annotation with @rbs skip
# @rbs skip
# @rbs (Integer) -> void
def method(a)
end

# bad - redundant param annotation with @rbs skip
# @rbs skip
# @rbs a: Integer
def method(a)
end

# bad - redundant trailing return type with @rbs skip
# @rbs skip
def method(a) #: void
end

# bad - redundant type annotations with @rbs override
# @rbs override
# @rbs a: Integer
def method(a)
end

# good
# @rbs skip
def method(a)
end

# good
# @rbs override
def method(a)
end

Constant Summary collapse

MSG_METHOD_TYPE_SIGNATURE =
'Redundant method type signature. ' \
'`@rbs skip` and `@rbs override` skip RBS generation.'
MSG_DOC_STYLE_ANNOTATION =
'Redundant `@rbs` annotation. ' \
'`@rbs skip` and `@rbs override` skip RBS generation.'
MSG_TRAILING_RETURN =
'Redundant trailing return type annotation. ' \
'`@rbs skip` and `@rbs override` skip RBS generation.'
MSG_DUPLICATE_SKIP =
'Duplicate `@rbs skip` annotation.'
MSG_DUPLICATE_OVERRIDE =
'Duplicate `@rbs override` annotation.'
MSG_CONFLICTING_SKIP_OVERRIDE =
'`@rbs skip` and `@rbs override` cannot both be specified.'

Instance Attribute Summary

Attributes included from CommentParser

#parsed_comments

Instance Method Summary collapse

Methods included from SourceCodeHelper

#annotation_range, #blank_line?, #char_at, #character_offset, #comment_at, #comment_range, #line_range, #location_to_range, #source_code_at

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 Also known as: on_defs



82
83
84
# File 'lib/rubocop/cop/style/rbs_inline/redundant_annotation_with_skip.rb', line 82

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

#on_new_investigationObject

: void



76
77
78
79
# File 'lib/rubocop/cop/style/rbs_inline/redundant_annotation_with_skip.rb', line 76

def on_new_investigation #: void
  super
  parse_comments
end