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>2020-05-04 12:09:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-04 12:09:36 +0300
commit5ba0ad3da6594180ec12d9166f925d9b1a27dce6 (patch)
tree7a2028f82f76f6031283180f608d54653296a286 /rubocop
parent2fa68d3a97fd31bf469050e130f0fc95e8944316 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/with_lock_retries_disallowed_method.rb58
-rw-r--r--rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb36
2 files changed, 58 insertions, 36 deletions
diff --git a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
new file mode 100644
index 00000000000..309ddcc9746
--- /dev/null
+++ b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require_relative '../../migration_helpers'
+
+module RuboCop
+ module Cop
+ module Migration
+ class WithLockRetriesDisallowedMethod < RuboCop::Cop::Cop
+ include MigrationHelpers
+
+ ALLOWED_MIGRATION_METHODS = %i[
+ create_table
+ drop_table
+ add_foreign_key
+ remove_foreign_key
+ add_column
+ remove_column
+ execute
+ change_column_default
+ remove_foreign_key_if_exists
+ remove_foreign_key_without_error
+ table_exists?
+ index_exists_by_name?
+ foreign_key_exists?
+ index_exists?
+ column_exists?
+ ].sort.freeze
+
+ MSG = "The method is not allowed to be called within the `with_lock_retries` block, the only allowed methods are: #{ALLOWED_MIGRATION_METHODS.join(', ')}"
+
+ def_node_matcher :send_node?, <<~PATTERN
+ send
+ PATTERN
+
+ def on_block(node)
+ block_body = node.body
+
+ return unless in_migration?(node)
+ return unless block_body
+ return unless node.method_name == :with_lock_retries
+
+ if send_node?(block_body)
+ check_node(block_body)
+ else
+ block_body.children.each { |n| check_node(n) }
+ end
+ end
+
+ def check_node(node)
+ return unless send_node?(node)
+
+ name = node.children[1]
+ add_offense(node, location: :expression) unless ALLOWED_MIGRATION_METHODS.include?(name)
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb b/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb
deleted file mode 100644
index ebd91dd5a6e..00000000000
--- a/rubocop/cop/migration/with_lock_retries_without_ddl_transaction.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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