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

Scary code block autocorrect each time #8179

Closed
tas50 opened this issue Jun 21, 2020 · 0 comments · Fixed by #8180
Closed

Scary code block autocorrect each time #8179

tas50 opened this issue Jun 21, 2020 · 0 comments · Fixed by #8180
Labels

Comments

@tas50
Copy link
Contributor

tas50 commented Jun 21, 2020

Expected behavior

Code should either autocorrect or not.

Actual behavior

Code is marked as corrected, but not actually changed.

Steps to reproduce the problem

This scary block autocorrect each run of RuboCop.

agent = ossec_agents.find do |n| (

          
          n[:ossec][:agents].key?(agent_id) \
                          && n[:ossec][:agent][:enable])
end
/Users/tsmith/Desktop/test.rb:3:1: W: Lint/UselessAssignment: Useless assignment to variable - agent.
agent = ossec_agents.find do |n| (
^^^^^
/Users/tsmith/Desktop/test.rb:3:34: C: [Corrected] Layout/MultilineBlockLayout: Block body expression is on the same line as the block start.
agent = ossec_agents.find do |n| ( ...
                                 ^
/Users/tsmith/Desktop/test.rb:4:1: C: [Corrected] Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
/Users/tsmith/Desktop/test.rb:5:1: C: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.

RuboCop version

Master

@koic koic added the bug label Jun 21, 2020
koic added a commit to koic/rubocop that referenced this issue Jun 21, 2020
…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'
```
bbatsov pushed a commit that referenced this issue Jun 21, 2020
…kLayout`

Fixes #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'
```
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.

2 participants