Class: RuboCop::Cop::Rails::ScopeArgs

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rails/scope_args.rb

Overview

Checks for scope calls where it was passed a method (usually a scope) instead of a lambda/proc.

Examples:


# bad
scope :something, where(something: true)

# good
scope :something, -> { where(something: true) }

Constant Summary collapse

MSG =
'Use `lambda`/`proc` instead of a plain method call.'
RESTRICT_ON_SEND =
%i[scope].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/rubocop/cop/rails/scope_args.rb', line 24

def on_send(node)
  scope?(node) do |second_arg|
    add_offense(second_arg) do |corrector|
      corrector.replace(second_arg, "-> { #{second_arg.source} }")
    end
  end
end