class RuboCop::Cop::Layout::LeadingCommentSpace
#ruby-gemset=myproject
#ruby=2.7.0
# good
@example AllowGemfileRubyComment: true
#ruby-gemset=myproject
#ruby=2.7.0
# bad
@example AllowGemfileRubyComment: false (default)
#*
# Another line of comment
# Some comment
#**
# good
@example AllowDoxygenCommentStyle: true
#*
# Another line of comment
# Some comment
#**
# bad
@example AllowDoxygenCommentStyle: false (default)
# 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
Checks whether comments have a leading space after the
def allow_doxygen_comment?
def allow_doxygen_comment? cop_config['AllowDoxygenCommentStyle'] end
def allow_gemfile_ruby_comment?
def allow_gemfile_ruby_comment? cop_config['AllowGemfileRubyComment'] end
def allowed_on_first_line?(comment)
def allowed_on_first_line?(comment) shebang?(comment) || (rackup_config_file? && rackup_options?(comment)) end
def doxygen_comment_style?(comment)
def doxygen_comment_style?(comment) allow_doxygen_comment? && comment.text.start_with?('#*') end
def gemfile?
def gemfile? File.basename(processed_source.file_path).eql?('Gemfile') end
def gemfile_ruby_comment?(comment)
def gemfile_ruby_comment?(comment) allow_gemfile_ruby_comment? && ruby_comment_in_gemfile?(comment) end
def hash_mark(expr)
def hash_mark(expr) range_between(expr.begin_pos, expr.begin_pos + 1) end
def on_new_investigation
def on_new_investigation processed_source.comments.each do |comment| next unless /\A#+[^#\s=+-]/.match?(comment.text) next if comment.loc.line == 1 && allowed_on_first_line?(comment) next if doxygen_comment_style?(comment) next if gemfile_ruby_comment?(comment) add_offense(comment) do |corrector| expr = comment.source_range corrector.insert_after(hash_mark(expr), ' ') end 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 ruby_comment_in_gemfile?(comment)
def ruby_comment_in_gemfile?(comment) gemfile? && comment.text.start_with?('#ruby') end
def shebang?(comment)
def shebang?(comment) comment.text.start_with?('#!') end