2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that makes sure workers include `ApplicationWorker`, not `Sidekiq::Worker`.
|
2022-10-11 01:57:18 +05:30
|
|
|
class IncludeSidekiqWorker < RuboCop::Cop::Base
|
|
|
|
extend RuboCop::Cop::AutoCorrector
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
MSG = 'Include `ApplicationWorker`, not `Sidekiq::Worker`.'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def_node_matcher :includes_sidekiq_worker?, <<~PATTERN
|
|
|
|
(send nil? :include (const (const nil? :Sidekiq) :Worker))
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless includes_sidekiq_worker?(node)
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
add_offense(node.arguments.first) do |corrector|
|
|
|
|
corrector.replace(node.arguments.first, 'ApplicationWorker')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|