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 caused by Layout/MultilineMethodDefinitionBraceLayout and Layout/HeredocArgumentClosingParenthesis interaction #8046

Closed
laurmurclar opened this issue May 27, 2020 · 2 comments · Fixed by #9252
Labels

Comments

@laurmurclar
Copy link
Contributor

I'm occasionally running into an infinite loop error when I have both Layout/MultilineMethodDefinitionBraceLayout and Layout/HeredocArgumentClosingParenthesis enabled. By "occasionally" I mean that it only happens on some files in our codebase, but it happens consistently on those files.


Original code

foo(
  "Some string",
  <<~TEXT,
    Lots of
    Lovely
    Text
  TEXT
  some_arg: { foo: "bar" })

Expected behavior

Code transformed to:

foo(
  "Some string",
  <<~TEXT,
    Lots of
    Lovely
    Text
  TEXT
  some_arg: { foo: "bar" }
)

Actual behavior

An infinite loop error:

bundle exec 'rubocop --safe-auto-correct --disable-uncorrectable example.rb'
Inspecting 1 file
C

Offenses:

example.rb:8:27: C: [Corrected] Layout/HeredocArgumentClosingParenthesis: Put the closing parenthesis for a method call with a HEREDOC parameter on the same line as the HEREDOC opening.
  some_arg: { foo: "bar" })
                          ^
example.rb:8:27: C: [Corrected] Layout/MultilineMethodCallBraceLayout: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.
  some_arg: { foo: "bar" })
                          ^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in /Users/lauramurphy-clarkin/src/intercom/example.rb.
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:278:in `block in iterate_until_no_changes'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `loop'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:274:in `iterate_until_no_changes'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:245:in `do_inspection_loop'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:148:in `file_offense_cache'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:122:in `file_offenses'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:113:in `process_file'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:92:in `block in each_inspected_file'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `reduce'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:91:in `each_inspected_file'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:78:in `inspect_files'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/runner.rb:39:in `run'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/command.rb:10:in `run'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli/environment.rb:17:in `run'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/lib/rubocop/cli.rb:41:in `run'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/exe/rubocop:13:in `block in <top (required)>'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.83.0/exe/rubocop:12:in `<top (required)>'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/bin/rubocop:23:in `load'
/Users/lauramurphy-clarkin/.rbenv/versions/2.6.5/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Run rubocop --safe-auto-correct --disable-uncorrectable example.rb with the Original code snippet in example.rb. Reproducible with the following cop configuration:

AllCops:
  TargetRailsVersion: 6.0
  TargetRubyVersion: 2.6
  DisplayCopNames: true
  DisabledByDefault: true

Layout/HeredocArgumentClosingParenthesis:
  Enabled: true

Layout/MultilineMethodCallBraceLayout:
  Enabled: true

RuboCop version

$ bundle exec rubocop -V
0.83.0 (using Parser 2.7.1.2, running on ruby 2.6.5 x86_64-darwin19)
@koic koic added the bug label May 28, 2020
@denys281
Copy link
Contributor

denys281 commented Jun 20, 2020

MultilineMethodDefinitionBraceLayout autocorrects it to

`foo(`
  "Some string",
  <<~TEXT,
    Lots of
    Lovely
    Text
  TEXT
  some_arg: { foo: "bar" }
)

then HeredocArgumentClosingParenthesis also trying to autocorrect and result is

foo(
  "Some string",
  <<~TEXT,
    Lots of
    Lovely
    Text
  TEXT
  some_arg: { foo: "bar" })

@koic what behavior HeredocArgumentClosingParenthesis should have in current example? Should it give offenses? or should it skip ? Or should we add MultilineMethodDefinitionBraceLayout to autocorrect_incompatible_with method?

@stale
Copy link

stale bot commented Dec 18, 2020

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!

@stale stale bot added the stale Issues that haven't been active in a while label Dec 18, 2020
@koic koic removed the stale Issues that haven't been active in a while label Dec 18, 2020
koic added a commit to koic/rubocop that referenced this issue Dec 23, 2020
…enthesis`

Fixes rubocop#8046.

This PR fixes an error for `Layout/HeredocArgumentClosingParenthesis`
when existing an argument between heredoc of end and closing parentheses.

`Layout/HeredocArgumentClosingParenthesis` alone reproduced an error
without being affected by other cops.
bbatsov pushed a commit that referenced this issue Dec 24, 2020
Fixes #8046.

This PR fixes an error for `Layout/HeredocArgumentClosingParenthesis`
when existing an argument between heredoc of end and closing parentheses.

`Layout/HeredocArgumentClosingParenthesis` alone reproduced an error
without being affected by other cops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants