class RubbyCop::Cop::Lint::DefEndAlignment
This cop checks whether the end keywords of method definitions are aligned properly.
Two modes are supported through the EnforcedStyleAlignWith configuration parameter. If it's set to `start_of_line` (which is the default), the `end` shall be aligned with the start of the line where the `def` keyword is. If it's set to `def`, the `end` shall be aligned with the `def` keyword.
@example
# bad private def foo end
@example
# EnforcedStyleAlignWith: start_of_line (default) # good private def foo end
@example
# EnforcedStyleAlignWith: def # good private def foo end
Constants
- MSG
Public Instance Methods
on_method_def(node, _method_name, _args, _body)
click to toggle source
# File lib/rubbycop/cop/lint/def_end_alignment.rb, line 45 def on_method_def(node, _method_name, _args, _body) check_end_kw_in_node(node) end
on_send(node)
click to toggle source
# File lib/rubbycop/cop/lint/def_end_alignment.rb, line 49 def on_send(node) return unless modifier_and_def_on_same_line?(node) method_def = node.first_argument expr = node.source_range line_start = range_between(expr.begin_pos, method_def.loc.keyword.end_pos) align_with = { def: method_def.loc.keyword, start_of_line: line_start } check_end_kw_alignment(method_def, align_with) ignore_node(method_def) # Don't check the same `end` again. end
Private Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubbycop/cop/lint/def_end_alignment.rb, line 68 def autocorrect(node) if style == :start_of_line && node.parent && node.parent.send_type? align(node, node.parent) else align(node, node) end end