Class: Rubocop::Cop::Lint::BlockAlignment

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/lint/block_alignment.rb

Overview

This cop checks whether the end keywords are aligned properly for do end blocks.

Examples:


variable = lambda do |i|
  i
end

Constant Summary collapse

MSG =
'end at %d, %d is not aligned with %s at %d, %d'

Instance Attribute Summary

Attributes inherited from Cop

#autocorrect, #corrections, #debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, lint?, #name, rails?, style?

Constructor Details

#initializeBlockAlignment

Returns a new instance of BlockAlignment.



17
18
19
20
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 17

def initialize
  super
  @inspected_blocks = []
end

Instance Method Details

#on_and(node) ⇒ Object Also known as: on_or



27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 27

def on_and(node)
  return if already_processed_node?(node)

  _left, right = *node
  if right.type == :block
    check_block_alignment(node, right)
    @inspected_blocks << right
  end
end

#on_block(node) ⇒ Object



22
23
24
25
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 22

def on_block(node)
  return if already_processed_node?(node)
  check_block_alignment(node, node)
end

#on_casgn(node) ⇒ Object



50
51
52
53
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 50

def on_casgn(node)
  _, _, children = *node
  process_block_assignment(node, children)
end

#on_lvasgn(node) ⇒ Object Also known as: on_ivasgn, on_cvasgn, on_gvasgn, on_and_asgn, on_or_asgn



39
40
41
42
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 39

def on_lvasgn(node)
  _, children = *node
  process_block_assignment(node, children)
end

#on_masgn(node) ⇒ Object



65
66
67
68
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 65

def on_masgn(node)
  variables, args = *node
  process_block_assignment(variables, args)
end

#on_op_asgn(node) ⇒ Object



55
56
57
58
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 55

def on_op_asgn(node)
  variable, _op, args = *node
  process_block_assignment(variable, args)
end

#on_send(node) ⇒ Object



60
61
62
63
# File 'lib/rubocop/cop/lint/block_alignment.rb', line 60

def on_send(node)
  _receiver, _method, *args = *node
  process_block_assignment(node, args.last)
end