Class: RuboCop::Cop::Layout::MultiLineBlockSpacing

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/layout/multi_line_block_spacing.rb

Overview

Requires a blank line between two consecutive statements when either of them spans multiple lines. Adjacent single-line statements need no blank line. The boundary with the enclosing ‘def`/`do`/`end` is left to other cops.

Detection-only (no autocorrect) for now — the comment-handling and autocorrect behaviour need validation against the real repos first.

Examples:

# bad
foo(
  bar
)
baz

# good
foo(
  bar
)

baz

Constant Summary collapse

MSG =
'Add a blank line around multi-line statements.'

Instance Method Summary collapse

Instance Method Details

#on_begin(node) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/layout/multi_line_block_spacing.rb', line 33

def on_begin(node)
  node.children.each_cons(2) do |first, second|
    next unless first.is_a?(::RuboCop::AST::Node) && second.is_a?(::RuboCop::AST::Node)
    next unless first.multiline? || second.multiline?
    next if blank_line_between?(first, second)

    add_offense(second)
  end
end