Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sidekiq_options_queue.rb « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2574a229ec20f9fe942283ac8cc43041dab8e395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module RuboCop
  module Cop
    # Cop that prevents manually setting a queue in Sidekiq workers.
    class SidekiqOptionsQueue < RuboCop::Cop::Cop
      MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'

      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]

          add_offense(pair, location: :expression) if key_name == :queue
        end
      end
    end
  end
end