class RuboCop::Cop::Layout::BlockEndNewline
This cop checks whether the end statement of a do..end block is on its own line.
@example
# bad blah do |i| foo(i) end # good blah do |i| foo(i) end # bad blah { |i| foo(i) } # good blah { |i| foo(i) }
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/layout/block_end_newline.rb, line 41 def autocorrect(node) lambda do |corrector| corrector.replace(delimiter_range(node), "\n#{node.loc.end.source}#{offset(node)}") end end
on_block(node)
click to toggle source
# File lib/rubocop/cop/layout/block_end_newline.rb, line 32 def on_block(node) return if node.single_line? # If the end is on its own line, there is no offense return if begins_its_line?(node.loc.end) add_offense(node, location: :end) end
Private Instance Methods
delimiter_range(node)
click to toggle source
# File lib/rubocop/cop/layout/block_end_newline.rb, line 54 def delimiter_range(node) Parser::Source::Range.new(node.loc.expression.source_buffer, node.children.last.loc.expression.end_pos, node.loc.expression.end_pos) end
message(node)
click to toggle source
# File lib/rubocop/cop/layout/block_end_newline.rb, line 50 def message(node) format(MSG, line: node.loc.end.line, column: node.loc.end.column + 1) end