-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
AmbiguousBlockAssociation gives bad advice #4181
Comments
Well, the message of the cop could probably be better, but the advice is just what it's supposed to be. That's not a bug. Might not play well with some DSLs, but the cop works just as it's expected to. Such code is confusing and should ideally be avoided. |
Huh? The point of this bug report is that the message could be better. I'm not saying this should not be flagged as ambiguous. |
we just started getting this error message which makes no sense at all: 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 }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
@stephengroat that looks like a different issue, so I think you should file a new ticket for it. |
@mvz thanks will do |
Suggestions for improvements are welcome. I'm not super fond of the current message myself. |
@mvz Feel free to suggest any improvements for description for this cop. I can change it and create PR when we all ok with that. |
Given:
|
Hi guys, @mvz @ashmaroli @bbatsov Now for this code: It will return this message:
It should provide better guidance for developer on fixing this offense. |
@smakagon Yes, that's more understandable and in line with what I suggested in the comment above. 👍 |
Yes, that's much better! |
The message printed for the AmbiguousBlockAssociation cop is confusing because it assumes an intent on the part of the developer that does not match the actual behavior of Ruby. I.e., the message only makes sense if the code in question is currently broken.
Here is an example:
Here, the cop would print something like:
However, the code as it stands associates the block with
bar
, and if the code is currently working, the programmer should definitely not parenthesize the parameter, because it would change the meaning of the code.Expected behavior
I expect RuboCop to either make no suggestion on how to resolve the ambiguity, or to suggest something that does not change the semantics of the code as it stands.
Actual behavior
RuboCop suggests a change that always breaks the existing code.
Steps to reproduce the problem
Create a file
foo.rb
, containing:Run
rubocop foo.rb
.RuboCop version
The text was updated successfully, but these errors were encountered: