-
-
Notifications
You must be signed in to change notification settings - Fork 263
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 false negatives for Rails/RedundantActiveRecordAllMethod
when using POSSIBLE_ENUMERABLE_BLOCK_METHODS
in a block
#1382
Fix false negatives for Rails/RedundantActiveRecordAllMethod
when using POSSIBLE_ENUMERABLE_BLOCK_METHODS
in a block
#1382
Conversation
Rails/RedundantActiveRecordAllMethod
when m…Rails/RedundantActiveRecordAllMethod
when using POSSIBLE_ENUMERABLE_BLOCK_METHODS
in a block
a97f810
to
b8a039a
Compare
@@ -174,7 +174,7 @@ def possible_enumerable_block_method?(node) | |||
parent = node.parent | |||
return false unless POSSIBLE_ENUMERABLE_BLOCK_METHODS.include?(parent.method_name) | |||
|
|||
parent.parent&.block_type? || parent.parent&.numblock_type? || parent.first_argument&.block_pass_type? | |||
parent.block_node || parent.first_argument&.block_pass_type? |
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.
block_node
doesn't return a boolean value for predicate method. block_literal?
seems more appropriate.
parent.block_node || parent.first_argument&.block_pass_type? | |
parent.block_literal? || parent.first_argument&.block_pass_type? |
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.
Thank you for your review! I've fixed some issues.
@@ -0,0 +1 @@ | |||
* [#1382](https://github.com/rubocop/rubocop-rails/pull/1382): Fix false negatives for `Rails/RedundantActiveRecordAllMethod`. ([@masato-bkn][]) |
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.
The change log could use a bit more information. For example, something like the following:
* [#1382](https://github.com/rubocop/rubocop-rails/pull/1382): Fix false negatives for `Rails/RedundantActiveRecordAllMethod`. ([@masato-bkn][]) | |
* [#1382](https://github.com/rubocop/rubocop-rails/pull/1382): Fix false negatives for `Rails/RedundantActiveRecordAllMethod` when using `all` method in block. ([@masato-bkn][]) |
b8a039a
to
e42189c
Compare
…sing `all` method in block This PR fixes false negatives for `Rails/RedundantActiveRecordAllMethod` when methods in `POSSIBLE_ENUMERABLE_BLOCK_METHODS` are used in a block as following: ``` expect { subject }.to change { User.all.count } ```
e42189c
to
2d7e7a0
Compare
Thanks! |
This PR fixes false negatives for
Rails/RedundantActiveRecordAllMethod
when methods inPOSSIBLE_ENUMERABLE_BLOCK_METHODS
are used in a block.Expected Behavior
Actual Behavior
No offenses are registered.
Steps to reproduce the problem
Run
bundle ex rubocop --only Rails/RedundantActiveRecordAllMethod
on the code below:RuboCop version
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.