rubocop-graphql 0.14.2 → 0.14.5

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: d8c5edb3e37ffc8245916608bb37f79dc28afb39dde464477e5b31e7f92aef59
4
- data.tar.gz: 3fc868fb4e1ee8cdb0fed44c35ae98899e83eb605e0618faba161f65344554b4
3
+ metadata.gz: 5c4b8fdbb39f5e0bea2bbcce54cdd520480f1e412a2b3c5ce549b7c37a5e2cbb
4
+ data.tar.gz: 5e6065465cad8df870476977d0b9e4ac64869c27a4247570c5d6d6d56bb32577
5
5
  SHA512:
6
- metadata.gz: 96f21cb69d2a7fc4c5c084e4859756fc7f525fc29e5c7c2dd4bf5fb1233d039ff3932d5783cdd10f91b0cee15c5cc8c91e94e3fec2f07ee0d09fdbc4b32e2799
7
- data.tar.gz: c88d409a7c67630c3f68d98fb6d78418be4c3c99d601470f9732ed456b4ee86f3f2439323c019b82eaa52f2b613aa01fdf14cc195304eb3fc0a7c6bb3bec6774
6
+ metadata.gz: 267c257092e56d804772fa9f58e0e657151348758d80b7b453b07c00e0aa33651b61f326424822f2fcc272dacff45a245820c3a9eea8bbe00e344ed6ff17bc83
7
+ data.tar.gz: badf0bbcdefc806c43cdc60defadf002cfc645dfb6c2f6bf6609b444c18cd9c13bb81b4a4c48eebf3ae25ffbdaf477678d6807349133866098736387d483df90
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
@@ -59,7 +59,7 @@ module RuboCop
59
59
 
60
60
  def register_offense(current)
61
61
  current_field_name = field_name(current)
62
- field_name_message = " in field `#{current_field_name}`" if current_field_name
62
+ field_name_message = " in field #{current_field_name}" if current_field_name
63
63
 
64
64
  message = format(
65
65
  self.class::MSG,
@@ -81,9 +81,16 @@ module RuboCop
81
81
  is_field_block = node.block_type? &&
82
82
  node.respond_to?(:method_name) &&
83
83
  node.method_name == :field
84
- return node.send_node.first_argument.value.to_s if is_field_block
85
84
 
86
- field_name(node.parent)
85
+ return field_name(node.parent) unless is_field_block
86
+
87
+ first_argument = node.send_node.first_argument
88
+ if first_argument.lvar_type?
89
+ variable_name = first_argument.children.first
90
+ return "with name from `#{variable_name}` variable"
91
+ end
92
+
93
+ "`#{first_argument.value}`"
87
94
  end
88
95
 
89
96
  def_node_search :argument_declarations, <<~PATTERN
@@ -29,7 +29,8 @@ module RuboCop
29
29
  )
30
30
  PATTERN
31
31
 
32
- MSG = "Avoid using legacy based type-based definitions. Use class-based defintions instead."
32
+ MSG = "Avoid using legacy based type-based definitions. " \
33
+ "Use class-based definitions instead."
33
34
 
34
35
  def on_send(node)
35
36
  return unless node.parent.type == :block
@@ -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,7 +163,19 @@ 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
+ def_node_matcher :argument_declaration?, <<~PATTERN
162
179
  (send nil? :argument (:sym _) ...)
163
180
  PATTERN
164
181
 
@@ -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.2".freeze
3
+ VERSION = "0.14.5".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.2
4
+ version: 0.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Tsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-26 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,7 +142,7 @@ 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.15
145
+ rubygems_version: 3.3.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Automatic performance checking tool for Ruby code.