debian-mirror-gitlab/rubocop/cop/include_sidekiq_worker.rb

27 lines
726 B
Ruby
Raw Normal View History

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`.
class IncludeSidekiqWorker < RuboCop::Cop::Cop
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)
add_offense(node.arguments.first, location: :expression)
end
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.source_range, 'ApplicationWorker')
end
end
end
end
end