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-10-06 12:08:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-10-06 12:08:32 +0300
commit497d517e130ac88cbdee69c4c9e88938e164fc52 (patch)
treeeacf8eb83f872a775e7d3661ee96f2765a450ef9 /rubocop
parenta7cacc8293bdc9b088c7755a53efd304daab3a1c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/migration/with_lock_retries_disallowed_method.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
index a89c33c298b..aef19517a9d 100644
--- a/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
+++ b/rubocop/cop/migration/with_lock_retries_disallowed_method.rb
@@ -29,9 +29,14 @@ module RuboCop
].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(', ')}"
+ MSG_ONLY_ONE_FK_ALLOWED = "Avoid adding more than one foreign key within the `with_lock_retries`. See https://docs.gitlab.com/ee/development/migration_style_guide.html#examples"
def_node_matcher :send_node?, <<~PATTERN
- send
+ send
+ PATTERN
+
+ def_node_matcher :add_foreign_key?, <<~PATTERN
+ (send nil? :add_foreign_key ...)
PATTERN
def on_block(node)
@@ -53,6 +58,17 @@ module RuboCop
name = node.children[1]
add_offense(node, location: :expression) unless ALLOWED_MIGRATION_METHODS.include?(name)
+ add_offense(node, location: :selector, message: MSG_ONLY_ONE_FK_ALLOWED) if multiple_fks?(node)
+ end
+
+ def multiple_fks?(node)
+ return unless add_foreign_key?(node)
+
+ count = node.parent.each_descendant(:send).count do |node|
+ add_foreign_key?(node)
+ end
+
+ count > 1
end
end
end