rubocop-graphql 0.14.3 → 0.14.6

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: c1aef8d25bbcf29e3aac8dd31b10b16341f88a0e27d71a04290ee4c265686db4
4
- data.tar.gz: 1f8e8a06d5f7c7b1a301c45672634b98fbd748b1904b7e8639bf7377b82d4654
3
+ metadata.gz: a7832bf74fe37877eee6544f83cc7625cfa874df93f6b141c07a2c1a628a927f
4
+ data.tar.gz: c764f2caaf3cbbb685eb944b1a206c4904a484fe000f39a41c40b33846eecc1b
5
5
  SHA512:
6
- metadata.gz: 050f68792f4b7b042994e3bcb9cc9aef1d5d42dc548d91ec7799b7d83211adc4efee756510cdf18c282d99e11e589a4bea1566a1ee2605944da927a7ff10463d
7
- data.tar.gz: 8ed14cde041d5d10f58f0e0ad9a8fee1c6a73f80e0d5c947af82fba6a5f70b7c72269e585f195f9123cea1a5bc0bebe37969d65e81dd55e49ce60fc89ab36fae
6
+ metadata.gz: 9bdb7f16d1b31c795e8d624030e774c3c92ebb1481e4459f229fe135557eb072dbe2920c1cfc2600bb0d768756b338846da6db1b396def061d95ad4d0628e5b0
7
+ data.tar.gz: d506eade963151227cfa3bf55f7ddf320b281111083ac784807c7c6aa6534a0899a01474d2c80f35c2460d1817b18f033d05ce880be59f477b5fe75cf85ce0e8
data/config/default.yml CHANGED
@@ -77,6 +77,7 @@ GraphQL/ExtractType:
77
77
  MaxFields: 2
78
78
  Prefixes:
79
79
  - is
80
+ - has
80
81
  - with
81
82
  - avg
82
83
  - min
@@ -108,5 +109,3 @@ GraphQL/OrderedFields:
108
109
  GraphQL/UnusedArgument:
109
110
  Enabled: true
110
111
  Description: 'Arguments should either be listed explicitly or **rest should be in the resolve signature'
111
-
112
-
@@ -80,7 +80,7 @@ module RuboCop
80
80
 
81
81
  is_field_block = node.block_type? &&
82
82
  node.respond_to?(:method_name) &&
83
- node.method_name == :field
83
+ node.method?(:field)
84
84
 
85
85
  return field_name(node.parent) unless is_field_block
86
86
 
@@ -93,6 +93,7 @@ module RuboCop
93
93
  "`#{first_argument.value}`"
94
94
  end
95
95
 
96
+ # @!method argument_declarations(node)
96
97
  def_node_search :argument_declarations, <<~PATTERN
97
98
  (send nil? :argument (:sym _) ...)
98
99
  PATTERN
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
6
  class ExtractInputType < Base
7
- # This cop checks fields on common prefix groups
7
+ # Checks fields on common prefix groups
8
8
  #
9
9
  # # @example
10
10
  # # good
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
6
  class ExtractType < Base
7
- # This cop checks fields on common prefix groups
7
+ # Checks fields on common prefix groups
8
8
  #
9
9
  # # @example
10
10
  # # good
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # This cop checks consistency of field definitions
6
+ # Checks consistency of field definitions
7
7
  #
8
8
  # EnforcedStyle supports two modes:
9
9
  #
@@ -52,6 +52,7 @@ module RuboCop
52
52
  include RuboCop::GraphQL::Sorbet
53
53
  include RuboCop::GraphQL::Heredoc
54
54
 
55
+ # @!method field_kwargs(node)
55
56
  def_node_matcher :field_kwargs, <<~PATTERN
