2019-08-26 08:24:25 -04:00
|
|
|
# frozen_string_literal: true
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that makes sure workers include `ApplicationWorker`, not `Sidekiq::Worker`.
|
|
|
|
class IncludeSidekiqWorker < RuboCop::Cop::Cop
|
2021-03-23 11:09:28 -04:00
|
|
|
MSG = 'Include `ApplicationWorker`, not `Sidekiq::Worker`.'
|
2017-12-12 11:21:00 -05:00
|
|
|
|
|
|
|
def_node_matcher :includes_sidekiq_worker?, <<~PATTERN
|
2017-09-19 11:25:42 -04:00
|
|
|
(send nil? :include (const (const nil? :Sidekiq) :Worker))
|
2017-12-12 11:21:00 -05:00
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless includes_sidekiq_worker?(node)
|
|
|
|
|
2017-09-19 11:25:42 -04:00
|
|
|
add_offense(node.arguments.first, location: :expression)
|
2017-12-12 11:21:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def autocorrect(node)
|
|
|
|
lambda do |corrector|
|
|
|
|
corrector.replace(node.source_range, 'ApplicationWorker')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|