将参数括号括起来以确保该块与方法调用相关联

And*_*eko 15 ruby ruby-on-rails rubocop

class User
  scope :active, -> { where(active: true) }
end
Run Code Online (Sandbox Code Playgroud)

运行rubocop我收到以下警告:

将参数括号括-> { where(active: true) }起来以确保该块将与->方法调用相关联.

我没有丝毫的线索,我的scope定义与此警告有什么关系.你呢?

除了关闭检查之外,我如何修复警告,因为此刻没有任何意义?

Ser*_*sev 22

它希望你这样做:

scope :active, (-> { where(active: true) }) 
Run Code Online (Sandbox Code Playgroud)

最好关掉警告:)

这种稳健的lambda语法非常好.也许你有旧的rubocop版本?

更新:固定在0.49.0.

  • 修复是[已合并](https://github.com/bbatsov/rubocop/pull/4237)在rubocop master中,很快检查新版本:) (5认同)