class RuboCop::Cop::Minitest::LifecycleHooksOrder


end
def teardown; end
def setup; end
def do_something; end
class FooTest < Minitest::Test
# good (after non test case methods)
end
end
assert foo
def test_something
def teardown; end
def setup; end
class FooTest < Minitest::Test
# good
end
def teardown; end
def setup; end
end
assert foo
def test_something
class FooTest < Minitest::Test
# bad (after test cases)
end
def teardown; end
def setup; end
class FooTest < Minitest::Test
# good
end
def setup; end
def teardown; end
class FooTest < Minitest::Test
# bad
@example
Checks that lifecycle hooks are declared in the order in which they will be executed.

def autocorrect(corrector, previous_node, node)

def autocorrect(corrector, previous_node, node)
  previous_node_range = range_with_comments_and_lines(previous_node)
  node_range = range_with_comments_and_lines(node)
  corrector.insert_before(previous_node_range, node_range.source)
  corrector.remove(node_range)
end

def hooks_and_test_cases(class_node)

def hooks_and_test_cases(class_node)
  class_def_nodes(class_node).select do |node|
    lifecycle_hook_method?(node) || test_case?(node)
  end
end

def on_class(class_node)

rubocop:disable Metrics/MethodLength
def on_class(class_node)
  return unless test_class?(class_node)
  previous_index = -1
  previous_hook_node = nil
  hooks_and_test_cases(class_node).each do |node|
    hook = node.method_name
    index = HOOKS_ORDER_MAP[hook]
    if index < previous_index
      message = format(MSG, current: hook, previous: previous_hook_node.method_name)
      add_offense(node, message: message) do |corrector|
        autocorrect(corrector, previous_hook_node, node)
      end
    end
    previous_index = index
    previous_hook_node = node
  end
end