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 from TrailingWhitespace + EmptyInterpolation #8944

Closed
bpo opened this issue Oct 26, 2020 · 2 comments
Closed

Infinite loop from TrailingWhitespace + EmptyInterpolation #8944

bpo opened this issue Oct 26, 2020 · 2 comments

Comments

@bpo
Copy link

bpo commented Oct 26, 2020

Using autocorrect (rubocop -a) with Layout/TrailingWhitespace and Lint/EmptyInterpolation causes infinite loops when encountering empty lines containing only indentation within heredocs.


Expected behavior

No infinite loop.

Actual behavior

 rubocop -a --debug
For ~/Code/linebreak_heredoc: Default configuration from ~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/config/default.yml
Inspecting 1 file
Scanning ~/Code/linebreak_heredoc/test.rb
W

Offenses:

test.rb:8:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
test.rb:8:5: W: [Corrected] Lint/EmptyInterpolation: Empty interpolation detected.
    #{}
    ^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in ~/Code/linebreak_heredoc/test.rb and caused by Layout/TrailingWhitespace -> Lint/EmptyInterpolation
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:304:in `check_for_infinite_loop'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:287:in `block in iterate_until_no_changes'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:286:in `loop'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:131:in `file_offenses'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:122:in `process_file'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:100:in `each'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:100:in `reduce'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:86:in `inspect_files'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/runner.rb:47:in `run'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli/command.rb:11:in `run'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli/environment.rb:18:in `run'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli.rb:65:in `run_command'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli.rb:72:in `execute_runners'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/lib/rubocop/cli.rb:41:in `run'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/exe/rubocop:13:in `block in <top (required)>'
~/.rbenv/versions/2.7.0/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
~/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rubocop-1.0.0/exe/rubocop:12:in `<top (required)>'
~/.rbenv/versions/2.7.0/bin/rubocop:23:in `load'
~/.rbenv/versions/2.7.0/bin/rubocop:23:in `<main>'
Finished in 0.1126139999832958 seconds

Steps to reproduce the problem

This is test.rb from the above output – note that the first empty line contains 4 spaces.

#! /usr/bin/env ruby -w

# frozen_string_literal: true

def testcase
  puts <<-TXT
    empty breaking lines
    
    looping infinitely on

    each rubocop run
  TXT
end

testcase

RuboCop version

$ rubocop -V
1.0.0 (using Parser 2.7.2.0, rubocop-ast 1.0.1, running on ruby 2.7.0 x86_64-darwin19)
@marcandre
Copy link
Contributor

Sorry about this. This has been fixed with #8914, expect a release in the next few days.

Until the next bugfix release, you can either fix them manually, or set your config with:

Layout/TrailingWhitespace:
  AllowInHeredoc: true

To fix them manually, either remove the trailing whitespaces, or replace them with #{' '}

@bpo
Copy link
Author

bpo commented Nov 3, 2020

Still fails for me in 1.1.0, with the slightly modified error:

Infinite loop detected in /linebreak_heredoc/test.rb and caused by Layout/HeredocIndentation, Layout/TrailingWhitespace, Lint/LiteralInInterpolation

edited to add: looks like #8975 is already tracking the new error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants