summaryrefslogtreecommitdiff
path: root/rubocop/cop/graphql/id_type.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/graphql/id_type.rb')
-rw-r--r--rubocop/cop/graphql/id_type.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/id_type.rb b/rubocop/cop/graphql/id_type.rb
new file mode 100644
index 00000000000..96f90ac136a
--- /dev/null
+++ b/rubocop/cop/graphql/id_type.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Graphql
+ class IDType < RuboCop::Cop::Cop
+ MSG = 'Do not use GraphQL::ID_TYPE, use a specific GlobalIDType instead'
+
+ WHITELISTED_ARGUMENTS = %i[iid full_path project_path group_path target_project_path].freeze
+
+ def_node_search :graphql_id_type?, <<~PATTERN
+ (send nil? :argument (_ #does_not_match?) (const (const nil? :GraphQL) :ID_TYPE) ...)
+ 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