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 TransactionExitStatement
in_rescue?
Logic
#695
Conversation
@@ -0,0 +1 @@ | |||
* Fixes a false negative where the `in_rescue?` check would bypass situations where the return was inside a transaction but ouside of a rescue. ([@dorkrawk][]) |
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.
It seems like a typo.
* Fixes a false negative where the `in_rescue?` check would bypass situations where the return was inside a transaction but ouside of a rescue. ([@dorkrawk][]) | |
* Fixes a false negative where the `in_rescue?` check would bypass situations where the return was inside a transaction but outside of a rescue. ([@dorkrawk][]) |
And can you add the PR address?
* [#695](https://github.com/rubocop/rubocop-rails/pull/695): Fixes a false negative where the `in_rescue?` check would bypass situations where the return was inside a transaction but outside of a rescue. ([@dorkrawk][])
return if user.active? | ||
^^^^^^ Exit statement `return` is not allowed. Use `raise` (rollback) or `next` (commit). |
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.
Can you indent it?
return if user.active? | |
^^^^^^ Exit statement `return` is not allowed. Use `raise` (rollback) or `next` (commit). | |
return if user.active? | |
^^^^^^ Exit statement `return` is not allowed. Use `raise` (rollback) or `next` (commit). |
({return | break | send nil? :throw} ...) | ||
... | ||
) | ||
PATTERN |
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.
Can you move it? The following is an example:
def_node_search :exit_statements, <<~PATTERN
({return | break | send nil? :throw} ...)
PATTERN
+ def_node_matcher :rescue_body_return_node?, <<~PATTERN
+ (:resbody ...
+ ...
+ ({return | break | send nil? :throw} ...)
+ ...
+ )
+ PATTERN
def on_send(node)
@koic Ok, I've made the requested updates and re-squashed the commits |
Thanks! |
The old logic for
in_rescue?
in theTransactionExitStatement
case missed situations where a transaction contained an exit outside of a rescue. For example:This fix adds a new node matcher to find exit statements within the rescue body.
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.and description in grammatically correct, complete sentences.