-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Implement a cop checking for ambiguous block association with a method #3931
Comments
…iation with a method
@bbatsov Sorry for spammy commits above. I've created Pull Request. Thanks for review. One thing that I'm not happy about now is that cop throws warnings for code like this: What do you think about that? Should we catch those cases? And don't catch these cases: But in specs we still have code like this: Which looks the same like problem described in feature request: Let me know what you think. |
Refactored and Extended specs. Currently it catches cases like this: It will not catch method call with arguments but we can make it catch these cases easily, just let me know: All tests pass. Travis-CI check is green. |
Rubocop 0.48 introduced a new Lint/AmbiguousBlockAssocation cop [1], which guards against the issues detailed in rubocop/rubocop#3931. However, the pattern is a solid RSpec idiom and not likely to cause the problems Lint/AmbigiousBlockAssociation attempts to guard against. For example: expect { foo }.to change { bar } so we'll just ignore it in RSpec as suggested in rubocop/rubocop#4222. [1]: https://github.com/bbatsov/rubocop/blob/d1b9d66c3518389b0c408a6a4a42061b36748df4/relnotes/v0.48.0.md
Passing a single param to some method and a block (with no parens around the param) should yield a warning. Many people would confusingly believe the block would be associated with the first method, but it's actually going to be associated with its parameter.
See #3928 as a reference.
Here's an example:
Expected behavior
This code should produce a warning saying you should use parens to disambiguate the meaning of your code.
Actual behavior
No warning is raised.
Steps to reproduce the problem
Just run RuboCop over the example code.
RuboCop version
The text was updated successfully, but these errors were encountered: