Class: RuboCop::Cop::Sidekiq::JobNaming

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/rubocop/cop/sidekiq/job_naming.rb

Overview

This cop checks that Sidekiq job class names end with “Job” instead of “Worker”. Since Sidekiq 6.3, it is best practice to use “Job” terminology over “Worker”.

Examples:

# bad
class MyWorker
  include Sidekiq::Job
end

class ProcessDataWorker
  include Sidekiq::Worker
end

# good
class MyJob
  include Sidekiq::Job
end

class ProcessDataJob
  include Sidekiq::Job
end

Constant Summary collapse

MSG =
'Job class name should end with `Job` instead of `Worker`.'

Constants included from Helpers

Helpers::NODE_MATCHERS

Instance Method Summary collapse

Methods included from Helpers

#approve_node, #expand_array_node, #expand_hash_array_node, #expand_hash_node, #expand_node, #expand_nodes, #in_sidekiq_worker?, included, #node_approved?, #sidekiq_arguments, #within?

Instance Method Details

#on_class(node) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/rubocop/cop/sidekiq/job_naming.rb', line 38

def on_class(node)
  return unless sidekiq_worker?(node)

  class_name = extract_class_name(node)
  return unless class_name
  return unless class_name.end_with?('Worker')

  add_offense(node.children.first, message: MSG)
end