Parenthesize the param to make sure that block will be associated with method call
Asked Answered
B

2

17
class User
  scope :active, -> { where(active: true) }
end

Running rubocop I get the following warning:

Parenthesize the param -> { where(active: true) } to make sure that the block will be associated with the -> method call.

I have no slightest clue, what my scope definition has to do with this warning. Do you?

How do I fix the warning except for turning the check off because it makes no sense at the moment?

Brandie answered 5/4, 2017 at 10:53 Comment(0)
C
24

It wants you to do this:

scope :active, (-> { where(active: true) }) 

Better to turn off the warning :)

This stabby lambda syntax is perfectly fine. Maybe you have old rubocop version?

Update: fixed in 0.49.0.

Colucci answered 5/4, 2017 at 10:58 Comment(5)
Nope, I have the newest version (from April the 3rd - 0.48.1). Will accept in 8 mins :)Brandie
Fix is already merged in rubocop master, check the new version soon :)Gazehound
How can I turn off this warning? What should I put in .rubocop.yml to fix this?Detainer
Weird, still getting this with 0.48.1, going to disable the copBrenner
@tirdadc: yep, 0.48.1 still has it. You need a newer version. Or master.Colucci
T
4

gem update rubocop worked for me.

Tephrite answered 10/7, 2017 at 22:39 Comment(1)
this is the correct answer, as far as I am concernedAscendant

© 2022 - 2024 — McMap. All rights reserved.