From 733c51d6ec11c009d919e61bbcfbc1579a0c17b3 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 20 Sep 2024 11:57:23 +0200 Subject: [PATCH] Don't use deprecated corrector apis Closes #368 This is pretty much just a compatibility layer in itself. Cops here are still declared with the old style (`autocorrect` instance method for example) but rewriting that all is not trivial and also works just fine --- lib/erb_lint/corrector.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/erb_lint/corrector.rb b/lib/erb_lint/corrector.rb index 804d03e..4488cd3 100644 --- a/lib/erb_lint/corrector.rb +++ b/lib/erb_lint/corrector.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "rubocop/cop/legacy/corrector" - module ERBLint class Corrector attr_reader :processed_source, :offenses, :corrected_content @@ -9,6 +7,8 @@ class Corrector def initialize(processed_source, offenses) @processed_source = processed_source @offenses = offenses + corrector = RuboCop::Cop::Corrector.new(@processed_source.source_buffer) + correct!(corrector) @corrected_content = corrector.rewrite end @@ -18,8 +18,10 @@ def corrections end.compact end - def corrector - ::RuboCop::Cop::Legacy::Corrector.new(@processed_source.source_buffer, corrections) + def correct!(corrector) + corrections.each do |correction| + correction.call(corrector) + end end end end