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
Add new Lint/ConstantOverwrittenInRescue
cop
#10722
Conversation
Wow! > E=Class.new(StandardError)
> begin; raise E; rescue => E; end
(pry):2: warning: already initialized constant E
(pry):1: warning: previous definition of E was here
> E
#<E: E> Frankly, it looks like a Ruby bug or a deficiency. In any case, thanks for the cop! |
module RuboCop | ||
module Cop | ||
module Lint | ||
# Checks for overwriting an exception with an exception result by use `rescue =>`. |
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.
I'd expand on the documentation here and add some explanation that people what people wrote vs what they meant to write.
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.
Documentation has been expanded to include additional explanations.
I like the cop, we just need to expand a bit the docs and the examples. |
I'd go with |
This PR is add a new cop. Checks for overwriting an exception with an exception result by use `rescue =>`. You intended to write as `rescue StandardError`. However, you have written `rescue => StandardError`. In that case, the result of `rescue` will overwrite `StandardError`. ## @example ```ruby # bad begin something rescue => StandardError end # good begin something rescue StandardError end ```
@pirj Thank you so much. |
Lint/OverwriteByRescue
copLint/ConstantOverwrittenInRescue
cop
Looks good. Thanks! |
This PR is add a new cop.
Checks for overwriting an exception with an exception result by use
rescue =>
.@example
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.