Commit c5729733 authored by Brett Walker's avatar Brett Walker Committed by Sean McGivern

Rubocop should ignore GraphQL enums

when checking for authorization
parent 655e07d1
# frozen_string_literal: true # frozen_string_literal: true
module Types module Types
# rubocop: disable Graphql/AuthorizeTypes
class IssuableSortEnum < SortEnum class IssuableSortEnum < SortEnum
graphql_name 'IssuableSort' graphql_name 'IssuableSort'
description 'Values for sorting issuables' description 'Values for sorting issuables'
end end
# rubocop: enable Graphql/AuthorizeTypes
end end
# frozen_string_literal: true # frozen_string_literal: true
module Types module Types
# rubocop: disable Graphql/AuthorizeTypes
class IssueSortEnum < IssuableSortEnum class IssueSortEnum < IssuableSortEnum
graphql_name 'IssueSort' graphql_name 'IssueSort'
description 'Values for sorting issues' description 'Values for sorting issues'
...@@ -10,7 +9,6 @@ module Types ...@@ -10,7 +9,6 @@ module Types
value 'DUE_DATE_DESC', 'Due date by descending order', value: 'due_date_desc' value 'DUE_DATE_DESC', 'Due date by descending order', value: 'due_date_desc'
value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order', value: 'relative_position_asc' value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order', value: 'relative_position_asc'
end end
# rubocop: enable Graphql/AuthorizeTypes
end end
Types::IssueSortEnum.prepend_if_ee('::EE::Types::IssueSortEnum') Types::IssueSortEnum.prepend_if_ee('::EE::Types::IssueSortEnum')
# frozen_string_literal: true # frozen_string_literal: true
module Types module Types
# rubocop: disable Graphql/AuthorizeTypes
# This is a BaseEnum through IssuableEnum, so it does not need authorization
class IssueStateEnum < IssuableStateEnum class IssueStateEnum < IssuableStateEnum
graphql_name 'IssueState' graphql_name 'IssueState'
description 'State of a GitLab issue' description 'State of a GitLab issue'
end end
# rubocop: enable Graphql/AuthorizeTypes
end end
# frozen_string_literal: true # frozen_string_literal: true
module Types module Types
# rubocop: disable Graphql/AuthorizeTypes
# This is a BaseEnum through IssuableEnum, so it does not need authorization
class MergeRequestStateEnum < IssuableStateEnum class MergeRequestStateEnum < IssuableStateEnum
graphql_name 'MergeRequestState' graphql_name 'MergeRequestState'
description 'State of a GitLab merge request' description 'State of a GitLab merge request'
value 'merged' value 'merged'
end end
# rubocop: enable Graphql/AuthorizeTypes
end end
...@@ -34,7 +34,10 @@ module RuboCop ...@@ -34,7 +34,10 @@ module RuboCop
end end
def whitelisted?(class_node) def whitelisted?(class_node)
return false unless class_node&.const_name 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) } WHITELISTED_TYPES.any? { |whitelisted| class_node.const_name.include?(whitelisted) }
end end
......
...@@ -79,5 +79,15 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do ...@@ -79,5 +79,15 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do
end end
TYPE TYPE
end end
it 'does not add an offense for Enums' do
expect_no_offenses(<<~TYPE)
module Types
class ATypeEnum < AnotherEnum
field :a_thing
end
end
TYPE
end
end end
end end
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