Search code examples
ruby-on-railsrubyruby-on-rails-4ruby-on-rails-5rubocop

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?


Solution

  • 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.