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 2.5 assigned block rescue alignment #6437

Merged
merged 2 commits into from
Dec 4, 2018

Conversation

gmcgibbon
Copy link
Contributor

Fixes #6433.

Currently, Layout/RescueEnsureAlignment rejects blocks with rescues that are assigned to a variable. In Ruby 2.5, this is valid:

result = [1, 2, 3].map do |el|
  el.to_s
rescue StandardError => _exception
  next
end

Before submitting the PR make sure the following are checked:

  • 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.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run rake default. It executes all tests and RuboCop for itself, and generates the documentation.

Copy link
Contributor

@Edouard-chin Edouard-chin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, you need to add a link to your GH handle name at the end of the CHANGELOG.md file to make the test pass.

There is also an edge case that I think isn't covered by this patch but TBH I'm not even sure what would be the right syntax

if a = something do
  test
rescue => e
  puts 'hello'
end; end

@gmcgibbon gmcgibbon force-pushed the ruby_25_rescue_align branch 2 times, most recently from 5ae32a1 to 52bcd2d Compare November 14, 2018 16:36
Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙇

Fix Ruby 2.5 Layout/RescueEnsureAlignment error on assigned blocks.
@bbatsov bbatsov merged commit 9477ef9 into rubocop:master Dec 4, 2018
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 4, 2018

Thanks!

@gmcgibbon gmcgibbon deleted the ruby_25_rescue_align branch December 4, 2018 00:38
Drenmi added a commit to Drenmi/rubocop that referenced this pull request Dec 6, 2018
… on assigned begin-end

We were missing some test cases for this cop, and accidentally introduced a
regression in rubocop#6437.

This change adds a relevant test case and fixes the issue.
bbatsov pushed a commit that referenced this pull request Dec 6, 2018
…igned begin-end

We were missing some test cases for this cop, and accidentally introduced a
regression in #6437.

This change adds a relevant test case and fixes the issue.
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.

None yet

4 participants