Commit b94326d2 authored by Max Woolf's avatar Max Woolf Committed by Peter Leitzen

Replaces problematic language within cop

AuthorizeTypes cop makes use of the term
"whitelist" which has connotations about value
mapped to racial terms.

https://about.gitlab.com/handbook/communication/#top-misused-terms
parent d3306a77
...@@ -8,29 +8,29 @@ module RuboCop ...@@ -8,29 +8,29 @@ module RuboCop
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization' 'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
# We want to exclude our own basetypes and scalars # 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 QueryType GraphQL::Schema BaseUnion].freeze
def_node_search :authorize?, <<~PATTERN def_node_search :authorize?, <<~PATTERN
(send nil? :authorize ...) (send nil? :authorize ...)
PATTERN PATTERN
def on_class(node) def on_class(node)
return if whitelisted?(class_constant(node)) return if allowed?(class_constant(node))
return if whitelisted?(superclass_constant(node)) return if allowed?(superclass_constant(node))
add_offense(node, location: :expression) unless authorize?(node) add_offense(node, location: :expression) unless authorize?(node)
end end
private private
def whitelisted?(class_node) def allowed?(class_node)
class_const = class_node&.const_name class_const = class_node&.const_name
return false unless class_const return false unless class_const
return true if class_const.end_with?('Enum') 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 end
def class_constant(node) 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