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-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /rubocop/cop/gitlab
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'rubocop/cop/gitlab')
-rw-r--r--rubocop/cop/gitlab/avoid_feature_get.rb27
-rw-r--r--rubocop/cop/gitlab/bulk_insert.rb23
2 files changed, 50 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/avoid_feature_get.rb b/rubocop/cop/gitlab/avoid_feature_get.rb
new file mode 100644
index 00000000000..e36e0b020c0
--- /dev/null
+++ b/rubocop/cop/gitlab/avoid_feature_get.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Gitlab
+ # Cop that blacklists the use of `Feature.get`.
+ class AvoidFeatureGet < RuboCop::Cop::Cop
+ MSG = 'Use `Feature.enable/disable` methods instead of `Feature.get`. ' \
+ 'See doc/development/testing_guide/best_practices.md#feature-flags-in-tests for more information.'
+
+ def_node_matcher :feature_get?, <<~PATTERN
+ (send (const nil? :Feature) :get ...)
+ PATTERN
+
+ def_node_matcher :global_feature_get?, <<~PATTERN
+ (send (const (cbase) :Feature) :get ...)
+ PATTERN
+
+ def on_send(node)
+ return unless feature_get?(node) || global_feature_get?(node)
+
+ add_offense(node, location: :selector)
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/gitlab/bulk_insert.rb b/rubocop/cop/gitlab/bulk_insert.rb
new file mode 100644
index 00000000000..c03ffbe0b2a
--- /dev/null
+++ b/rubocop/cop/gitlab/bulk_insert.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Gitlab
+ # Cop that disallows the use of `Gitlab::Database.bulk_insert`, in favour of using
+ # the `BulkInsertSafe` module.
+ class BulkInsert < RuboCop::Cop::Cop
+ MSG = 'Use the `BulkInsertSafe` concern, instead of using `Gitlab::Database.bulk_insert`. See https://docs.gitlab.com/ee/development/insert_into_tables_in_batches.html'
+
+ def_node_matcher :raw_union?, <<~PATTERN
+ (send (const (const nil? :Gitlab) :Database) :bulk_insert ...)
+ PATTERN
+
+ def on_send(node)
+ return unless raw_union?(node)
+
+ add_offense(node, location: :expression)
+ end
+ end
+ end
+ end
+end