2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that prevents manually setting a queue in Sidekiq workers.
|
2022-10-11 01:57:18 +05:30
|
|
|
class SidekiqOptionsQueue < RuboCop::Cop::Base
|
2021-04-29 21:17:54 +05:30
|
|
|
MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def_node_matcher :sidekiq_options?, <<~PATTERN
|
|
|
|
(send nil? :sidekiq_options $...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless sidekiq_options?(node)
|
|
|
|
|
|
|
|
node.arguments.first.each_node(:pair) do |pair|
|
|
|
|
key_name = pair.key.children[0]
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
add_offense(pair) if key_name == :queue
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|