class RuboCop::Cop::Style::TrailingMethodEndStatement

Checks for trailing code after the method definition.

@example

# bad
def some_method
do_stuff; end

def do_this(x)
  baz.map { |b| b.this(x) } end

def foo
  block do
    bar
  end end

# good
def some_method
  do_stuff
end

def do_this(x)
  baz.map { |b| b.this(x) }
end

def foo
  block do
    bar
  end
end

Constants

MSG

Public Instance Methods

on_def(node) click to toggle source
# File lib/rubocop/cop/style/trailing_method_end_statement.rb, line 41
def on_def(node)
  return if node.endless? || !trailing_end?(node)

  add_offense(node.loc.end) do |corrector|
    corrector.insert_before(node.loc.end, "\n#{' ' * node.loc.keyword.column}")
  end
end

Private Instance Methods

body_and_end_on_same_line?(node) click to toggle source
# File lib/rubocop/cop/style/trailing_method_end_statement.rb, line 55
def body_and_end_on_same_line?(node)
  last_child = node.children.last
  last_child.loc.last_line == node.loc.end.last_line
end
trailing_end?(node) click to toggle source
# File lib/rubocop/cop/style/trailing_method_end_statement.rb, line 51
def trailing_end?(node)
  node.body && node.multiline? && body_and_end_on_same_line?(node)
end