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
Enforce Style/RedundantBegin for new modules #15192
Enforce Style/RedundantBegin for new modules #15192
Conversation
@@ -359,8 +359,7 @@ Layout/EmptyLinesAroundClassBody: | |||
Description: 'these are used to increase readability' | |||
|
|||
Layout/EmptyLinesAroundMethodBody: | |||
Enabled: false | |||
Description: 'these are used to increase readability' | |||
Enabled: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, the following code:
def cleanup
begin
disconnect
rescue StandardError
nil
end
end
Is automatically fixed to:
def cleanup
disconnect
rescue StandardError
nil
end
It's also not a bad rule to enable either
Will pick this up tomorrow however if anyone wants to go ahead and review/land this before me, feel free to unassign me and land this so long if that would be faster. |
I'm not willing to die on this hill, but I've never been a fan of explicit begins, as it creates a dual-use code block that obfuscates the error handling at the beginning and sort of encourages an error handler to cover the entirety of a method rather than specific lines that need to be protected. I totally get the limited use case here, but in the event the code is altered, the maintainer may not see that the code is contained in this dual-use code block unless they scan down and see the handler code. |
I will add my assent to @bwatters-r7 view in that explicit well scoped |
After reviewing this I also have to agree with @bwatters-r7 and @jmartin-r7's points. Whilst there were some cases where there is definitely an advantage for code cleanliness, there were one or two cases here where the lack of explicit That being said I do think the spacing changes are good and I have no issue with those, and the majority of the |
I'm in favor of the change as it's idiomatic Ruby, and with the autofix support it won't be an inconvenience to new contributors who aren't aware of this Ruby feature. Accidental overzealous try/catches of course aren't good either, but overall I don't mind if this gets merged in |
I prefer to narrow my |
However, I will also state that explicit |
tl;dr I could go either way. Previous discussion. |
This has come up a few times during PR review, probably best to just automate it.
https://github.com/rubocop/ruby-style-guide#implicit-begin
Verification
Best viewed with whitespace disabled ?=w1