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

Lint/AmbiguousBlockAssociation's message is confusing #5170

Closed
eregon opened this issue Dec 1, 2017 · 2 comments
Closed

Lint/AmbiguousBlockAssociation's message is confusing #5170

eregon opened this issue Dec 1, 2017 · 2 comments

Comments

@eregon
Copy link

eregon commented Dec 1, 2017

The message is (for the code using Module.new {}):

Parenthesize the param Module.new {} to make sure that the block
will be associated with the Module.new method call.

But this sounds like spreading fear and doubt when the Ruby parser has no such concepts :)
{} always binds tightly to the call right next to it.
This block {} will never go to using, unless it's rewritten as do ... end.

Expected behavior

A better message, clarifying the true purpose of the cop, which I guess is to differentiate empty Hash literals and blocks.
Maybe

core/module/using_spec.rb:92:9: W: Lint/AmbiguousBlockAssociation: Parenthesize the param
`Module.new {}` to clarify `{}` is a block passed to `Module.new` and not an empty Hash literal.
        using Module.new {}
        ^^^^^^^^^^^^^^^^^^^

However, I find using(Module.new {}) not so beautiful, but that might be subjective.

mod = Module.new
using mod

is likely a better fix.

Actual behavior

core/module/using_spec.rb:92:9: W: Lint/AmbiguousBlockAssociation: Parenthesize the param
Module.new {} to make sure that the block will be associated with the Module.new method call.
        using Module.new {}
        ^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

Run RuboCop on a file containing

using Module.new {}

RuboCop version

$ rubocop -V
0.51.0 (using Parser 2.4.0.2, running on ruby 2.4.2 x86_64-linux)
@Drenmi
Copy link
Collaborator

Drenmi commented Dec 2, 2017

Looks like the message was improved once in #4181, but I agree that there's more room for improvement. 🙂

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 13, 2018

I'm closing this ticket due to no recent activity. Feel free to re-open it if you ever come back to it. PRs welcome!

@bbatsov bbatsov closed this as completed Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants