class RuboCop::Cop::Layout::LeadingCommentSpace
# Some comment
# good
#Some comment
# bad
@example
or rackup options.
‘#:nodoc`, `=begin`- and `=end` comments, “shebang” directives,
required for some RDoc special syntax, like `#++`, `#–`,
`#` denoting the start of the comment. The leading space is not
This cop checks whether comments have a leading space after the
def allowed_on_first_line?(comment)
def allowed_on_first_line?(comment) shebang?(comment) || rackup_config_file? && rackup_options?(comment) end
def autocorrect(comment)
def autocorrect(comment) expr = comment.loc.expression hash_mark = range_between(expr.begin_pos, expr.begin_pos + 1) ->(corrector) { corrector.insert_after(hash_mark, ' ') } end
def investigate(processed_source)
def investigate(processed_source) processed_source.each_comment do |comment| next unless comment.text =~ /\A#+[^#\s=:+-]/ next if comment.loc.line == 1 && allowed_on_first_line?(comment) add_offense(comment) end end
def rackup_config_file?
def rackup_config_file? File.basename(processed_source.file_path).eql?('config.ru') end
def rackup_options?(comment)
def rackup_options?(comment) comment.text.start_with?('#\\') end
def shebang?(comment)
def shebang?(comment) comment.text.start_with?('#!') end