Class: Rubocop::Cop::Lint::EndAlignment

Inherits:
Cop
  • Object
show all
Includes:
CheckAssignment, CheckMethods
Defined in:
lib/rubocop/cop/lint/end_alignment.rb

Overview

This cop checks whether the end keywords are aligned properly.

Two modes are supported through the AlignWith configuration parameter. If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, def, etc.). If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

Examples:


variable = if true
           end

Constant Summary collapse

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

Constants inherited from Cop

Cop::OPERATOR_METHODS

Constants included from Util

Util::PROC_NEW_NODE

Instance Attribute Summary

Attributes inherited from Cop

#config, #corrections, #offences, #processed_source

Instance Method Summary collapse

Methods included from CheckAssignment

#on_and_asgn, #on_casgn, #on_gvasgn, #on_ivasgn, #on_lvasgn, #on_op_asgn, #on_or_asgn

Methods included from CheckMethods

#on_def, #on_defs

Methods inherited from Cop

#add_offence, all, #autocorrect?, #config_to_allow_offences, #config_to_allow_offences=, #cop_config, cop_name, #cop_name, cop_type, #debug?, #exclude_file?, #exclude_paths, #ignore_node, #include_file?, #include_paths, inherited, #initialize, lint?, #message, non_rails, rails?, #relevant_file?, style?, #support_autocorrect?

Methods included from Util

block_length, command?, comment_line?, const_name, first_part_of_call_chain, lambda?, lambda_or_proc?, line_range, on_node, proc?, range_with_surrounding_space, source_range, strip_quotes

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_class(node) ⇒ Object



24
25
26
# File 'lib/rubocop/cop/lint/end_alignment.rb', line 24

def on_class(node)
  check(node)
end

#on_if(node) ⇒ Object



32
33
34
# File 'lib/rubocop/cop/lint/end_alignment.rb', line 32

def on_if(node)
  check(node) if node.loc.respond_to?(:end)
end

#on_module(node) ⇒ Object



28
29
30
# File 'lib/rubocop/cop/lint/end_alignment.rb', line 28

def on_module(node)
  check(node)
end

#on_until(node) ⇒ Object



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

def on_until(node)
  check(node)
end

#on_while(node) ⇒ Object



36
37
38
# File 'lib/rubocop/cop/lint/end_alignment.rb', line 36

def on_while(node)
  check(node)
end