Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-13 18:09:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-13 18:09:32 +0300
commitbd25f1d9c685039381df23e49bc52cdcf4ec1b4a (patch)
tree33b3b16ae2ef653f74828f69742154122ff0ac2d /rubocop
parent70ce746bd011b101605e6d84f141d1f0c3175831 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/background_migration_missing_active_concern.rb58
-rw-r--r--rubocop/migration_helpers.rb6
2 files changed, 63 insertions, 1 deletions
diff --git a/rubocop/cop/migration/background_migration_missing_active_concern.rb b/rubocop/cop/migration/background_migration_missing_active_concern.rb
new file mode 100644
index 00000000000..417472bf512
--- /dev/null
+++ b/rubocop/cop/migration/background_migration_missing_active_concern.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that checks `ActiveSupport::Concern` is included in EE batched background migrations
+ # if they define `scope_to`.
+ class BackgroundMigrationMissingActiveConcern < RuboCop::Cop::Base
+ include MigrationHelpers
+
+ MSG = <<~MSG
+ Extend `ActiveSupport::Concern` in the EE background migration if it defines `scope_to`.
+ MSG
+
+ def_node_matcher :prepended_block_uses_scope_to?, <<~PATTERN
+ (:block (:send nil? :prepended) (:args) `(:send nil? :scope_to ...))
+ PATTERN
+
+ def_node_matcher :scope_to?, <<~PATTERN
+ (:send nil? :scope_to ...)
+ PATTERN
+
+ def_node_matcher :extend_activesupport_concern?, <<~PATTERN
+ (:send nil? :extend (:const (:const nil? :ActiveSupport) :Concern))
+ PATTERN
+
+ def on_block(node)
+ return unless in_ee_background_migration?(node)
+ return unless prepended_block_uses_scope_to?(node)
+
+ return if module_extends_activesupport_concern?(node)
+
+ node.descendants.each do |descendant|
+ next unless scope_to?(descendant)
+
+ add_offense(descendant)
+ end
+ end
+
+ private
+
+ def module_extends_activesupport_concern?(node)
+ while node = node.parent
+ break if node.type == :module
+ end
+
+ return false unless node
+
+ node.descendants.any? do |descendant|
+ extend_activesupport_concern?(descendant)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb
index f14f4d33709..16a9aa53cd3 100644
--- a/rubocop/migration_helpers.rb
+++ b/rubocop/migration_helpers.rb
@@ -34,7 +34,11 @@ module RuboCop
def in_background_migration?(node)
filepath(node).include?('/lib/gitlab/background_migration/') ||
- filepath(node).include?('/ee/lib/ee/gitlab/background_migration/')
+ in_ee_background_migration?(node)
+ end
+
+ def in_ee_background_migration?(node)
+ filepath(node).include?('/ee/lib/ee/gitlab/background_migration/')
end
def in_deployment_migration?(node)