diff options
Diffstat (limited to 'rubocop/cop/rspec/timecop_freeze.rb')
-rw-r--r-- | rubocop/cop/rspec/timecop_freeze.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/rubocop/cop/rspec/timecop_freeze.rb b/rubocop/cop/rspec/timecop_freeze.rb index 508b5df7c7f..70e37ecfa55 100644 --- a/rubocop/cop/rspec/timecop_freeze.rb +++ b/rubocop/cop/rspec/timecop_freeze.rb @@ -13,7 +13,9 @@ module RuboCop # # good # freeze_time(Time.current) { example.run } # - class TimecopFreeze < RuboCop::Cop::Cop + class TimecopFreeze < RuboCop::Cop::Base + extend RuboCop::Cop::AutoCorrector + include MatchRange MESSAGE = 'Do not use `Timecop.freeze`, use `freeze_time` instead. ' \ 'See https://gitlab.com/gitlab-org/gitlab/-/issues/214432 for more info.' @@ -25,11 +27,7 @@ module RuboCop def on_send(node) return unless timecop_freeze?(node) - add_offense(node, location: :expression, message: MESSAGE) - end - - def autocorrect(node) - -> (corrector) do + add_offense(node, message: MESSAGE) do |corrector| each_match_range(node.source_range, /^(Timecop\.freeze)/) do |match_range| corrector.replace(match_range, 'freeze_time') end |