Class: RuboCop::Cop::Style::RbsInline::InvalidTypes
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Style::RbsInline::InvalidTypes
- Includes:
- RBS::Inline::AST::Annotations, RBS::Inline::AST::Members, RangeHelp
- Defined in:
- lib/rubocop/cop/style/rbs_inline/invalid_types.rb
Overview
IRB::Inline expects the types of annotation comments are valid syntax. This cop checks for comments that do not match the expected pattern.
Constant Summary collapse
- MSG =
'Invalid annotation found.'
Instance Method Summary collapse
-
#on_new_investigation ⇒ Object
: void # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
Instance Method Details
#on_new_investigation ⇒ Object
: void # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/style/rbs_inline/invalid_types.rb', line 30 def on_new_investigation #: void # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity results = parse_comments results.each do |result| result.each_annotation do |annotation| location = annotation.source.comments.first&.location or raise range = range_between(character_offset(location.start_offset), character_offset(location.end_offset)) case annotation when Application add_offense(range) unless annotation.types when BlockType, IvarType, SpecialVarTypeAnnotation, VarType add_offense(range) unless annotation.type when Generic add_offense(range) unless annotation.type_param when ModuleSelf add_offense(range) if annotation.self_types.empty? when SyntaxErrorAssertion add_offense(range) when Embedded comment = annotation.source.comments.fetch(0) parsing_result = RBS::Inline::AnnotationParser::ParsingResult.new(comment) = RBSEmbedded.new(parsing_result, annotation) add_offense(range) if .members.is_a?(RBS::ParsingError) end end end end |