rubocop-graphql 1.5.1 → 1.5.3

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: 1307db3b7122e5a576ca03bbaecbb5798b03a927718aa85fa25fd5a9afe1ec07
4
- data.tar.gz: ea58763eb067a3e576149ebe41830a7ca7210e080e61382011fab9707ceaf2b9
3
+ metadata.gz: dcfe45f266ed034043a0d696144d81221322a9a6a68128e192fbac769ac696e7
4
+ data.tar.gz: 2f9a5060ffa601ba91b05fe3351029453d48da27a16a2b3512319fc4360bddc9
5
5
  SHA512:
6
- metadata.gz: 86d2c4c34918bb8713b15c4485b681d62b8b8c74b894aefbfb4d12e1d364ef2eff48c6c5562ca5b10690195b8f8403dacac73552b0cdfa2960f64fde07b63e3c
7
- data.tar.gz: 784d752ff412289d3eeeabdd204939bef5ad946e6cd5f40c8cc2ccfd1ebe4b7ec657f8ebe44c3d14fc7d8b50508891bc9b945f732b1b25c1a9dff6d6751ce87f
6
+ metadata.gz: ba60c5712c2c6c5445e4ef26ca320bc55e9e83a563389162cad75bfac2fbdb6f20ff3c947fd75eda284367fca751a0f053429b2acc84255b403d04cd42e2bfec
7
+ data.tar.gz: 3e60c89cfaea9ed2e281f7cb6a62f77776c4ab816bd20051ac7e1f0acb5061fdf494de2928777c8fd67568d314e0cb3cf7109eb2bc0b78c8c1b292ac58948be1
@@ -47,6 +47,7 @@ module RuboCop
47
47
  class FieldDefinitions < Base # rubocop:disable Metrics/ClassLength
48
48
  extend AutoCorrector
49
49
  include ConfigurableEnforcedStyle
50
+ include CommentsHelp
50
51
  include RuboCop::GraphQL::NodePattern
51
52
  include RuboCop::Cop::RangeHelp
52
53
  include RuboCop::GraphQL::Sorbet
@@ -212,17 +213,19 @@ module RuboCop
212
213
  end
213
214
 
214
215
  def insert_new_resolver(corrector, field_definition, resolver_definition)
216
+ resolver_definition_range = source_range_with_comment(resolver_definition)
215
217
  source_to_insert =
216
218
  "\n#{signature_to_insert(resolver_definition)}\n" \
217
- "#{indent(resolver_definition)}#{resolver_definition.source}\n"
219
+ "#{indent(resolver_definition)}#{resolver_definition_range.source.strip}\n"
218
220
 
219
221
  field_definition_range = range_including_heredoc(field_definition)
220
222
  corrector.insert_after(field_definition_range, source_to_insert)
221
223
  end
222
224
 
223
225
  def remove_old_resolver(corrector, resolver_definition)
226
+ resolver_definition_range = source_range_with_comment(resolver_definition)
224
227
  range_to_remove = range_with_surrounding_space(
225
- range: resolver_definition.source_range, side: :left
228
+ range: resolver_definition_range, side: :left
226
229
  )
227
230
  corrector.remove(range_to_remove)
228
231
 
@@ -230,8 +233,9 @@ module RuboCop
230
233
 
231
234
  return unless resolver_signature
232
235
 
236
+ resolver_signature_range = source_range_with_comment(resolver_signature)
233
237
  range_to_remove = range_with_surrounding_space(
234
- range: resolver_signature.source_range, side: :left
238
+ range: resolver_signature_range, side: :left
235
239
  )
236
240
  corrector.remove(range_to_remove)
237
241
  end
@@ -241,7 +245,8 @@ module RuboCop
241
245
 
242
246
  return unless signature
243
247
 
244
- "\n#{indent(signature)}#{signature.source}"
248
+ range = source_range_with_comment(signature)
249
+ "\n#{indent(signature)}#{range.source.strip}"
245
250
  end
246
251
 
247
252
  def indent(node)
@@ -58,16 +58,14 @@ module RuboCop
58
58
  "Field `%<current>s` should appear before `%<previous>s`."
