Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in HeredocIndentation auto-correction #8108

Closed
jonas054 opened this issue Jun 7, 2020 · 0 comments
Closed

Infinite loop in HeredocIndentation auto-correction #8108

jonas054 opened this issue Jun 7, 2020 · 0 comments
Labels

Comments

@jonas054
Copy link
Collaborator

jonas054 commented Jun 7, 2020

Auto-correcting a file containing a heredoc with incorrect indentation, that has a line within consisting only of spaces, leads to an infinite loop.

# frozen_string_literal: true

def m
  <<~RUBY
        a
  
      the_line_above_has_2_spaces
  RUBY
end

Expected behavior

$ rubocop -a
Inspecting 1 file
C

Offenses:

file.rb:5:1: C: [Corrected] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc.
        a ...
^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected

Actual behavior

$ rubocop -a
Inspecting 1 file
C

Offenses:

file.rb:5:1: C: [Corrected] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc.
        a ...
^^^^^^^^^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in /home/jonas/dev/8108/file.rb.
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:276:in `block in iterate_until_no_changes'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:272:in `loop'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:272:in `iterate_until_no_changes'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:243:in `do_inspection_loop'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:122:in `block in file_offenses'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:146:in `file_offense_cache'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:120:in `file_offenses'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:111:in `process_file'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:90:in `block in each_inspected_file'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:89:in `each'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:89:in `reduce'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:89:in `each_inspected_file'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:78:in `inspect_files'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/runner.rb:39:in `run'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli/command.rb:10:in `run'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli/environment.rb:17:in `run'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/lib/rubocop/cli.rb:41:in `run'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/exe/rubocop:13:in `block in <top (required)>'
/usr/local/rvm/rubies/ruby-2.6.5/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/usr/local/rvm/gems/ruby-2.6.5/gems/rubocop-0.85.0/exe/rubocop:12:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.6.5/bin/rubocop:23:in `load'
/usr/local/rvm/gems/ruby-2.6.5/bin/rubocop:23:in `<main>'
/usr/local/rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
/usr/local/rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'

Steps to reproduce the problem

Run rubocop -a on the example file above.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ rubocop -V
0.85.0 (using Parser 2.7.1.3, rubocop-ast 0.0.3, running on ruby 2.6.5 x86_64-linux)
@bbatsov bbatsov added the bug label Jun 7, 2020
@koic koic closed this as completed in 32de264 Jun 7, 2020
koic added a commit that referenced this issue Jun 7, 2020
…ite_loop

[Fix #8108] Disregard whitespace lines in HeredocIndentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants