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 Style/IfUnlessModifier #7957

Closed
matt-thomson opened this issue May 12, 2020 · 1 comment · Fixed by #8449
Closed

Infinite loop in Style/IfUnlessModifier #7957

matt-thomson opened this issue May 12, 2020 · 1 comment · Fixed by #8449
Labels

Comments

@matt-thomson
Copy link

We're seeing an issue with the Style/IfUnlessModifier cop getting in an infinite loop on a long line (seemingly switching between the single-line and multi-line versions).

This started happening on v0.83.0; no violations were reported on v0.82.0.

.rubocop.yml

Layout/LineLength:
  Max: 90

example.rb

# frozen_string_literal: true

<<~FOO.strip
  #{'Lorem ipsum dolor sit amet, consectetur adipiscing elit vivamus mollis.' if count > 1}
FOO

Expected behavior

To terminate without an infinite loop.

Actual behavior

Rubocop exits with code 2, and the following output:

$ bundle exec rubocop -a
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
 - Layout/EmptyLinesAroundAttributeAccessor (0.83)
 - Layout/SpaceAroundMethodCallOperator (0.82)
 - Lint/RaiseException (0.81)
 - Lint/StructNewOverride (0.81)
 - Style/ExponentialNotation (0.82)
 - Style/HashEachMethods (0.80)
 - Style/HashTransformKeys (0.80)
 - Style/HashTransformValues (0.80)
 - Style/SlicingWithRange (0.83)
For more information: https://docs.rubocop.org/en/latest/versioning/
Inspecting 2 files
.C

Offenses:

example.rb:4:5: C: [Corrected] Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
  #{if count > 1
    ^^
example.rb:4:79: C: [Corrected] Style/IfUnlessModifier: Modifier form of if makes the line too long.
  #{'Lorem ipsum dolor sit amet, consectetur adipiscing elit vivamus mollis.' if count > 1}
                                                                              ^^

1 file inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /private/tmp/rubocop/example.rb.
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:292:in `check_for_infinite_loop'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:275:in `block in iterate_until_no_changes'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `loop'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `iterate_until_no_changes'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:245:in `do_inspection_loop'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:148:in `file_offense_cache'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:122:in `file_offenses'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:113:in `process_file'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:92:in `block in each_inspected_file'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `reduce'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each_inspected_file'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:78:in `inspect_files'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:39:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command.rb:10:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/environment.rb:17:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:41:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/exe/rubocop:13:in `block in <top (required)>'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/exe/rubocop:12:in `<top (required)>'
/Users/mthomson/.rbenv/versions/2.6.6/bin/rubocop:23:in `load'
/Users/mthomson/.rbenv/versions/2.6.6/bin/rubocop:23:in `<top (required)>'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/Users/mthomson/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/Users/mthomson/.rbenv/versions/2.6.6/bin/bundle:23:in `load'
/Users/mthomson/.rbenv/versions/2.6.6/bin/bundle:23:in `<main>'

Steps to reproduce the problem

Set up files as in description above, and run bundle exec rubocop -a.

RuboCop version

$ bundle exec rubocop -V
0.83.0 (using Parser 2.7.1.2, running on ruby 2.6.6 x86_64-darwin18)
@jonas054 jonas054 added the bug label May 13, 2020
@bquorning
Copy link
Contributor

This started happening on v0.83.0; no violations were reported on v0.82.0.

It definitely happens on v0.82.0 too.

I did a git bisect which says the behavior was introduced by commit e524404 from pull request #7507.

dmytro-savochkin pushed a commit to dmytro-savochkin/rubocop that referenced this issue Aug 4, 2020
…code after end keyword makes it too long
bbatsov pushed a commit that referenced this issue Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants