class RuboCop::Cop::Style::BlockEndNewline
}
foo(i)
blah { |i|
# good
foo(i) }
blah { |i|
# bad
end
foo(i)
blah do |i|
# good
foo(i) end
blah do |i|
# bad
@example
is on its own line.
This cop checks whether the end statement of a do end blocks
def autocorrect(node)
def autocorrect(node) @corrections << lambda do |corrector| indentation = indentation_of_block_start_line(node) corrector.insert_before(node.loc.end, "\n" + (' ' * indentation)) end end
def indentation_of_block_start_line(node)
def indentation_of_block_start_line(node) match = /\S.*/.match(node.loc.begin.source_line) match.begin(0) end
def on_block(node)
def on_block(node) end_loc = node.loc.end do_loc = node.loc.begin # Actually it's either do or {. return if do_loc.line == end_loc.line # Ignore one-liners. # If the end is on its own line, there is no offense return if /^\s*#{end_loc.source}/.match(end_loc.source_line) msg = format(MSG, end_loc.line, end_loc.column + 1) add_offense(node, end_loc, msg) end