diff options
Diffstat (limited to 'rubocop/cop/graphql/id_type.rb')
-rw-r--r-- | rubocop/cop/graphql/id_type.rb | 29 |
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..9ec877900ec --- /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].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 |