forked from rubocop/rubocop-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope_args.rb
34 lines (30 loc) · 877 Bytes
/
scope_args.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# This cop checks for scope calls where it was passed
# a method (usually a scope) instead of a lambda/proc.
#
# @example
#
# # bad
# scope :something, where(something: true)
#
# # good
# scope :something, -> { where(something: true) }
class ScopeArgs < Base
extend AutoCorrector
MSG = 'Use `lambda`/`proc` instead of a plain method call.'
RESTRICT_ON_SEND = %i[scope].freeze
def_node_matcher :scope?, '(send nil? :scope _ $send)'
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
end
end
end
end