rubocop-graphql 0.4.0 → 0.4.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: 5be7099abfc014351e097467d9dfe7c687d4a0323241f7ce592e0abe25f6b0cb
4
- data.tar.gz: da4e69f7810f416873d3f3f0742b70758a3c66c343bbd0d2572c223605156c77
3
+ metadata.gz: 67638fefeb268ea870db034bc46363245b644ec8df5f620878e8e1c90b681975
4
+ data.tar.gz: b378c1830557ccbf00b7be144b6ac6141c7246e60b848d91b14a5cc8eee86a2a
5
5
  SHA512:
6
- metadata.gz: ea0737a86c403dbd57b5777c221ce80ec86e97c6fce499d00f573ef7adeb15f37e2db7b2c8f6275ff7aa58e1a17b12472a748cdf06f26c0411cb9943075386fd
7
- data.tar.gz: c0b0235d1035b9b77ffaaac3ee419b4e240c9eb7363033f37f9396a028930e33f6d11d3145f95c708e68a0b2f7566de0e1cf96264619eb1da0c3626e99304a0b
6
+ metadata.gz: e9dbfcab7cdb4820b9ab7d1a9425bb1378bcc279aebb82116058398f9b66b97d90c6af5edf38dd0c94d079f57395ffc7055936e00d89ec98c72e606b4c4d955a
7
+ data.tar.gz: 0dd262d908e7de3cbb2fc8b57aab421a7e32214f42322c1bdeab03f43b96072e349e2d0165158df123e78cf0700b9bebc95acb4876a7b5ba655c0fa44eb566f6
@@ -12,8 +12,7 @@ module RuboCop
12
12
  # class will invoke the inherited hook instead
13
13
  class << self
14
14
  undef inherited
15
- def inherited(*)
16
- end
15
+ def inherited(*); end
17
16
  end
18
17
 
19
18
  # Special case `Module#<` so that the rspec support rubocop exports
@@ -45,7 +45,8 @@ module RuboCop
45
45
 
46
46
  private
47
47
 
48
- MSG = "Consider moving %<field_names>s to a new type and adding the `%<prefix>s` field instead"
48
+ MSG = "Consider moving %<field_names>s to a new type and " \
49
+ "adding the `%<prefix>s` field instead"
49
50
 
50
51
  def check_fields_prefixes(body)
51
52
  sorted_prefixes = fractured(body).sort_by { |k, _| k.size }.reverse
@@ -105,9 +105,9 @@ module RuboCop
105
105
  def group_field_declarations(corrector, node)
106
106
  field = RuboCop::GraphQL::Field.new(node)
107
107
 
108
- first_field = field.schema_member.body.find { |node|
108
+ first_field = field.schema_member.body.find do |node|
109
109
  field_definition?(node) || field_definition_with_body?(node)
110
- }
110
+ end
111
111
 
112
112
  source_to_insert = "\n" + indent(node) + node.source
113
113
  corrector.insert_after(first_field.loc.expression, source_to_insert)
@@ -124,11 +124,12 @@ module RuboCop
124
124
  method_definition = field.schema_member.find_method_definition(field.resolver_method_name)
125
125
  return unless method_definition
126
126
 
127
- field_sibling_index = if field_definition_with_body?(field.parent)
128
- field.parent.sibling_index
129
- else
130
- field.sibling_index
131
- end
127
+ field_sibling_index =
128
+ if field_definition_with_body?(field.parent)
129
+ field.parent.sibling_index
130
+ else
131
+ field.sibling_index
132
+ end
132
133
 
133
134
  return if method_definition.sibling_index - field_sibling_index == 1
134
135
 
@@ -146,7 +147,9 @@ module RuboCop
146
147
  method_range = range_by_whole_lines(method_definition.loc.expression)
147
148
  corrector.insert_before(method_range, source_to_insert)
148
149
 
149
- range_to_remove = range_with_surrounding_space(range: field_definition.loc.expression, side: :left)
150
+ range_to_remove = range_with_surrounding_space(
151
+ range: field_definition.loc.expression, side: :left
152
+ )
150
153
  corrector.remove(range_to_remove)
151
154
  end
152
155
 
@@ -57,9 +57,14 @@ module RuboCop
57
57
  method_definition = resolver_method_definition_for(field)
58
58
  suggested_hash_key_name = hash_key_to_use(method_definition)
59
59
 
60
- corrector.insert_after(node.loc.expression, ", hash_key: #{suggested_hash_key_name.inspect}")
60
+ corrector.insert_after(
61
+ node.loc.expression, ", hash_key: #{suggested_hash_key_name.inspect}"
62
+ )
63
+
64
+ range = range_with_surrounding_space(
65
+ range: method_definition.loc.expression, side: :left
66
+ )
61
67
 
62
- range = range_with_surrounding_space(range: method_definition.loc.expression, side: :left)
63
68
  corrector.remove(range)
64
69
  end
65
70
  end
@@ -58,7 +58,9 @@ module RuboCop
58
58
 
59
59
  corrector.insert_after(node.loc.expression, ", method: :#{suggested_method_name}")
60
60
 
61
- range = range_with_surrounding_space(range: method_definition.loc.expression, side: :left)
61
+ range = range_with_surrounding_space(
62
+ range: method_definition.loc.expression, side: :left
63
+ )
62
64
  corrector.remove(range)
63
65
  end
64
66
  end
@@ -3,7 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # This cop checks if a type (object, input, interface, scalar, union, mutation, subscription, and resolver) has a description.
6
+ # This cop checks if a type (object, input, interface, scalar, union,
7
+ # mutation, subscription, and resolver) has a description.
7
8
  #
8
9
  # @example
9
10
  # # good
@@ -45,7 +46,9 @@ module RuboCop
45
46
  def on_module(node)
46
47
  return if child_nodes(node).none? { |child_node| interface?(child_node) }
47
48
 
48
- add_offense(node.identifier) if child_nodes(node).none? { |child_node| has_description?(child_node) }
49
+ if child_nodes(node).none? { |child_node| has_description?(child_node) }
50
+ add_offense(node.identifier)
51
+ end
49
52
  end
50
53
 
51
54
  private
@@ -9,9 +9,9 @@ module RuboCop
9
9
  # The maximum allowed length is configurable using the Max option.
10
10
  class ResolverMethodLength < Cop
11
11
  include RuboCop::Cop::ConfigurableMax
12
- include RuboCop::Cop::TooManyLines
12
+ include RuboCop::Cop::CodeLength
13
13
 
14
- LABEL = "ResolverMethod"
14
+ MSG = "ResolverMethod has too many lines. [%<total>d/%<max>d]"
15
15
 
16
16
  def_node_matcher :field_definition, <<~PATTERN
17
17
  (send nil? :field (sym $...) ...)
@@ -21,18 +21,31 @@ module RuboCop
21
21
  excluded_methods = cop_config["ExcludedMethods"]
22
22
  return if excluded_methods.include?(String(node.method_name))
23
23
 
24
- check_code_length(node) if field_is_defined?(node)
24
+ if field_is_defined?(node)
25
+ length = code_length(node)
26
+
27
+ return unless length > max_length
28
+
29
+ add_offense(node, message: message(length))
30
+ end
25
31
  end
26
32
  alias on_defs on_def
27
33
 
28
34
  private
29
35
 
36
+ def code_length(node)
37
+ node.source.lines[1..-2].count { |line| !irrelevant_line(line) }
38
+ end
39
+
30
40
  def field_is_defined?(node)
31
- node.parent.children.flat_map { |child| field_definition(child) }.include?(node.method_name)
41
+ node.parent
42
+ .children
43
+ .flat_map { |child| field_definition(child) }
44
+ .include?(node.method_name)
32
45
  end
33
46
 
34
- def cop_label
35
- LABEL
47
+ def message(length)
48
+ format(MSG, total: length, max: max_length)
36
49
  end
37
50
  end
38
51
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module GraphQL
5
5
  module Ext
6
6
  module SnakeCase
7
- SNAKE_CASE = /^[\da-z_]+[!?=]?$/
7
+ SNAKE_CASE = /^[\da-z_]+[!?=]?$/.freeze
8
8
 
9
9
  refine Symbol do
10
10
  def snake_case?
@@ -56,7 +56,8 @@ module RuboCop
56
56
  end
57
57
 
58
58
  def resolver_method_name
59
- @resolver_method_name ||= @nodes.flat_map { |kwarg| resolver_method_option(kwarg) }.compact.first
59
+ @resolver_method_name ||=
60
+ @nodes.flat_map { |kwarg| resolver_method_option(kwarg) }.compact.first
60
61
  end
61
62
  end
62
63
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.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.4.0
4
+ version: 0.4.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: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2020-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,33 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: standard
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: '3.9'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: '3.9'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.71.0
61
+ version: '0.87'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.71.0
68
+ version: '0.87'
69
69
  description: A collection of RuboCop cops to improve GraphQL-related code
70
70
  email:
71
71
  - dmitry.a.tsepelev@gmail.com
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: '2.4'
121
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - ">="