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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-12 09:09:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-12 09:09:02 +0300
commit5f362c717e637ba18d04d2ed6722098455c8b571 (patch)
treea5de8fbd57e14af24c950b7031137caf3358badf /rubocop
parent554826c7017ebcb2ce7343c1ea491dc611050b0b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/graphql/resolver_type.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/rubocop/cop/graphql/resolver_type.rb b/rubocop/cop/graphql/resolver_type.rb
new file mode 100644
index 00000000000..1209c5dbc6b
--- /dev/null
+++ b/rubocop/cop/graphql/resolver_type.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+# This cop checks for missing GraphQL type annotations on resolvers
+#
+# @example
+#
+# # bad
+# module Resolvers
+# class NoTypeResolver < BaseResolver
+# field :some_field, GraphQL::STRING_TYPE
+# end
+# end
+#
+# # good
+# module Resolvers
+# class WithTypeResolver < BaseResolver
+# type MyType, null: true
+#
+# field :some_field, GraphQL::STRING_TYPE
+# end
+# end
+
+module RuboCop
+ module Cop
+ module Graphql
+ class ResolverType < RuboCop::Cop::Cop
+ MSG = 'Missing type annotation: Please add `type` DSL method call. ' \
+ 'e.g: type UserType.connection_type, null: true'
+
+ def_node_matcher :typed?, <<~PATTERN
+ (... (begin <(send nil? :type ...) ...>))
+ PATTERN
+
+ def on_class(node)
+ add_offense(node, location: :expression) if resolver?(node) && !typed?(node)
+ end
+
+ private
+
+ def resolver?(node)
+ node.loc.name.source.end_with?('Resolver')
+ end
+ end
+ end
+ end
+end