rubocop-graphql 1.5.0 → 1.5.2

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: b6b8cbd4a0d9dec84fd66e8fd76716d4d23d1a6ce486c713a951cd6c375255dd
4
- data.tar.gz: 9f7b85517392c031a54e63d9cbd28280cf41d9afb890f67f8e4054fc0704e553
3
+ metadata.gz: 54137ed6106e3d8c0d2c675ea02e41989aef1d4480edf875071c9c7918a96fba
4
+ data.tar.gz: a1a0b7d307854a39d4b4761d77cc829569dd9e97453a329d027886331407aae0
5
5
  SHA512:
6
- metadata.gz: 3474232c9c512d5b86d3c8fd43b790562b01ac458786e96c3c34a1556f530390fff21bd55a7805c382278b43d6c13cb336307b987ce070cbab01788e3c6e5194
7
- data.tar.gz: f8c5fba9247ad3ce42131b4bd3ee8dfd7f623eb896ca7cce9fb6e0f6ad29c6d38ce616f877e0a5d92dedc8a7701110cd37334fd9af1cb042bcc130285fa2b7d6
6
+ metadata.gz: 9e1fc8711b226bd656ca33d8409949a40667e9eabf31ca55a3536ae5f4f54f3af4e7254cbaa589e406172c724afdeb6772ffe5dd689909ebeb09608c7c94b848
7
+ data.tar.gz: 392b99c409b0e2b8247fff232d35fab529c1abf5eb3f7b648f40eb9020b07a5c56f074d88538626e564872a4a13f1cb59ee20a5ddc0c982099a2aa3edc596289
data/config/default.yml CHANGED
@@ -128,6 +128,7 @@ GraphQL/ResolverMethodLength:
128
128
  Max: 10
129
129
  CountComments: false
130
130
  ExcludedMethods: []
131
+ CountAsOne: []
131
132
 
132
133
  GraphQL/ObjectDescription:
133
134
  Enabled: true
@@ -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
@@ -23,9 +23,11 @@ module RuboCop
23
23
  return if excluded_methods.include?(String(node.method_name))
24
24
 
25
25
  if field_is_defined?(node)
26
- length = code_length(node)
26
+ return if node.line_count <= max_length
27
27
 
28
- return unless length > max_length
28
+ calculator = build_code_length_calculator(node)
29
+ length = calculator.calculate
30
+ return if length <= max_length
29
31
 
30
32
  add_offense(node, message: message(length))
31
33
  end
@@ -34,10 +36,6 @@ module RuboCop
34
36
 
35
37
  private
36
38
 
37
- def code_length(node)
38
- node.source.lines[1..-2].count { |line| !irrelevant_line(line) }
39
- end
40
-
41
39
  def field_is_defined?(node)
42
40
  node.parent
43
41
  .children
@@ -33,7 +33,7 @@ module RuboCop
33
33
 
34
34
  # @!method field_description(node)
35
35
  def_node_matcher :field_description, <<~PATTERN
36
- (send nil? :field _ _ (:str $_) ...)
36
+ (send nil? :field _ _ {(:str $_)|(:dstr $...)} ...)
37
37
  PATTERN
38
38
 
39
39
  attr_reader :node
@@ -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.0".freeze
3
+ VERSION = "1.5.2".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.0
4
+ version: 1.5.2
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-01-06 00:00:00.000000000 Z
11
+ date: 2024-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler