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

Parenthesize warning incorrectly identifying method as param #4198

Closed
stephengroat opened this issue Mar 28, 2017 · 5 comments
Closed

Parenthesize warning incorrectly identifying method as param #4198

stephengroat opened this issue Mar 28, 2017 · 5 comments
Labels

Comments

@stephengroat
Copy link

the cop identifies the method sort_by as a paramater


Expected behavior

Unknown what the purpose of the cop exactly is

Actual behavior

verify.rb:59:8: W: Parenthesize the param sort_by to make sure that the block will be associated with the != method call.
   error('section.yml is not alphabetized by name') \
       if sections != sections.sort_by { |section| section['id'].downcase }
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

git checkout https://github.com/2factorauth/twofactorauth -b 51df6e1
bundle install
bundle exec rake

RuboCop version

Using rubocop 0.48.0
@bbatsov bbatsov added the bug label Mar 28, 2017
@dzirtusss
Copy link

Same mistake happens for common rspec assertions like:

expect(deliver).not_to change { GuestListMembership.count }

Where parenthesize seems also not needed

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 30, 2017

Where parenthesize seems also not needed

This example is different - it this DSL that's completely fine, but it might have also been an actual oversight. The cop can't possible tell those apart. I'm advising people to simply disable the cop when needed in such cases. Or we can add some method exceptions list. At any rate - that's a different problem.

@dzirtusss
Copy link

Thanks for quick answer, in my case I've decided to fix it refactoring to:

expect(deliver).not_to change(GuestListMembership, :count)

But you may consider putting exception I guess... this is looks like common case to me.

@dzirtusss
Copy link

As well rubocop raises only with expect().not_to same with expect().to doesn't raise this error.

Drenmi added a commit to Drenmi/rubocop that referenced this issue Mar 31, 2017
…ator methods

This cop would register an offense when the outer method is an operator,
e.g.:

```
foo == bar { |b| b.baz }
```

However, this is idiomatic Ruby, and disambiguation isn't needed in
these cases.

This change fixes that.
@SirRawlins
Copy link

@dzirtusss I'm seeing the exact same thing here, barks only on expect().not_to

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

No branches or pull requests

4 participants