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`.
|
2022-09-14 11:12:56 -04:00
|
|
|
class IncludeSidekiqWorker < RuboCop::Cop::Base
|
|
|
|
extend RuboCop::Cop::AutoCorrector
|
|
|
|
|
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)
|
|
|
|
|
2022-09-14 11:12:56 -04:00
|
|
|
add_offense(node.arguments.first) do |corrector|
|
|
|
|
corrector.replace(node.arguments.first, 'ApplicationWorker')
|
2017-12-12 11:21:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|