Parent

Methods

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::SpaceBeforeBlockBraces

Checks that block braces have or don't have a space before the opening brace depending on configuration.

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/style/space_before_block_braces.rb, line 10
def on_block(node)
  return if node.loc.begin.is?('do') # No braces.

  # If braces are on separate lines, and the Blocks cop is enabled,
  # those braces will be changed to do..end by the user or by
  # auto-correct, so reporting space issues is not useful, and it
  # creates auto-correct conflicts.
  if config.for_cop('Style/Blocks')['Enabled'] &&
      Util.block_length(node) > 0
    return
  end

  left_brace = node.loc.begin
  space_plus_brace = range_with_surrounding_space(left_brace)
  used_style =
    space_plus_brace.source.start_with?('{') ? :no_space : :space

  case used_style
  when style  then correct_style_detected
  when :space then space_detected(left_brace, space_plus_brace)
  else             space_missing(left_brace)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.