Skip to content

Commit

Permalink
Fix two bugs in #expect_correction
Browse files Browse the repository at this point in the history
- When an attempt at correcting does not correct anything, just end the
  loop.
- Reset the memoized `@token_table` on each iteration. It would be
  cleaner to use a new `cop` instance on each iteration, but I am not
  sure how to fix that.
  • Loading branch information
bquorning authored and bbatsov committed Jun 5, 2020
1 parent 1f65829 commit f6286b9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rubocop/rspec/expect_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@ def expect_correction(correction, loop: false)

break corrected_source unless loop
break corrected_source if cop.corrections.empty?
break corrected_source if corrected_source == @processed_source.buffer.source

if iteration > RuboCop::Runner::MAX_ITERATIONS
raise RuboCop::Runner::InfiniteCorrectionLoop.new(@processed_source.path, [])
end

# Prepare for next loop
cop.instance_variable_set(:@corrections, [])
# Cache invalidation. This is bad!
cop.instance_variable_set(:@token_table, nil)
@processed_source = parse_source(corrected_source,
@processed_source.path)
_investigate(cop, @processed_source)
Expand Down

0 comments on commit f6286b9

Please sign in to comment.