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-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /rubocop/cop/graphql
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'rubocop/cop/graphql')
-rw-r--r--rubocop/cop/graphql/authorize_types.rb21
1 files changed, 6 insertions, 15 deletions
diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb
index 7aaa9299362..1dba719cdff 100644
--- a/rubocop/cop/graphql/authorize_types.rb
+++ b/rubocop/cop/graphql/authorize_types.rb
@@ -7,39 +7,30 @@ module RuboCop
MSG = 'Add an `authorize :ability` call to the type: '\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
- TYPES_DIR = 'app/graphql/types'
-
# We want to exclude our own basetypes and scalars
- WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
- QueryType GraphQL::Schema BaseUnion].freeze
+ ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
+ QueryType GraphQL::Schema BaseUnion].freeze
def_node_search :authorize?, <<~PATTERN
(send nil? :authorize ...)
PATTERN
def on_class(node)
- return unless in_type?(node)
- return if whitelisted?(class_constant(node))
- return if whitelisted?(superclass_constant(node))
+ return if allowed?(class_constant(node))
+ return if allowed?(superclass_constant(node))
add_offense(node, location: :expression) unless authorize?(node)
end
private
- def in_type?(node)
- path = node.location.expression.source_buffer.name
-
- path.include? TYPES_DIR
- end
-
- def whitelisted?(class_node)
+ def allowed?(class_node)
class_const = class_node&.const_name
return false unless class_const
return true if class_const.end_with?('Enum')
- WHITELISTED_TYPES.any? { |whitelisted| class_node.const_name.include?(whitelisted) }
+ ALLOWED_TYPES.any? { |allowed| class_node.const_name.include?(allowed) }
end
def class_constant(node)