Class: RuboCop::Cop::Sane::EmptyLineBeforeComment

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/sane/empty_line_before_comment.rb

Overview

Enforces an empty line before comments, except when the previous line is the start of a block, class, method, or another comment.

Examples:

# bad
foo = 1
# This is a comment
bar = 2

# good
foo = 1

# This is a comment
bar = 2

# good - after block/class/method start
def foo
  # This comment doesn't need a blank line
  bar
end

# good - consecutive comments
# First comment
# Second comment

# good - after control structure start
if condition
  # Comment inside if
  do_something
end

Constant Summary collapse

MSG =
"Add empty line before comment."

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



42
43
44
45
46
# File 'lib/rubocop/cop/sane/empty_line_before_comment.rb', line 42

def on_new_investigation
  processed_source.comments.each do |comment|
    check_comment(comment)
  end
end