Skip to content
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

EachWithObject Cop Incorrectly Flags Block #1106

Closed
CyborgMaster opened this issue May 22, 2014 · 3 comments
Closed

EachWithObject Cop Incorrectly Flags Block #1106

CyborgMaster opened this issue May 22, 2014 · 3 comments

Comments

@CyborgMaster
Copy link

I'm pretty sure I've found a bug in the EachWithObject cop. It flags this call to reduce as one which should be changed to each_with_object

    used_replacement_variables.reduce(query) do |q, v|
      ReplacementVariableMap.query_for_variable v, q
    end

This uses ActiveRecord::Relation query objects and appends a bunch of query conditions into one query. I do return a query object here, but each addition returns a new Relation object so it needs to be passed on to the next call to reduce.

Maybe the cop just needs to be disabled with # rubocop:disable here, but it seems like this cop should be checking for a exact match on the return value. For example if the methods looked like this:

    used_replacement_variables.reduce(query) do |q, v|
      ReplacementVariableMap.query_for_variable v, q
      q
    end

then I would expect it to be flagged.

@geniou
Copy link
Contributor

geniou commented May 23, 2014

You are right - its a but. The cop is checking the return value, but somehow its not working. I take a look.

@geniou
Copy link
Contributor

geniou commented May 23, 2014

Fix is provided as pull request. @CyborgMaster thanks for reporting the bug.

bbatsov added a commit that referenced this issue May 23, 2014
[Fix #1106] EachWithObject with method call body
@CyborgMaster
Copy link
Author

@geniou, you're welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants