diff options
Diffstat (limited to 'rubocop/cop/graphql/gid_expected_type.rb')
-rw-r--r-- | rubocop/cop/graphql/gid_expected_type.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/gid_expected_type.rb b/rubocop/cop/graphql/gid_expected_type.rb new file mode 100644 index 00000000000..354c5516752 --- /dev/null +++ b/rubocop/cop/graphql/gid_expected_type.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Graphql + class GIDExpectedType < RuboCop::Cop::Cop + MSG = 'Add an expected_type parameter to #object_from_id calls if possible.' + + def_node_search :id_from_object?, <<~PATTERN + (send ... :object_from_id (...)) + PATTERN + + def on_send(node) + return unless id_from_object?(node) + + add_offense(node) + end + end + end + end +end |