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
Layout/RescueEnsureAlignment issue with nested begin #6603
Comments
I believe this cop is working as intended. Here are some options you have: # A
v ||= begin
1
rescue
2
end
# B
def one_two
1
rescue
2
end
v ||= one_two
# C
v ||=
begin
1
rescue
2
end I prefer B, personally. Hope that helps! |
Tests improved by #6606 |
Hm... so the following code while being contrived and generally not good is perfectly fine with rubocop case something
when something_else
whatever = case nested
when no_matter
ret
end
end the nested why is rescue different then? |
@dreyks Likely an oversight. Generally some alignment cops have configurable styles to allow one of the two common styles of alignment, but this is not one of them (yet). I guess someone can tackle this down the road. |
ok cool. I might look into it if I have some spare time |
Add a test to demonstrate the correct styles of a begin-rescue as the RHS of an assignment.
Here after upgrading from 0.58 to 0.61, as this cop triggered many new failures for previously allowed syntax:
Since this was previously valid, and since a similar format is allowed for Ruby 2.5 do/rescue blocks (per #6437), I'll also put in a vote for either loosening or parameterizing this. |
Also, FWIW, I'm guessing you can close this in favor of #6254, which seems like one of the more popular threads for this issue/request. |
Looks similar to #6433
Expected behavior
No error emitted
Actual behavior
Cop expects
rescue
to be aligned withbegin
Steps to reproduce the problem
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:The text was updated successfully, but these errors were encountered: