Skip to content

Commit

Permalink
Remove pre-RuboCop v1 compatibility code
Browse files Browse the repository at this point in the history
Gemspec now requires >= 1.0, so this is just dead code
  • Loading branch information
Earlopain committed Sep 18, 2024
1 parent 4ec6a7d commit 48ffca8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 163 deletions.
8 changes: 3 additions & 5 deletions lib/erb_lint/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def run_with_corrections(runner, filename, file_content)
runner.run(processed_source)
break unless autocorrect? && runner.offenses.any?

corrector = correct(processed_source, runner.offenses)
corrector = corrector(processed_source, runner.offenses)
break if corrector.corrections.empty?
break if processed_source.file_content == corrector.corrected_content

Expand Down Expand Up @@ -202,10 +202,8 @@ def read_content(filename)
$stdin.binmode.read.force_encoding(Encoding::UTF_8)
end

def correct(processed_source, offenses)
corrector = ERBLint::Corrector.new(processed_source, offenses)
failure!(corrector.diagnostics.join(", ")) if corrector.diagnostics.any?
corrector
def corrector(processed_source, offenses)
ERBLint::Corrector.new(processed_source, offenses)
end

def config_filename
Expand Down
19 changes: 3 additions & 16 deletions lib/erb_lint/corrector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "rubocop/cop/legacy/corrector"

module ERBLint
class Corrector
attr_reader :processed_source, :offenses, :corrected_content
Expand All @@ -17,22 +19,7 @@ def corrections
end

def corrector
BASE.new(@processed_source.source_buffer, corrections)
end

if ::RuboCop::Version::STRING.to_f >= 0.87
require "rubocop/cop/legacy/corrector"
BASE = ::RuboCop::Cop::Legacy::Corrector

def diagnostics
[]
end
else
BASE = ::RuboCop::Cop::Corrector

def diagnostics
corrector.diagnostics
end
::RuboCop::Cop::Legacy::Corrector.new(@processed_source.source_buffer, corrections)
end
end
end
68 changes: 15 additions & 53 deletions lib/erb_lint/linters/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "better_html"
require "tempfile"
require "erb_lint/utils/offset_corrector"

module ERBLint
module Linters
Expand Down Expand Up @@ -36,30 +35,14 @@ def run(processed_source)
end
end

if ::RuboCop::Version::STRING.to_f >= 0.87
def autocorrect(_processed_source, offense)
return unless offense.context
def autocorrect(_processed_source, offense)
return unless offense.context

rubocop_correction = offense.context[:rubocop_correction]
return unless rubocop_correction
rubocop_correction = offense.context[:rubocop_correction]
return unless rubocop_correction

lambda do |corrector|
corrector.import!(rubocop_correction, offset: offense.context[:offset])
end
end
else
def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
passthrough = Utils::OffsetCorrector.new(
processed_source,
corrector,
offense.context[:offset],
offense.context[:bound_range],
)
offense.context[:rubocop_correction].call(passthrough)
end
lambda do |corrector|
corrector.import!(rubocop_correction, offset: offense.context[:offset])
end
end

Expand All @@ -85,39 +68,18 @@ def inspect_content(processed_source, erb_node)
activate_team(processed_source, source, offset, code_node, build_team)
end

if ::RuboCop::Version::STRING.to_f >= 0.87
def activate_team(processed_source, source, offset, code_node, team)
report = team.investigate(source)
report.offenses.each do |rubocop_offense|
next if rubocop_offense.disabled?
def activate_team(processed_source, source, offset, code_node, team)
report = team.investigate(source)
report.offenses.each do |rubocop_offense|
next if rubocop_offense.disabled?

correction = rubocop_offense.corrector if rubocop_offense.corrected?
correction = rubocop_offense.corrector if rubocop_offense.corrected?

offense_range = processed_source
.to_source_range(rubocop_offense.location)
.offset(offset)
offense_range = processed_source
.to_source_range(rubocop_offense.location)
.offset(offset)

add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
end
end
else
def activate_team(processed_source, source, offset, code_node, team)
team.inspect_file(source)
team.cops.each do |cop|
correction_offset = 0
cop.offenses.reject(&:disabled?).each do |rubocop_offense|
if rubocop_offense.corrected?
correction = cop.corrections[correction_offset]
correction_offset += 1
end

offense_range = processed_source
.to_source_range(rubocop_offense.location)
.offset(offset)

add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
end
end
add_offense(rubocop_offense, offense_range, correction, offset, code_node.loc.range)
end
end

Expand Down
69 changes: 0 additions & 69 deletions lib/erb_lint/utils/offset_corrector.rb

This file was deleted.

20 changes: 0 additions & 20 deletions spec/lib/erb_lint/utils/offset_corrector_spec.rb

This file was deleted.

0 comments on commit 48ffca8

Please sign in to comment.