KEMBAR78
[Fix #14453] Update `Style/RedundantBegin` to register `begin` blocks inside `if`, `unless`, `case`, `while` and `until` as redundant by dvandersluis · Pull Request #14463 · rubocop/rubocop · GitHub
Skip to content

Conversation

@dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Aug 18, 2025

A begin block (without rescue or ensure) inside if, case, while or until is redundant, and can be handled by the cop.

Fixes #14453.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@vlad-pisanov
Copy link
Contributor

nice! another similar case that comes to mind is

while cond?
  begin
    foo
    bar
  end
end

@dvandersluis
Copy link
Member Author

Thanks @vlad-pisanov I added support for while and until as well.

@dvandersluis dvandersluis changed the title [Fix #14453] Update Style/RedundantBegin to register begin blocks inside if, unless and case as redundant [Fix #14453] Update Style/RedundantBegin to register begin blocks inside if, unless, case, when and until as redundant Aug 19, 2025
@dvandersluis dvandersluis changed the title [Fix #14453] Update Style/RedundantBegin to register begin blocks inside if, unless, case, when and until as redundant [Fix #14453] Update Style/RedundantBegin to register begin blocks inside if, unless, case, while and until as redundant Aug 19, 2025
… blocks inside `if`, `unless`, `case`, `while` and `until` as redundant
@bbatsov bbatsov merged commit a08b607 into rubocop:master Aug 19, 2025
22 checks passed
@dvandersluis dvandersluis deleted the issue/14453 branch August 19, 2025 15:51
koic added a commit to koic/rubocop that referenced this pull request Aug 22, 2025
Follow-up to rubocop#14463.

This PR makes `Style/RedundantBegin` aware of `case` pattern matching.
bbatsov pushed a commit that referenced this pull request Aug 22, 2025
Follow-up to #14463.

This PR makes `Style/RedundantBegin` aware of `case` pattern matching.
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.

Style/RendundantBegin could eliminate multiline begin blocks in branches

3 participants