When passing a lambda declaration as a method parameter, the new Lint/AmbiguousBlockAssociation cop forces unnecessary parentheses.
Example:
# cited
foo ->(a) { a }
# making the cop happy
foo(->(a) { a })
Note that the method does not generally require parentheses:
# good
foo a
I expect Lint/AmbiguousBlockAssociation to not cite lambdas passed as params like any other object.
The new Lint/AmbiguousBlockAssociation cop creates a citation for lambdas passed as params like any other object.
Create file:
foo ->(a) { a }
Run rubocop:
rubocop -D
$ rubocop -V
0.48.0 (using Parser 2.4.0.0, running on ruby 2.3.3 x86_64-darwin16)
@Drenmi thanks for fixing that! I missed that case...
I got plain Rails scope like scope :technical, -> { where(technical: true) }
and I have
Parenthesize the param -> { where(technical: true) } to make sure that the block will be associated with the -> method call.
scope(:technical, -> { where(technical: true) }) fixes the problem but is it the way it should be?
scope :technical, (-> { where(technical: true) }) is good too but doesn't it look pretty strange?
@ivanovaleksey Are you using 0.48.1?
@bbatsov, yes
$ bundle exec rubocop -V
0.48.1 (using Parser 2.4.0.0, running on ruby 2.3.3 x86_64-darwin16)
Yeah, I'm seeing the same thing, on 0.48.1 for something like:
scope :vat, -> { where(post_subtotal_type: 'vat') }
@brandonweiss @bbatsov yes, there is a problem with lambda check. It's easily fixable. Should I create another PR to this issue?
Most helpful comment
I got plain Rails scope like
scope :technical, -> { where(technical: true) }and I have
scope(:technical, -> { where(technical: true) })fixes the problem but is it the way it should be?scope :technical, (-> { where(technical: true) })is good too but doesn't it look pretty strange?