Class: RuboCop::Cop::Momocop::Layout::LeadingCommentSpace
- Inherits:
-
Layout::LeadingCommentSpace
- Object
- Layout::LeadingCommentSpace
- RuboCop::Cop::Momocop::Layout::LeadingCommentSpace
- Defined in:
- lib/rubocop/cop/momocop/layout/leading_comment_space.rb
Overview
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`, `=begin`- and `=end` comments, “shebang” directives, or rackup options, or rbs-inline typing.
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubocop/cop/momocop/layout/leading_comment_space.rb', line 54 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) next if rbs_inline_comment_style?(comment) add_offense(comment) do |corrector| expr = comment.source_range corrector.insert_after(hash_mark(expr), ' ') end end end |
#rbs_inline_comment_style?(comment) ⇒ Boolean
70 71 72 |
# File 'lib/rubocop/cop/momocop/layout/leading_comment_space.rb', line 70 def rbs_inline_comment_style?(comment) comment.text.start_with?('#:') end |