Sha256: cbb9a388ec8e3df5e73f8e51ecd2b5359fe0cef2b6860e3f16e2ee017ff4733d

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks that comment annotation keywords are written according
      # to guidelines.
      class CommentAnnotation < Cop
        include AnnotationComment

        MSG = 'Annotation keywords should be all upper case, followed by a ' \
              'colon and a space, then a note describing the problem.'

        def investigate(processed_source)
          processed_source.comments.each do |comment|
            margin, first_word, colon, space, note = split_comment(comment)
            next unless annotation?(comment) &&
              !correct_annotation?(first_word, colon, space, note)

            start = comment.loc.expression.begin_pos + margin.length
            length = first_word.length + (colon || '').length
            range = Parser::Source::Range.new(processed_source.buffer,
                                              start,
                                              start + length)
            add_offense(nil, range)
          end
        end

        private

        def correct_annotation?(first_word, colon, space, note)
          keyword?(first_word) && (colon && space && note || !colon && !note)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/comment_annotation.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.26.1 lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.26.0 lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.25.0 lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.24.1 lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.24.0 lib/rubocop/cop/style/comment_annotation.rb
rubocop-0.23.0 lib/rubocop/cop/style/comment_annotation.rb