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 an infinite loop error for Layout/SpaceInsideBlockBraces #7203

Commits on Jul 13, 2019

  1. Fix an infinite loop error for Layout/SpaceInsideBlockBraces

    This PR fixes an infinite loop error for `Layout/SpaceInsideBlockBraces`
    when`EnforcedStyle: no_space` with `SpaceBeforeBlockParameters: false`
    are set in multiline block.
    
    ```yaml
    # .rubocop.yml
    AllCops:
      DisabledByDefault: true
    
    Layout/SpaceInsideBlockBraces:
      Enabled: true
      EnforcedStyle: no_space
      SpaceBeforeBlockParameters: false
    ```
    
    ```ruby
    # example.rb
    items.map {|item|
      item.do_something
    }
    ```
    
    ```console
    % rubocop -a --only Layout/SpaceInsideBlockBraces
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:2:20: C: [Corrected] Layout/SpaceInsideBlockBraces: Space
    inside } detected.
      item.do_something ...
    
    0 files inspected, 1 offense detected, 1 offense corrected
    Infinite loop detected in /private/tmp/foo/example.rb.
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:268:in `check_for_infinite_loop'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:251:in `block in iterate_until_no_changes'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:250:in `loop'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:250:in `iterate_until_no_changes'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:221:in `do_inspection_loop'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:142:in `file_offense_cache'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:122:in `file_offenses'
    /Users/koic/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.72.0/lib/rubocop/runner.rb:110:in `process_file'
    
    (snip)
    ```
    
    Furthermore, it is changed by auto-correction to the following
    unnatural code.
    
    ```diff
    diff --git a/example.rb b/example.rb
    index f1427be..fb547ee 100644
    --- a/example.rb
    +++ b/example.rb
    @@ -1,3 +1,2 @@
     items.map {|item|
     -  item.do_something
     -}
     +  item.do_something}
    ```
    
    This PR prevents the error by noticing right brace of multiline block.
    koic committed Jul 13, 2019
    Copy the full SHA
    7ae1e4f View commit details
    Browse the repository at this point in the history