Welcome to mirror list, hosted at ThFree Co, Russian Federation.

id_type.rb « graphql « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53d79751fa8e6cc50a5dff5532d663be720cc298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module RuboCop
  module Cop
    module Graphql
      class IDType < RuboCop::Cop::Base
        MSG = 'Do not use GraphQL::Types::ID, use a specific GlobalIDType instead'

        ALLOWLISTED_ARGUMENTS = %i[iid full_path project_path group_path target_project_path namespace_path].freeze

        def_node_search :graphql_id_type?, <<~PATTERN
          (send nil? :argument (_ #does_not_match?) (const (const (const nil? :GraphQL) :Types) :ID) ...)
        PATTERN

        def on_send(node)
          return unless graphql_id_type?(node)

          add_offense(node)
        end

        private

        def does_not_match?(arg)
          !ALLOWLISTED_ARGUMENTS.include?(arg) # rubocop:disable Rails/NegateInclude
        end
      end
    end
  end
end