Sha256: 760e42d0298618edf154a6e3727ac9d37d4f211be4041e9e27d02357c96c6b6b

Contents?: true

Size: 957 Bytes

Versions: 7

Compression:

Stored size: 957 Bytes

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|
            next unless comment.text =~ /^#+[^#\s=:+-]/
            next if comment.text.start_with?('#!') && comment.loc.line == 1

            add_offense(comment, :expression)
          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)
          ->(corrector) { corrector.insert_after(hash_mark, ' ') }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubocop-0.34.2 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.34.1 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.34.0 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.33.0 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.32.1 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.32.0 lib/rubocop/cop/style/leading_comment_space.rb
rubocop-0.31.0 lib/rubocop/cop/style/leading_comment_space.rb