2019-08-26 08:24:25 -04:00
|
|
|
# frozen_string_literal: true
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that prevents manually setting a queue in Sidekiq workers.
|
|
|
|
class SidekiqOptionsQueue < RuboCop::Cop::Cop
|
2021-03-23 11:09:28 -04:00
|
|
|
MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
def_node_matcher :sidekiq_options?, <<~PATTERN
|
2017-09-19 11:25:42 -04:00
|
|
|
(send nil? :sidekiq_options $...)
|
2017-12-12 11:21:00 -05:00
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless sidekiq_options?(node)
|
|
|
|
|
|
|
|
node.arguments.first.each_node(:pair) do |pair|
|
|
|
|
key_name = pair.key.children[0]
|
|
|
|
|
2017-09-19 11:25:42 -04:00
|
|
|
add_offense(pair, location: :expression) if key_name == :queue
|
2017-12-12 11:21:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|