summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-09-07 13:29:19 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-09-24 12:02:01 +0100
commit81d949f656979429835e0b6059a10a44faba488b (patch)
tree671a8927eab32278c656cb24e220ea4df41abd30 /rubocop
parent4ce9f2fdfb6d135e6229675b9965c1b90efdfcfe (diff)
downloadgitlab-ce-81d949f656979429835e0b6059a10a44faba488b.tar.gz
Applies the CE backport of EE#657
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/group_public_or_visible_to_user.rb22
-rw-r--r--rubocop/rubocop.rb1
2 files changed, 23 insertions, 0 deletions
diff --git a/rubocop/cop/group_public_or_visible_to_user.rb b/rubocop/cop/group_public_or_visible_to_user.rb
new file mode 100644
index 00000000000..beda0b7f8ba
--- /dev/null
+++ b/rubocop/cop/group_public_or_visible_to_user.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+#
+module RuboCop
+ module Cop
+ # Cop that blacklists the usage of Group.public_or_visible_to_user
+ class GroupPublicOrVisibleToUser < RuboCop::Cop::Cop
+ MSG = '`Group.public_or_visible_to_user` should be used with extreme care. ' \
+ 'Please ensure that you are not using it on its own and that the amount ' \
+ 'of rows being filtered is reasonable.'
+
+ def_node_matcher :public_or_visible_to_user?, <<~PATTERN
+ (send (const nil? :Group) :public_or_visible_to_user ...)
+ PATTERN
+
+ def on_send(node)
+ return unless public_or_visible_to_user?(node)
+
+ add_offense(node, location: :expression)
+ end
+ end
+ end
+end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index ff929c7b6ce..76d6037706e 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -38,3 +38,4 @@ require_relative 'cop/code_reuse/service_class'
require_relative 'cop/code_reuse/presenter'
require_relative 'cop/code_reuse/serializer'
require_relative 'cop/code_reuse/active_record'
+require_relative 'cop/group_public_or_visible_to_user'