Class: RuboCop::Cop::Yoshiki::Layout::EmptyLineBeforeComment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/yoshiki/layout/empty_line_before_comment.rb

Overview

Requires a blank line before a full-line comment group when the previous physical line is code at the same indent.

Consecutive # lines and a =begin/=end document are each one group: one blank before the first line, nothing inserted inside. =begin is always column 0, so it still gets a blank when the preceding code is indented.

Trailing comments stay on their code line. A # comment that opens a body (class / module / def / do / begin / {) sits deeper than the opener, so it is left alone. Extra indent is not a substitute for a blank — Layout/CommentIndentation will pull those comments back.

# rubocop: directives glue to the code they apply to. # rubocop:enable in particular frequently trails a region and must not grow a blank line.

Examples:

# bad
include Foo
# associations
has_many :bars

# good
include Foo

# associations
has_many :bars
# good — first non-empty line of a body
def join!
  # players
  seats << player
end
# good — enable trails the disabled region
complicated_call(a, b, c)
# rubocop:enable Metrics/MethodLength
# good — disable glues to the following statement
simple_call
# rubocop:disable Metrics/MethodLength
complicated_call(a, b, c)
# bad
include Foo
=begin
associations
=end
has_many :bars

# good
include Foo

=begin
associations
=end
has_many :bars

Constant Summary collapse

MSG =
'Add a blank line before this comment.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



76
77
78
# File 'lib/rubocop/cop/yoshiki/layout/empty_line_before_comment.rb', line 76

def on_new_investigation
  processed_source.comments.each { inspect_comment(it) }
end