rubocop-graphql 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a06d74f8fd3b057575ec841300332c5803de10df0fd2af2fb36f290830370e4
4
- data.tar.gz: 75ecf04464efb37fd64dbc1f5ad4d2a2c12523a277090897a832080100530252
3
+ metadata.gz: 34e03ca837f50f20a65cb0e80d7322c5b2998160148dbc354052875335efee8d
4
+ data.tar.gz: d14bb40f366fa3320c56262a7fafa7d47ffbe445092e481b3d9d0e946bd64649
5
5
  SHA512:
6
- metadata.gz: 14583dce74bc8bee2f10a024aad913f607de15b4e2ea340698b2b8ba211adaadd05e8130eb860074a94b670e967c8825b8bbbbd4b9d357bef99c201040531399
7
- data.tar.gz: 48b9456d0f54573da9472832322dbdd11f5e7c4793a1713131fa4fc72d4f2e8e75b0206c22eb68a1a2bfc1811af3536464c6a1a2a23c0cd137108374035107c3
6
+ metadata.gz: 634b1f66850e898eb545d78da1f6ccb8c0b0bc4fe11d5910e9d8f4820ea1af19e5d55a09ca755acfea73eb6cbb114ac59436a1dae6e6282da8b5fc176c09533e
7
+ data.tar.gz: 95ec70c992b7428116555b7c1107d1465d14ce7aa6753efea42ad4739a3c6c4bb3f67f0450eb320cd04d8bba4afbce0b00d1d3e4cef8aa305fa4eb80f81113bd
@@ -10,16 +10,19 @@ module RuboCop
10
10
  #
11
11
  # class SomeResolver < Resolvers::Base
12
12
  # argument :arg1, String, required: true
13
- # argument :arg2, String, required: true
13
+ # argument :user_id, String, required: true, loads: Types::UserType
14
+ # argument :post_id, String, loads: Types::PostType, as: :article
15
+ # argument :comment_ids, String, loads: Types::CommentType
14
16
  #
15
- # def resolve(arg1:, arg2:); end
17
+ # def resolve(arg1:, user:, article:, comments:); end
16
18
  # end
17
19
  #
18
20
  # # good
19
21
  #
20
22
  # class SomeResolver < Resolvers::Base
21
23
  # argument :arg1, String, required: true
22
- # argument :arg2, String, required: true
24
+ # argument :user_id, String, required: true, loads: Types::UserType
25
+ # argument :comment_ids, String, loads: Types::CommentType
23
26
  #
24
27
  # def resolve(arg1:, **rest); end
25
28
  # end
@@ -84,12 +87,15 @@ module RuboCop
84
87
  end
85
88
 
86
89
  def find_unresolved_args(method_node, declared_arg_nodes)
87
- resolve_method_kwargs = method_node.arguments.select(&:kwarg_type?).map do |node|
90
+ resolve_method_kwargs = method_node.arguments.select do |arg|
91
+ arg.kwarg_type? || arg.kwoptarg_type?
92
+ end
93
+ resolve_method_kwargs_names = resolve_method_kwargs.map do |node|
88
94
  node.node_parts[0]
89
95
  end.to_set
90
96
  declared_args = declared_arg_nodes.map { |node| RuboCop::GraphQL::Argument.new(node) }
91
- declared_args.map(&:name).uniq.reject do |declared_arg|
92
- resolve_method_kwargs.include?(declared_arg)
97
+ declared_args.map(&method(:arg_name)).uniq.reject do |declared_arg_name|
98
+ resolve_method_kwargs_names.include?(declared_arg_name)
93
99
  end
94
100
  end
95
101
 
@@ -119,6 +125,27 @@ module RuboCop
119
125
  node.loc.expression.end
120
126
  end
121
127
 
128
+ def inferred_arg_name(name_as_string)
129
+ case name_as_string
130
+ when /_id$/
131
+ name_as_string.sub(/_id$/, "").to_sym
132
+ when /_ids$/
133
+ name_as_string.sub(/_ids$/, "")
134
+ .sub(/([^s])$/, "\\1s")
135
+ .to_sym
136
+ else
137
+ name
138
+ end
139
+ end
140
+
141
+ def arg_name(declared_arg)
142
+ if declared_arg.kwargs.loads.nil?
143
+ declared_arg.name
144
+ else
145
+ declared_arg.as || inferred_arg_name(declared_arg.name.to_s)
146
+ end
147
+ end
148
+
122
149
  def_node_search :argument_declarations, <<~PATTERN
123
150
  (send nil? :argument (:sym _) ...)
124
151
  PATTERN
@@ -19,6 +19,14 @@ module RuboCop
19
19
  (pair (sym :description) ...)
20
20
  PATTERN
21
21
 
22
+ def_node_matcher :loads_kwarg?, <<~PATTERN
23
+ (pair (sym :loads) ...)
24
+ PATTERN
25
+
26
+ def_node_matcher :as_kwarg?, <<~PATTERN
27
+ (pair (sym :as) ...)
28
+ PATTERN
29
+
22
30
  def initialize(argument_node)
23
31
  @nodes = argument_kwargs(argument_node) || []
24
32
  end
@@ -26,6 +34,14 @@ module RuboCop
26
34
  def description
27
35
  @nodes.find { |kwarg| description_kwarg?(kwarg) }
28
36
  end
37
+
38
+ def loads
39
+ @nodes.find { |kwarg| loads_kwarg?(kwarg) }
40
+ end
41
+
42
+ def as
43
+ @nodes.find { |kwarg| as_kwarg?(kwarg) }
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -13,6 +13,10 @@ module RuboCop
13
13
  (send nil? :argument (:sym $_) ...)
14
14
  PATTERN
15
15
 
16
+ def_node_matcher :argument_as, <<~PATTERN
17
+ (pair (sym :as) (sym $_))
18
+ PATTERN
19
+
16
20
  attr_reader :node
17
21
 
18
22
  def initialize(node)
@@ -23,6 +27,10 @@ module RuboCop
23
27
  @name ||= argument_name(@node)
24
28
  end
25
29
 
30
+ def as
31
+ @as ||= argument_as(kwargs.as)
32
+ end
33
+
26
34
  def description
27
35
  @description ||= argument_description(@node) || kwargs.description || block.description
28
36
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.12.0".freeze
3
+ VERSION = "0.12.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Tsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
11
+ date: 2022-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler