2022-07-16 23:28:13 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Migration
|
2022-10-11 01:57:18 +05:30
|
|
|
class BackgroundMigrationBaseClass < RuboCop::Cop::Base
|
2022-07-16 23:28:13 +05:30
|
|
|
MSG = 'Batched background migration jobs should inherit from Gitlab::BackgroundMigration::BatchedMigrationJob'
|
|
|
|
|
|
|
|
def_node_search :top_level_module?, <<~PATTERN
|
|
|
|
(module (const nil? :Gitlab) (module (const nil? :BackgroundMigration) ...))
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def_node_matcher :matching_parent_namespace?, <<~PATTERN
|
|
|
|
{nil? (const (const {cbase nil?} :Gitlab) :BackgroundMigration)}
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def_node_search :inherits_batched_migration_job?, <<~PATTERN
|
|
|
|
(class _ (const #matching_parent_namespace? :BatchedMigrationJob) ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_module(module_node)
|
|
|
|
return unless top_level_module?(module_node)
|
|
|
|
|
|
|
|
top_level_class_node = module_node.each_descendant(:class).first
|
|
|
|
|
|
|
|
return if top_level_class_node.nil? || inherits_batched_migration_job?(top_level_class_node)
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
add_offense(top_level_class_node)
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|