class Rubocop::Cop::Style::Blocks

Check for uses of braces or do/end around single line or multi-line blocks.

Constants

MULTI_LINE_MSG
SINGLE_LINE_MSG

Public Instance Methods

on_block(node) click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/blocks.rb, line 12
def on_block(node)
  block_length = Util.block_length(node)
  block_begin = node.loc.begin.source

  if block_length > 0 && block_begin == '{'
    add_offence(:convention, node.loc.begin, MULTI_LINE_MSG)
  elsif block_length == 0 && block_begin != '{'
    add_offence(:convention, node.loc.begin, SINGLE_LINE_MSG)
  end

  super
end