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 incorrect auto-correct for Style/RedundantBegin #9777

Commits on May 7, 2021

  1. Fix an incorrect auto-correct for Style/RedundantBegin

    This PR fixes an incorrect auto-correct for `Style/RedundantBegin`
    when using multi-line `if` in `begin` block.
    
    And fixes standardrb/standard#289 that is causing
    the following infinite loop error due to `Style/RedundantBegin` with
    `Style/MultilineMemoization`.
    
    ```ruby
    % cat example.rb
    @memo ||= begin
      if condition
        do_something
      end
    end
    
    % bundle exec rubocop -a --only Style/RedundantBegin,Style/MultilineMemoization
    (snip)
    
    Inspecting 1 file
    C
    
    Offenses:
    
    example.rb:1:1: C: [Corrected] Style/MultilineMemoization: Wrap
    multiline memoization blocks in begin and end.
    @memo ||= (if condition ...
    ^^^^^^^^^^^^^^^^^^^^^^^
    example.rb:1:11: C: [Corrected] Style/RedundantBegin: Redundant begin
    block detected.
    @memo ||= begin
              ^^^^^
    
    0 files inspected, 2 offenses detected, 2 offenses corrected
    Infinite loop detected in
    /Users/koic/src/github.com/koic/rubocop-issues/289/example.rb and caused
    by Style/MultilineMemoization
    /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:285:in
    `block in iterate_until_no_changes'
    /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in
    `loop'
    /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
    ```
    koic committed May 7, 2021
    Copy the full SHA
    b20bf22 View commit details
    Browse the repository at this point in the history