diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-12-12 19:21:00 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-12-13 18:28:26 +0300 |
commit | 3cad04cd51fb2453e33044a0eb2923dd389c2d20 (patch) | |
tree | b3169a93b7f4d3dc1429fa98cf09abb4a3a5c61a /rubocop/cop/sidekiq_options_queue.rb | |
parent | 0ec81dd5ac480120e7ac2b76189ee7978d5c48e8 (diff) |
Add rubocops to ensure Sidekiq workers include ApplicationWorker and don't manually set their queue
Diffstat (limited to 'rubocop/cop/sidekiq_options_queue.rb')
-rw-r--r-- | rubocop/cop/sidekiq_options_queue.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/rubocop/cop/sidekiq_options_queue.rb b/rubocop/cop/sidekiq_options_queue.rb new file mode 100644 index 00000000000..43b35ba0214 --- /dev/null +++ b/rubocop/cop/sidekiq_options_queue.rb @@ -0,0 +1,27 @@ +require_relative '../spec_helpers' + +module RuboCop + module Cop + # Cop that prevents manually setting a queue in Sidekiq workers. + class SidekiqOptionsQueue < RuboCop::Cop::Cop + include SpecHelpers + + MSG = 'Do not manually set a queue; `ApplicationWorker` sets one automatically.'.freeze + + def_node_matcher :sidekiq_options?, <<~PATTERN + (send nil :sidekiq_options $...) + PATTERN + + def on_send(node) + return if in_spec?(node) + return unless sidekiq_options?(node) + + node.arguments.first.each_node(:pair) do |pair| + key_name = pair.key.children[0] + + add_offense(pair, :expression) if key_name == :queue + end + end + end + end +end |