Class: RuboCop::Cop::Sidekiq::JobFileNaming

Inherits:
Base
  • Object
show all
Includes:
ClassNameHelper, ProcessedSourcePath
Defined in:
lib/rubocop/cop/sidekiq/job_file_naming.rb

Overview

Checks that job file names match the class name.

Examples:

# bad - file: send_email_worker.rb
class SendEmailJob
  include Sidekiq::Job
end

Constant Summary collapse

MSG =
'Job file name should match the class name.'

Instance Method Summary collapse

Methods included from Sidekiq::Language

#active_job_class?, #perform_call?, #sidekiq_include?, #sidekiq_options_call?

Instance Method Details

#on_class(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/sidekiq/job_file_naming.rb', line 20

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

  file_path = processed_file_path
  return unless file_path

  class_name = class_name(node)
  return unless class_name

  expected = underscore(class_name)
  actual = File.basename(file_path, '.rb')
  return if expected == actual

  add_offense(node.loc.keyword)
end