lib/rubocop/cop/rspec/let_before_examples.rb in rubocop-rspec-1.38.1 vs lib/rubocop/cop/rspec/let_before_examples.rb in rubocop-rspec-1.39.0
- old
+ new
@@ -29,13 +29,10 @@
#
# it 'checks what some does' do
# expect(some).to be
# end
class LetBeforeExamples < Cop
- include RangeHelp
- include RuboCop::RSpec::FinalEndLocation
-
MSG = 'Move `let` before the examples in the group.'
def_node_matcher :example_or_group?, <<-PATTERN
{
#{(Examples::ALL + ExampleGroups::ALL).block_pattern}
@@ -50,15 +47,13 @@
end
def autocorrect(node)
lambda do |corrector|
first_example = find_first_example(node.parent)
- first_example_pos = first_example.loc.expression
- indent = "\n" + ' ' * first_example.loc.column
-
- corrector.insert_before(first_example_pos, source(node) + indent)
- corrector.remove(node_range_with_surrounding_space(node))
+ RuboCop::RSpec::Corrector::MoveNode.new(
+ node, corrector, processed_source
+ ).move_before(first_example)
end
end
private
@@ -77,22 +72,9 @@
end
end
def find_first_example(node)
node.children.find { |sibling| example_or_group?(sibling) }
- end
-
- def node_range_with_surrounding_space(node)
- range = node_range(node)
- range_by_whole_lines(range, include_final_newline: true)
- end
-
- def source(node)
- node_range(node).source
- end
-
- def node_range(node)
- node.loc.expression.with(end_pos: final_end_location(node).end_pos)
end
end
end
end
end