Commit 2aa1fabe authored by Peter Leitzen's avatar Peter Leitzen

Merge branch...

Merge branch '225643-follow-up-from-resolve-add-graphql-authorizetype-cop-to-ee-namespaced-types' into 'master'

Avoid misused terms in Graphql/AuthorizeType cop

Closes #225643

See merge request gitlab-org/gitlab!35851
parents 753957f5 b94326d2
......@@ -8,7 +8,7 @@ module RuboCop
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
# We want to exclude our own basetypes and scalars
WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
QueryType GraphQL::Schema BaseUnion].freeze
def_node_search :authorize?, <<~PATTERN
......@@ -16,21 +16,21 @@ module RuboCop
PATTERN
def on_class(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 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment