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>2021-09-20 16:18:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /rubocop/cop/migration/prevent_index_creation.rb
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'rubocop/cop/migration/prevent_index_creation.rb')
-rw-r--r--rubocop/cop/migration/prevent_index_creation.rb33
1 files changed, 28 insertions, 5 deletions
diff --git a/rubocop/cop/migration/prevent_index_creation.rb b/rubocop/cop/migration/prevent_index_creation.rb
index c90f911d24e..c383466f73b 100644
--- a/rubocop/cop/migration/prevent_index_creation.rb
+++ b/rubocop/cop/migration/prevent_index_creation.rb
@@ -12,16 +12,29 @@ module RuboCop
MSG = "Adding new index to #{FORBIDDEN_TABLES.join(", ")} is forbidden, see https://gitlab.com/gitlab-org/gitlab/-/issues/332886"
+ def on_new_investigation
+ super
+ @forbidden_tables_used = false
+ end
+
def_node_matcher :add_index?, <<~PATTERN
- (send nil? :add_index (sym #forbidden_tables?) ...)
+ (send nil? :add_index ({sym|str} #forbidden_tables?) ...)
PATTERN
def_node_matcher :add_concurrent_index?, <<~PATTERN
- (send nil? :add_concurrent_index (sym #forbidden_tables?) ...)
+ (send nil? :add_concurrent_index ({sym|str} #forbidden_tables?) ...)
PATTERN
- def forbidden_tables?(node)
- FORBIDDEN_TABLES.include?(node)
+ def_node_matcher :forbidden_constant_defined?, <<~PATTERN
+ (casgn nil? _ ({sym|str} #forbidden_tables?))
+ PATTERN
+
+ def_node_matcher :add_concurrent_index_with_constant?, <<~PATTERN
+ (send nil? :add_concurrent_index (const nil? _) ...)
+ PATTERN
+
+ def on_casgn(node)
+ @forbidden_tables_used = !!forbidden_constant_defined?(node)
end
def on_def(node)
@@ -32,8 +45,18 @@ module RuboCop
end
end
+ private
+
+ def forbidden_tables?(node)
+ FORBIDDEN_TABLES.include?(node.to_sym)
+ end
+
def offense?(node)
- add_index?(node) || add_concurrent_index?(node)
+ add_index?(node) || add_concurrent_index?(node) || any_constant_used_with_forbidden_tables?(node)
+ end
+
+ def any_constant_used_with_forbidden_tables?(node)
+ add_concurrent_index_with_constant?(node) && @forbidden_tables_used
end
end
end