56
57
  (send nil? :field
57
58
  ...
@@ -28,6 +28,7 @@ module RuboCop
28
28
  include RuboCop::GraphQL::NodePattern
29
29
  include RuboCop::Cop::RangeHelp
30
30
 
31
+ # @!method hash_key_to_use(node)
31
32
  def_node_matcher :hash_key_to_use, <<~PATTERN
32
33
  (def
33
34
  _
@@ -50,7 +51,7 @@ module RuboCop
50
51
  suggested_hash_key_name = hash_key_to_use(method_definition)
51
52
 
52
53
  return if suggested_hash_key_name.nil?
53
- return if RuboCop::GraphQL::Field::CONFLICT_FIELD_NAMES.include?(suggested_hash_key_name)
54
+ return if conflict?(suggested_hash_key_name)
54
55
 
55
56
  add_offense(node, message: message(suggested_hash_key_name)) do |corrector|
56
57
  autocorrect(corrector, node)
@@ -59,6 +60,10 @@ module RuboCop
59
60
 
60
61
  private
61
62
 
63
+ def conflict?(suggested_hash_key_name)
64
+ RuboCop::GraphQL::Field::CONFLICT_FIELD_NAMES.include?(suggested_hash_key_name.to_sym)
65
+ end
66
+
62
67
  def message(hash_key)
63
68
  format(MSG, hash_key: hash_key)
64
69
  end
@@ -28,6 +28,7 @@ module RuboCop
28
28
  include RuboCop::GraphQL::NodePattern
29
29
  include RuboCop::Cop::RangeHelp
30
30
 
31
+ # @!method method_to_use(node)
31
32
  def_node_matcher :method_to_use, <<~PATTERN
32
33
  (def
33
34
  _
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # This cop detects duplicate field definitions within
6
+ # Detects duplicate field definitions within
7
7
  # the same type
8
8
  #
9
9
  # @example
@@ -66,6 +66,7 @@ module RuboCop
66
66
  node.first_argument.value.to_s
67
67
  end
68
68
 
69
+ # @!method field_declarations(node)
69
70
  def_node_search :field_declarations, <<~PATTERN
70
71
  {
71
72
  (send nil? :field (:sym _) ...)
@@ -20,6 +20,7 @@ module RuboCop
20
20
  #
21
21
  module GraphQL
22
22
  class LegacyDsl < Base
23
+ # @!method legacy_dsl?(node)
23
24
  def_node_matcher :legacy_dsl?, <<~PATTERN
24
25
  (block
25
26
  (send
@@ -29,10 +30,11 @@ module RuboCop
29
30
  )
30
31
  PATTERN
31
32
 
32
- MSG = "Avoid using legacy based type-based definitions. Use class-based defintions instead."
33
+ MSG = "Avoid using legacy based type-based definitions. " \
34
+ "Use class-based definitions instead."
33
35
 
34
36
  def on_send(node)
35
- return unless node.parent.type == :block
37
+ return unless node.parent.block_type?
36
38
 
37
39
  add_offense(node.parent) if legacy_dsl?(node.parent)
38
40
  end
@@ -26,10 +26,12 @@ module RuboCop
26
26
 
27
27
  MSG = "Missing type description"
28
28
 
29
+ # @!method has_i18n_description?(node)
29
30
  def_node_matcher :has_i18n_description?, <<~PATTERN
30
31
  (send nil? :description (send (const nil? :I18n) :t ...))
31
32
  PATTERN
32
33
 
34
+ # @!method interface?(node)
33
35
  def_node_matcher :interface?, <<~PATTERN
34
36
  (send nil? :include (const ...))
35
37
  PATTERN
@@ -101,10 +101,12 @@ module RuboCop
101
101
  previous.source_range.last_line == current.source_range.first_line - 1
102
102
  end
103
103
 
104
+ # @!method argument_declarations_without_blocks(node)
104
105
  def_node_search :argument_declarations_without_blocks, <<~PATTERN
105
106
  (send nil? :argument (:sym _) ...)
106
107
  PATTERN
107
108
 
109
+ # @!method argument_declarations_with_blocks(node)
108
110
  def_node_search :argument_declarations_with_blocks, <<~PATTERN
109
111
  (block
110
112
  (send nil? :argument
@@ -74,6 +74,7 @@ module RuboCop
74
74
  previous.source_range.last_line == current.source_range.first_line - 1
75
75
  end
76
76
 
77
+ # @!method field_declarations(node)
77
78
  def_node_search :field_declarations, <<~PATTERN
78
79
  {
79
80
  (send nil? :field (:sym _) ...)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # This cop checks if the length of a resolver method exceeds some maximum value.
6
+ # Checks if the length of a resolver method exceeds some maximum value.
7
7
  # Comment lines can optionally be ignored.
8
8
  #
9
9
  # The maximum allowed length is configurable using the Max option.
@@ -13,6 +13,7 @@ module RuboCop
13
13
 
14
14
  MSG = "ResolverMethod has too many lines. [%<total>d/%<max>d]"
15
15
 
16
+ # @!method field_definition(node)
16
17
  def_node_matcher :field_definition, <<~PATTERN
17
18
  (send nil? :field (sym $...) ...)
18
19
  PATTERN
@@ -79,9 +79,14 @@ module RuboCop
79
79
  private
80
80
 
81
81
  def find_declared_arg_nodes(node)
82
- argument_declarations(node).select do |arg_declaration|
83
- # argument is declared on the same class that is being analyzed
84
- arg_declaration.each_ancestor(:class).first == node
82
+ node.each_child_node.flat_map do |child|
83
+ if scoped_node?(child)
84
+ []
85
+ elsif argument_declaration?(child)
86
+ [child]
87
+ else
88
+ find_declared_arg_nodes(child)
89
+ end
85
90
  end
86
91
  end
87
92
 
@@ -158,10 +163,24 @@ module RuboCop
158
163
  declared_arg.name
159
164
  end
160
165
 
161
- def_node_search :argument_declarations, <<~PATTERN
166
+ def scoped_node?(node)
167
+ scope_changing_syntax?(node) || block_or_lambda?(node)
168
+ end
169
+
170
+ def scope_changing_syntax?(node)
171
+ node.def_type? || node.defs_type? || node.class_type? || node.module_type?
172
+ end
173
+
174
+ def block_or_lambda?(node)
175
+ node.block_type? || node.lambda_type?
176
+ end
177
+
178
+ # @!method argument_declaration?(node)
179
+ def_node_matcher :argument_declaration?, <<~PATTERN
162
180
  (send nil? :argument (:sym _) ...)
163
181
  PATTERN
164
182
 
183
+ # @!method resolve_method_definition(node)
165
184
  def_node_search :resolve_method_definition, <<~PATTERN
166
185
  (def :resolve
167
186
  (args ...) ...)
@@ -7,6 +7,7 @@ module RuboCop
7
7
  extend RuboCop::NodePattern::Macros
8
8
  include DescriptionMethod
9
9
 
10
+ # @!method argument_block(node)
10
11
  def_node_matcher :argument_block, <<~PATTERN
11
12
  (block
12
13
  (send nil? :argument ...)
@@ -6,6 +6,7 @@ module RuboCop
6
6
  class Kwargs
7
7
  extend RuboCop::NodePattern::Macros
8
8
 
9
+ # @!method argument_kwargs(node)
9
10
  def_node_matcher :argument_kwargs, <<~PATTERN
10
11
  (send nil? :argument
11
12
  ...
@@ -15,14 +16,17 @@ module RuboCop
15
16
  )
16
17
  PATTERN
17
18
 
19
+ # @!method description_kwarg?(node)
18
20
  def_node_matcher :description_kwarg?, <<~PATTERN
19
21
  (pair (sym :description) ...)
20
22
  PATTERN
21
23
 
24
+ # @!method loads_kwarg?(node)
22
25
  def_node_matcher :loads_kwarg?, <<~PATTERN
23
26
  (pair (sym :loads) ...)
24
27
  PATTERN
25
28
 
29
+ # @!method as_kwarg?(node)
26
30
  def_node_matcher :as_kwarg?, <<~PATTERN
27
31
  (pair (sym :as) ...)
28
32
  PATTERN
@@ -5,14 +5,17 @@ module RuboCop
5
5
  class Argument
6
6
  extend RuboCop::NodePattern::Macros
7
7
 
8
+ # @!method argument_description(node)
8
9
  def_node_matcher :argument_description, <<~PATTERN
9
10
  (send nil? :argument _ _ (:str $_) ...)
10
11
  PATTERN
11
12
 
13
+ # @!method argument_name(node)
12
14
  def_node_matcher :argument_name, <<~PATTERN
13
15
  (send nil? :argument (:sym $_) ...)
14
16
  PATTERN
15
17
 
18
+ # @!method argument_as(node)
16
19
  def_node_matcher :argument_as, <<~PATTERN
17
20
  (pair (sym :as) (sym $_))
18
21
  PATTERN
@@ -22,10 +22,12 @@ module RuboCop
22
22
 
23
23
  DESCRIPTION_STRING = "{({str|dstr|const} ...)|(send const ...)|(send ({str|dstr} ...) _)}"
24
24
 
25
+ # @!method description_method_call?(node)
25
26
  def_node_matcher :description_method_call?, <<~PATTERN
26
27
  (send nil? :description #{DESCRIPTION_STRING})
27
28
  PATTERN
28
29
 
30
+ # @!method description_with_block_arg?(node)
29
31
  def_node_matcher :description_with_block_arg?, <<~PATTERN
30
32
  (send (lvar _) {:description= :description} #{DESCRIPTION_STRING})
31
33
  PATTERN
@@ -7,6 +7,7 @@ module RuboCop
7
7
  extend RuboCop::NodePattern::Macros
8
8
  include DescriptionMethod
9
9
 
10
+ # @!method field_block(node)
10
11
  def_node_matcher :field_block, <<~PATTERN
11
12
  (block
12
13
  (send nil? :field ...)
@@ -6,6 +6,7 @@ module RuboCop
6
6
  class Kwargs
7
7
  extend RuboCop::NodePattern::Macros
8
8
 
9
+ # @!method field_kwargs(node)
9
10
  def_node_matcher :field_kwargs, <<~PATTERN
10
11
  (send nil? :field
11
12
  ...
@@ -15,22 +16,27 @@ module RuboCop
15
16
  )
16
17
  PATTERN
17
18
 
19
+ # @!method resolver_kwarg?(node)
18
20
  def_node_matcher :resolver_kwarg?, <<~PATTERN
19
21
  (pair (sym :resolver) ...)
20
22
  PATTERN
21
23
 
24
+ # @!method method_kwarg?(node)
22
25
  def_node_matcher :method_kwarg?, <<~PATTERN
23
26
  (pair (sym :method) ...)
24
27
  PATTERN
25
28
 
29
+ # @!method hash_key_kwarg?(node)
26
30
  def_node_matcher :hash_key_kwarg?, <<~PATTERN
27
31
  (pair (sym :hash_key) ...)
28
32
  PATTERN
29
33
 
34
+ # @!method description_kwarg?(node)
30
35
  def_node_matcher :description_kwarg?, <<~PATTERN
31
36
  (pair (sym :description) ...)
32
37
  PATTERN
33
38
 
39
+ # @!method resolver_method_option(node)
34
40
  def_node_matcher :resolver_method_option, <<~PATTERN
35
41
  (pair (sym :resolver_method) (sym $...))
36
42
  PATTERN
@@ -20,15 +20,18 @@ module RuboCop
20
20
 
21
21
  def_delegators :@node, :sibling_index, :parent
22
22
 
23
+ # @!method field_name(node)
23
24
  def_node_matcher :field_name, <<~PATTERN
24
25
  (send nil? :field (:sym $_) ...)
25
26
  PATTERN
26
27
 
28
+ # @!method field_with_body_name(node)
27
29
  def_node_matcher :field_with_body_name, <<~PATTERN
28
30
  (block
29
31
  (send nil? :field (:sym $_) ...)...)
30
32
  PATTERN
31
33
 
34
+ # @!method field_description(node)
32
35
  def_node_matcher :field_description, <<~PATTERN
33
36
  (send nil? :field _ _ (:str $_) ...)
34
37
  PATTERN
@@ -5,10 +5,12 @@ module RuboCop
5
5
  module NodePattern
6
6
  extend RuboCop::NodePattern::Macros
7
7
 
8
+ # @!method field_definition?(node)
8
9
  def_node_matcher :field_definition?, <<~PATTERN
9
10
  (send nil? :field (:sym _) ...)
10
11
  PATTERN
11
12
 
13
+ # @!method field_definition_with_body?(node)
12
14
  def_node_matcher :field_definition_with_body?, <<~PATTERN
13
15
  (block
14
16
  (send nil? :field (:sym _) ...)
@@ -16,6 +18,7 @@ module RuboCop
16
18
  )
17
19
  PATTERN
18
20
 
21
+ # @!method argument?(node)
19
22
  def_node_matcher :argument?, <<~PATTERN
20
23
  (send nil? :argument (:sym _) ...)
21
24
  PATTERN
@@ -5,6 +5,7 @@ module RuboCop
5
5
  class SchemaMember
6
6
  extend RuboCop::NodePattern::Macros
7
7
 
8
+ # @!method class_contents(node)
8
9
  def_node_matcher :class_contents, <<~PATTERN
9
10
  (class _ _ $_)
10
11
  PATTERN
@@ -16,7 +17,7 @@ module RuboCop
16
17
  end
17
18
 
18
19
  def find_method_definition(method_name)
19
- body.find { |node| node.def_type? && node.method_name == method_name }
20
+ body.find { |node| node.def_type? && node.method?(method_name) }
20
21
  end
21
22
 
22
23
  def body
@@ -5,6 +5,7 @@ module RuboCop
5
5
  module Sorbet
6
6
  extend RuboCop::NodePattern::Macros
7
7
 
8
+ # @!method sorbet_signature(node)
8
9
  def_node_matcher(:sorbet_signature, <<~PATTERN)
9
10
  (block (send nil? :sig) (args) ...)
10
11
  PATTERN
@@ -3,22 +3,22 @@
3
3
  module RuboCop
4
4
  module GraphQL
5
5
  module SwapRange
6
+ include RuboCop::Cop::RangeHelp
7
+
6
8
  def swap_range(corrector, current, previous)
7
9
  current_range = declaration(current)
8
10
  previous_range = declaration(previous)
9
11
 
10
- src1 = current_range.source
11
- src2 = previous_range.source
12
-
13
- corrector.replace(current_range, src2)
14
- corrector.replace(previous_range, src1)
12
+ corrector.insert_before(previous_range, current_range.source)
13
+ corrector.remove(current_range)
15
14
  end
16
15
 
17
16
  def declaration(node)
18
17
  buffer = processed_source.buffer
19
- begin_pos = node.source_range.begin_pos
18
+ begin_pos = range_by_whole_lines(node.source_range).begin_pos
20
19
  end_line = buffer.line_for_position(node.loc.expression.end_pos)
21
- end_pos = buffer.line_range(end_line).end_pos
20
+ end_pos = range_by_whole_lines(buffer.line_range(end_line),
21
+ include_final_newline: true).end_pos
22
22
  Parser::Source::Range.new(buffer, begin_pos, end_pos)
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.14.3".freeze
3
+ VERSION = "0.14.6".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.14.3
4
+ version: 0.14.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Tsepelev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -127,7 +127,7 @@ metadata:
127
127
  homepage_uri: https://github.com/DmitryTsepelev/rubocop-graphql
128
128
  source_code_uri: https://github.com/DmitryTsepelev/rubocop-graphql
129
129
  changelog_uri: https://github.com/DmitryTsepelev/rubocop-graphql/blob/master/CHANGELOG.md
130
- post_install_message:
130
+ post_install_message:
131
131
  rdoc_options: []
132
132
  require_paths:
133
133
  - lib
@@ -142,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.2.33
146
- signing_key:
145
+ rubygems_version: 3.1.6
146
+ signing_key:
147
147
  specification_version: 4
148
148
  summary: Automatic performance checking tool for Ruby code.
149
149
  test_files: []