Skip to content

Commit

Permalink
Merge pull request rubocop#13379 from Earlopain/ruby-3.4-stringio
Browse files Browse the repository at this point in the history
Fix an error when running with Ruby 3.4-dev
  • Loading branch information
koic authored Oct 23, 2024
2 parents 7b6fdc6 + 5c04cff commit 7516094
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

require 'regexp_parser'
require 'set'
require 'stringio'
require 'unicode/display_width'

# we have to require RuboCop's version, before rubocop-ast's
Expand Down
13 changes: 1 addition & 12 deletions lib/rubocop/cop/correctors/alignment_corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def autocorrect_line(corrector, line_begin_pos, expr, column_delta,
if column_delta.positive? && range.resize(1).source != "\n"
corrector.insert_before(range, ' ' * column_delta)
elsif /\A[ \t]+\z/.match?(range.source)
remove(range, corrector)
corrector.remove(range)
end
end

Expand Down Expand Up @@ -96,17 +96,6 @@ def calculate_range(expr, line_begin_pos, column_delta)
end
end

def remove(range, corrector)
original_stderr = $stderr
$stderr = StringIO.new # Avoid error messages on console
corrector.remove(range)
rescue RuntimeError
range = range_between(range.begin_pos + 1, range.end_pos + 1)
retry if /^ +$/.match?(range.source)
ensure
$stderr = original_stderr
end

def each_line(expr)
line_begin_pos = expr.begin_pos
expr.source.each_line do |line|
Expand Down

0 comments on commit 7516094

Please sign in to comment.