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

[Fix #8179] Fix an infinite correction loop for Layout/MultilineBlockLayout #8180

Conversation

koic
Copy link
Member

@koic koic commented Jun 21, 2020

Fixes #8179.

This PR fixes an infinite correction loop error for Layout/MultilineBlockLayout when missing newline before opening parenthesis ( for block body.

# frozen_string_literal: true

foo do |o| (
    bar
  )
end
% rubocop -a --only Layout/MultilineBlockLayout
Inspecting 1 file
C

Offenses:

example.rb:3:12: C: [Corrected] Layout/MultilineBlockLayout: Block body
expression is on the same line as the block start.
foo do |o| ( ...
           ^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/8179/example.rb.
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:276:in
`block in iterate_until_no_changes'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:272:in
`loop'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:272:in
`iterate_until_no_changes'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:243:in
`do_inspection_loop'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:122:in
`block in file_offenses'

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

…ineBlockLayout`

Fixes rubocop#8179.

This PR fixes an infinite correction loop error for `Layout/MultilineBlockLayout`
when missing newline before opening parenthesis `(` for block body.

```ruby
# frozen_string_literal: true

foo do |o| (
    bar
  )
end
```

```console
% rubocop -a --only Layout/MultilineBlockLayout
Inspecting 1 file
C

Offenses:

example.rb:3:12: C: [Corrected] Layout/MultilineBlockLayout: Block body
expression is on the same line as the block start.
foo do |o| ( ...
           ^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in /Users/koic/src/github.com/koic/rubocop-issues/8179/example.rb.
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:276:in
`block in iterate_until_no_changes'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:272:in
`loop'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:272:in
`iterate_until_no_changes'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:243:in
`do_inspection_loop'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/runner.rb:122:in
`block in file_offenses'
```
@koic koic force-pushed the fix_incorrect_autocorrect_for_multiline_block_layout branch from 4bb0878 to 0248db9 Compare June 21, 2020 06:59
@bbatsov bbatsov merged commit 42a03c3 into rubocop:master Jun 21, 2020
@tas50
Copy link
Contributor

tas50 commented Jun 21, 2020

Thanks for the super fast fix @koic

@koic koic deleted the fix_incorrect_autocorrect_for_multiline_block_layout branch June 22, 2020 01:09
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

Successfully merging this pull request may close these issues.

Scary code block autocorrect each time
3 participants