Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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' ```
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_an_incorrect_autocorrect_for_style_redundant_begin.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9777](https://github.com/rubocop/rubocop/pull/9777): Fix an incorrect auto-correct for `Style/RedundantBegin` when using multi-line `if` in `begin` block. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters