Class: RuboCop::Cop::Standard::SemanticBlocks

Inherits:
Cop
  • Object
show all
Includes:
IgnoredMethods
Defined in:
lib/standard/cop/semantic_blocks.rb

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/standard/cop/semantic_blocks.rb', line 26

def autocorrect(node)
  return if correction_would_break_code?(node)

  if node.single_line?
    replace_do_end_with_braces(node.loc)
  elsif node.braces?
    replace_braces_with_do_end(node.loc)
  else
    replace_do_end_with_braces(node.loc)
  end
end

#on_block(node) ⇒ Object



20
21
22
23
24
# File 'lib/standard/cop/semantic_blocks.rb', line 20

def on_block(node)
  return if ignored_node?(node) || proper_block_style?(node)

  add_offense(node, location: :begin)
end

#on_send(node) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/standard/cop/semantic_blocks.rb', line 6

def on_send(node)
  return unless node.arguments?
  return if node.parenthesized? || node.operator_method?

  node.arguments.each do |arg|
    get_blocks(arg) do |block|
      # If there are no parentheses around the arguments, then braces
      # and do-end have different meaning due to how they bind, so we
      # allow either.
      ignore_node(block)
    end
  end
end