Class: RuboCop::Cop::AnnotationComment
- Inherits:
-
Object
- Object
- RuboCop::Cop::AnnotationComment
- Extended by:
- Forwardable
- Defined in:
- lib/rubocop/cop/mixin/annotation_comment.rb
Overview
Representation of an annotation comment in source code (eg. # TODO: blah blah blah
).
Instance Attribute Summary collapse
-
#colon ⇒ Object
readonly
Returns the value of attribute colon.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#space ⇒ Object
readonly
Returns the value of attribute space.
Instance Method Summary collapse
- #annotation? ⇒ Boolean
-
#bounds ⇒ Object
Returns the range bounds for just the annotation.
- #correct?(colon:) ⇒ Boolean
-
#initialize(comment, keywords) ⇒ AnnotationComment
constructor
A new instance of AnnotationComment.
Constructor Details
#initialize(comment, keywords) ⇒ AnnotationComment
Returns a new instance of AnnotationComment.
13 14 15 16 17 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 13 def initialize(comment, keywords) @comment = comment @keywords = keywords @margin, @keyword, @colon, @space, @note = split_comment(comment) end |
Instance Attribute Details
#colon ⇒ Object (readonly)
Returns the value of attribute colon.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def colon @colon end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def comment @comment end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def keyword @keyword end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def margin @margin end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def note @note end |
#space ⇒ Object (readonly)
Returns the value of attribute space.
9 10 11 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 9 def space @space end |
Instance Method Details
#annotation? ⇒ Boolean
19 20 21 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 19 def annotation? keyword_appearance? && !just_keyword_of_sentence? end |
#bounds ⇒ Object
Returns the range bounds for just the annotation
31 32 33 34 35 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 31 def bounds start = comment.source_range.begin_pos + margin.length length = [keyword, colon, space].reduce(0) { |len, elem| len + elem.to_s.length } [start, start + length] end |
#correct?(colon:) ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/rubocop/cop/mixin/annotation_comment.rb', line 23 def correct?(colon:) return false unless keyword && space && note return false unless keyword == keyword.upcase self.colon.nil? == !colon end |