Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::LeadingCommentSpace

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.

Constants

MSG

Public Instance Methods

autocorrect(comment) click to toggle source
# File lib/rubocop/cop/style/leading_comment_space.rb, line 21
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
investigate(processed_source) click to toggle source
# File lib/rubocop/cop/style/leading_comment_space.rb, line 12
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

[Validate]

Generated with the Darkfish Rdoc Generator 2.