2021-01-03 14:25:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Graphql
|
|
|
|
class IDType < RuboCop::Cop::Cop
|
2021-10-27 15:23:28 +05:30
|
|
|
MSG = 'Do not use GraphQL::Types::ID, use a specific GlobalIDType instead'
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
WHITELISTED_ARGUMENTS = %i[iid full_path project_path group_path target_project_path namespace_path].freeze
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
def_node_search :graphql_id_type?, <<~PATTERN
|
2021-10-27 15:23:28 +05:30
|
|
|
(send nil? :argument (_ #does_not_match?) (const (const (const nil? :GraphQL) :Types) :ID) ...)
|
2021-01-03 14:25:43 +05:30
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless graphql_id_type?(node)
|
|
|
|
|
|
|
|
add_offense(node)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def does_not_match?(arg)
|
|
|
|
!WHITELISTED_ARGUMENTS.include?(arg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|