59
59
 
60
60
  def on_class(node)
61
- declarations_with_blocks = argument_declarations_with_blocks(node)
62
- declarations_without_blocks = argument_declarations_without_blocks(node)
63
-
64
- argument_declarations = declarations_without_blocks.map do |node|
65
- arg_name = argument_name(node)
66
- same_arg_with_block_declaration = declarations_with_blocks.find do |dec|
67
- argument_name(dec) == arg_name
61
+ # Do a single pass over descendants to get argument declarations
62
+ # with and without a block.
63
+ argument_declarations = argument_declaration(node).map do |declaration|
64
+ if argument_declaration_with_block?(declaration)
65
+ declaration.parent
66
+ else
67
+ declaration
68
68
  end
69
-
70
- same_arg_with_block_declaration || node
71
69
  end
72
70
 
73
71
  argument_declarations.each_cons(2) do |previous, current|
@@ -80,6 +78,10 @@ module RuboCop
80
78
 
81
79
  private
82
80
 
81
+ def argument_declaration_with_block?(node)
82
+ node.parent&.block_type? && node.parent.send_node == node
83
+ end
84
+
83
85
  def register_offense(previous, current)
84
86
  message = format(
85
87
  self.class::MSG,
@@ -102,19 +104,10 @@ module RuboCop
102
104
  previous.source_range.last_line == current.source_range.first_line - 1
103
105
  end
104
106
 
105
- # @!method argument_declarations_without_blocks(node)
106
- def_node_search :argument_declarations_without_blocks, <<~PATTERN
107
+ # @!method argument_declaration(node)
108
+ def_node_search :argument_declaration, <<~PATTERN
107
109
  (send nil? :argument (:sym _) ...)
108
110
  PATTERN
109
-
110
- # @!method argument_declarations_with_blocks(node)
111
- def_node_search :argument_declarations_with_blocks, <<~PATTERN
112
- (block
113
- (send nil? :argument
114
- (:sym _)
115
- ...)
116
- ...)
117
- PATTERN
118
111
  end
119
112
  end
120
113
  end
@@ -8,16 +8,23 @@ module RuboCop
8
8
  end
9
9
 
10
10
  def range_including_heredoc(node)
11
- field = RuboCop::GraphQL::Field.new(node)
12
- last_heredoc = field.kwargs.instance_variable_get(:@nodes).reverse.find do |kwarg|
13
- heredoc?(kwarg.value)
14
- end&.value
11
+ last_heredoc = find_last_heredoc(node)
15
12
 
16
13
  range = node.source_range
17
14
  range = range.join(last_heredoc.loc.heredoc_end) if last_heredoc
18
15
 
19
16
  range_by_whole_lines(range)
20
17
  end
18
+
19
+ private
20
+
21
+ def find_last_heredoc(node)
22
+ # Do a cheap check first.
23
+ return nil unless node.source.include?("<<")
24
+
25
+ heredocs = node.descendants.select { |descendant| heredoc?(descendant) }
26
+ heredocs.max_by { |heredoc| heredoc.loc.heredoc_end }
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -15,16 +15,8 @@ module RuboCop
15
15
  end
16
16
 
17
17
  def sorbet_signature_for(node)
18
- node.parent.each_descendant.find do |sibling|
19
- siblings_in_sequence?(sibling, node) &&
20
- sorbet_signature(sibling)
21
- end
22
- end
23
-
24
- private
25
-
26
- def siblings_in_sequence?(first_node, second_node)
27
- first_node.sibling_index - second_node.sibling_index == - 1
18
+ sibling = node.left_sibling
19
+ sibling if sibling && sorbet_signature(sibling)
28
20
  end
29
21
  end
30
22
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "1.5.1".freeze
3
+ VERSION = "1.5.3".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: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Tsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-31 00:00:00.000000000 Z
11
+ date: 2024-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.90'
61
+ version: '1.50'
62
62
  - - "<"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '2'
@@ -68,7 +68,7 @@ dependencies:
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: '0.90'
71
+ version: '1.50'
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'