summaryrefslogtreecommitdiff
path: root/rubocop/cop/sidekiq_redis_call.rb
blob: e4ae430f7c7302e84a4aaf1060644ea6a5c78930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module RuboCop
  module Cop
    # Cop that prevents manually setting a queue in Sidekiq workers.
    class SidekiqRedisCall < RuboCop::Cop::Base
      MSG = 'Refrain from directly using Sidekiq.redis unless for migration. For admin operations, use Sidekiq APIs.'

      def_node_matcher :using_sidekiq_redis?, <<~PATTERN
        (send (const nil? :Sidekiq) :redis)
      PATTERN

      def on_send(node)
        add_offense(node, message: MSG) if using_sidekiq_redis?(node)
      end
    end
  end
end