Class: RuboCop::Cop::Sidekiq::PreferJob

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/sidekiq/prefer_job.rb

Overview

This cop checks for the use of ‘Sidekiq::Worker` and suggests using `Sidekiq::Job` instead. Since Sidekiq 6.3, it is best practice to use `Sidekiq::Job` over `Sidekiq::Worker`.

Examples:

# bad
class MyWorker
  include Sidekiq::Worker
end

# good
class MyJob
  include Sidekiq::Job
end

Constant Summary collapse

MSG =
'Prefer `Sidekiq::Job` over `Sidekiq::Worker`.'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rubocop/cop/sidekiq/prefer_job.rb', line 30

def on_send(node)
  return unless sidekiq_worker_include?(node)

  add_offense(node, message: MSG) do |corrector|
    corrector.replace(node.arguments.first, 'Sidekiq::Job')
  end
end