Rubocop: Infinite loop on running rubocop -a on some code with HERE doc

Created on 5 Mar 2018  路  6Comments  路  Source: rubocop-hq/rubocop

  1. Create test.rb with content
<<a
#{'a';'b'}
a
  1. Run rubocop -a test.rb

    Actual behavior

Inspecting 1 file
W

Offenses:

test/lib/test/unit/assertions.rb:2:6: C: [Corrected] Layout/SpaceAfterSemicolon: Space missing after semicolon.
#{'b';'c'}
     ^
test/lib/test/unit/assertions.rb:2:6: C: Style/Semicolon: Do not use semicolons to terminate expressions.
#{'b'; 'c'}
     ^
test/lib/test/unit/assertions.rb:2:7: W: [Corrected] Lint/LiteralInInterpolation: Literal interpolation detected.
#{'b';'c'}
      ^^^
test/lib/test/unit/assertions.rb:2:8: C: [Corrected] Layout/SpaceInsideStringInterpolation: Space inside string interpolation detected.
#{'b'; 'c'}
       ^^^
test/lib/test/unit/assertions.rb:2:8: W: [Corrected] Lint/LiteralInInterpolation: Literal interpolation detected.
#{'b'; 'c'}
       ^^^

0 files inspected, 5 offenses detected, 4 offenses corrected
Infinite loop detected in test.rb

This is simplified version of code from https://github.com/ruby/csv.git, running rubocop -a cause this Infinite loop on test/lib/test/unit/assertions.rb file in this project.
I've already tryed to run rubocop -a in ruby\csv and got another problem- https://github.com/bbatsov/rubocop/issues/5586, but it seems fixed

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.53.0 (using Parser 2.5.0.2, running on ruby 2.5.0 x86_64-linux)
bug

Most helpful comment

I have a fix for Layout/SpaceInsideStringInterpolation that I am going to turn into a PR soon.

All 6 comments

My guess is that it鈥檚 a conflict between Layout/SpaceInsideStringInterpolation and Layout/SpaceAfterSemicolon. The first wants to remove whitespaces inside the #{} interpolation, and the second one desperately wants to add a space after the semicolon.

I guess rewriting the interpolation as two interpolations would make Rubocop happy (#{'a'}#{'b'}), but that doesn鈥檛 feel like the right solution. Perhaps we should say that semicolons are ok inside string interpolations?

I guess rewriting the interpolation as two interpolations would make Rubocop happy (#{'a'}#{'b'}),

I don't think RuboCop users should rewrite their code so RuboCop would not crash even on pretty bad code :)

I don't think RuboCop users should rewrite their code so RuboCop would not crash even on pretty bad code :)

I couldn鈥檛 agree more. 馃槂

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

Still crashes:

$ rubocop -v
0.68.1
$ rubocop -a t.rb
Inspecting 1 file
W

Offenses:

t.rb:2:6: C: [Corrected] Layout/SpaceAfterSemicolon: Space missing after semicolon.
#{'a';'b'}
     ^
t.rb:2:6: C: Style/Semicolon: Do not use semicolons to terminate expressions.
#{'a'; 'b'}
     ^
t.rb:2:7: W: [Corrected] Lint/LiteralInInterpolation: Literal interpolation detected.
#{'a';'b'}
      ^^^
t.rb:2:8: C: [Corrected] Layout/SpaceInsideStringInterpolation: Space inside string interpolation detected.
#{'a'; 'b'}
       ^^^
t.rb:2:8: W: [Corrected] Lint/LiteralInInterpolation: Literal interpolation detected.
#{'a'; 'b'}
       ^^^

0 files inspected, 5 offenses detected, 4 offenses corrected
Infinite loop detected in /Users/erichodel/t.rb.
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:263:in `check_for_infinite_loop'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:246:in `block in iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:245:in `loop'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:216:in `do_inspection_loop'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:119:in `block in file_offenses'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:137:in `file_offense_cache'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:117:in `file_offenses'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:105:in `process_file'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:81:in `each'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:81:in `reduce'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:81:in `each_inspected_file'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:73:in `inspect_files'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/runner.rb:39:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/cli.rb:210:in `execute_runner'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/cli.rb:80:in `execute_runners'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/lib/rubocop/cli.rb:51:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/exe/rubocop:13:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/2.6.0/gems/rubocop-0.68.1/exe/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'

I have a fix for Layout/SpaceInsideStringInterpolation that I am going to turn into a PR soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirrmann picture kirrmann  路  3Comments

mlammers picture mlammers  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments

printercu picture printercu  路  3Comments

tedPen picture tedPen  路  3Comments