Sha256: b5ff937c1349371cbaa0f2cfa0dc7ce1b11d68b5d0a168ab3d8a5343a8ad205c

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks whether comments have a leading space
      # after the # denoting the start of the comment. The
      # leading space is not required for some RDoc special syntax,
      # like #++, #--, #:nodoc, etc.
      class LeadingCommentSpace < Cop
        MSG = 'Missing space after #.'

        def investigate(processed_source)
          processed_source.comments.each do |comment|
            if comment.text =~ /^#+[^#\s:+-]/
              unless comment.text.start_with?('#!') && comment.loc.line == 1
                add_offense(comment, :expression)
              end
            end
          end
        end

        def autocorrect(comment)
          expr = comment.loc.expression
          b = expr.begin_pos
          hash_mark = Parser::Source::Range.new(expr.source_buffer, b, b + 1)
          @corrections << lambda do |corrector|
            corrector.insert_after(hash_mark, ' ')
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.21.0 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.20.1 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.20.0 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.19.1 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.19.0 lib/rubocop/cop/style/leading_comment_space.rb