Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 747
Andrey Deineko Avatar asked Apr 05 '17 10:04

Andrey Deineko


2 Answers

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.

like image 155
Sergio Tulentsev Avatar answered Sep 28 '22 23:09

Sergio Tulentsev


gem update rubocop worked for me.

like image 43
AnthonyM. Avatar answered Sep 28 '22 23:09

AnthonyM.