summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 15:07:59 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-27 15:07:59 +0000
commit71c5863d7b1ca9836a7d7703f35750cd726a9846 (patch)
treef6d74be15157d527ffc648212df141293a36a330 /rubocop
parent39fa7d1eeb2dba52f0601128f3ac91f57d19866e (diff)
downloadgitlab-ce-71c5863d7b1ca9836a7d7703f35750cd726a9846.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb b/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb
new file mode 100644
index 00000000000..ebd91dd5a6e
--- /dev/null
+++ b/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ # Cop that prevents usage of `with_lock_retries` with `disable_ddl_transaction!`
+ class WithLockRetriesWithoutDdlTransaction < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ MSG = '`with_lock_retries` cannot be used with disabled DDL transactions (`disable_ddl_transaction!`). ' \
+ 'Please remove the `disable_ddl_transaction!` call from your migration.'.freeze
+
+ def_node_matcher :disable_ddl_transaction?, <<~PATTERN
+ (send _ :disable_ddl_transaction!)
+ PATTERN
+
+ def_node_matcher :with_lock_retries?, <<~PATTERN
+ (send _ :with_lock_retries)
+ PATTERN
+
+ def on_send(node)
+ return unless in_migration?(node)
+ return unless with_lock_retries?(node)
+
+ node.each_ancestor(:begin) do |begin_node|
+ disable_ddl_transaction_node = begin_node.children.find { |n| disable_ddl_transaction?(n) }
+
+ add_offense(node, location: :expression) if disable_ddl_transaction_node
+ end
+ end
+ end
+ end
+ end
+end