rubocop-graphql 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/graphql/argument_uniqueness.rb +4 -10
- data/lib/rubocop/cop/graphql/field_uniqueness.rb +4 -10
- data/lib/rubocop/cop/graphql/unused_argument.rb +4 -5
- data/lib/rubocop/graphql/class.rb +17 -0
- data/lib/rubocop/graphql/node_uniqueness.rb +16 -0
- data/lib/rubocop/graphql/version.rb +1 -1
- data/lib/rubocop-graphql.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d488e2bcf0fac1f61555afb433e26834bc653b88598ba9fd23d58be29db44cc
|
4
|
+
data.tar.gz: 31afb3a28f7cd44f165dcd4bd93aecebf270ccc2af05f50816f171f19c88680d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5d35e978439e99de72eb4d90088b6a726bfbf78a6303ce422bfb09a05b4d965e7a28acb06ada12538dea8148f691384a48682ad651cc39d631e779d41098cfb
|
7
|
+
data.tar.gz: 44ca6c9891b4184b6ab40b1a4be8d9398fb94276502a603f09639bf5993c553aee01f845e61a119470f1a7eb5f51659db7114bf47a472c41394649b91fc20c28
|
@@ -20,11 +20,13 @@ module RuboCop
|
|
20
20
|
# end
|
21
21
|
#
|
22
22
|
class ArgumentUniqueness < Base
|
23
|
+
include RuboCop::GraphQL::NodeUniqueness
|
24
|
+
|
23
25
|
MSG = "Argument names should only be defined once per block. "\
|
24
26
|
"Argument `%<current>s` is duplicated%<field_name>s."
|
25
27
|
|
26
28
|
def on_class(node)
|
27
|
-
return if
|
29
|
+
return if ::RuboCop::GraphQL::Class.new(node).nested?
|
28
30
|
|
29
31
|
# { "MyClassName" => { "test_field" => <Set: {"field_arg_name"}> } }
|
30
32
|
argument_names_by_field_by_class = Hash.new do |h, k|
|
@@ -36,7 +38,7 @@ module RuboCop
|
|
36
38
|
argument_declarations(node).each do |current|
|
37
39
|
current_field_name = field_name(current)
|
38
40
|
current_argument_name = argument_name(current)
|
39
|
-
class_name =
|
41
|
+
class_name = current_class_full_name(current)
|
40
42
|
|
41
43
|
argument_names = if current_field_name
|
42
44
|
argument_names_by_field_by_class[class_name][current_field_name]
|
@@ -55,14 +57,6 @@ module RuboCop
|
|
55
57
|
|
56
58
|
private
|
57
59
|
|
58
|
-
def current_class_name(node)
|
59
|
-
node.each_ancestor(:class).first.defined_module_name
|
60
|
-
end
|
61
|
-
|
62
|
-
def nested_class?(node)
|
63
|
-
node.each_ancestor(:class).any?
|
64
|
-
end
|
65
|
-
|
66
60
|
def register_offense(current)
|
67
61
|
current_field_name = field_name(current)
|
68
62
|
field_name_message = " in field `#{current_field_name}`" if current_field_name
|
@@ -27,16 +27,18 @@ module RuboCop
|
|
27
27
|
# end
|
28
28
|
#
|
29
29
|
class FieldUniqueness < Base
|
30
|
+
include RuboCop::GraphQL::NodeUniqueness
|
31
|
+
|
30
32
|
MSG = "Field names should only be defined once per type. "\
|
31
33
|
"Field `%<current>s` is duplicated."
|
32
34
|
|
33
35
|
def on_class(node)
|
34
|
-
return if
|
36
|
+
return if ::RuboCop::GraphQL::Class.new(node).nested?
|
35
37
|
|
36
38
|
field_names_by_class = Hash.new { |h, k| h[k] = Set.new }
|
37
39
|
|
38
40
|
field_declarations(node).each do |current|
|
39
|
-
current_class =
|
41
|
+
current_class = current_class_full_name(current)
|
40
42
|
field_names = field_names_by_class[current_class]
|
41
43
|
current_field_name = field_name(current)
|
42
44
|
|
@@ -51,10 +53,6 @@ module RuboCop
|
|
51
53
|
|
52
54
|
private
|
53
55
|
|
54
|
-
def nested_class?(node)
|
55
|
-
node.each_ancestor(:class).any?
|
56
|
-
end
|
57
|
-
|
58
56
|
def register_offense(current)
|
59
57
|
message = format(
|
60
58
|
self.class::MSG,
|
@@ -68,10 +66,6 @@ module RuboCop
|
|
68
66
|
node.first_argument.value.to_s
|
69
67
|
end
|
70
68
|
|
71
|
-
def current_class_name(node)
|
72
|
-
node.each_ancestor(:class).first.defined_module_name
|
73
|
-
end
|
74
|
-
|
75
69
|
def_node_search :field_declarations, <<~PATTERN
|
76
70
|
{
|
77
71
|
(send nil? :field (:sym _) ...)
|
@@ -139,11 +139,10 @@ module RuboCop
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def arg_name(declared_arg)
|
142
|
-
if declared_arg.kwargs.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
142
|
+
return declared_arg.as if declared_arg.kwargs.as
|
143
|
+
return inferred_arg_name(declared_arg.name.to_s) if declared_arg.kwargs.loads
|
144
|
+
|
145
|
+
declared_arg.name
|
147
146
|
end
|
148
147
|
|
149
148
|
def_node_search :argument_declarations, <<~PATTERN
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
# Shared methods to check duplicated definitions
|
6
|
+
module NodeUniqueness
|
7
|
+
def current_class_full_name(node)
|
8
|
+
node.each_ancestor(:class).map(&:defined_module_name).join("::")
|
9
|
+
end
|
10
|
+
|
11
|
+
def nested_class?(node)
|
12
|
+
node.each_ancestor(:class).any?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/rubocop-graphql.rb
CHANGED
@@ -9,11 +9,13 @@ require_relative "rubocop/graphql/version"
|
|
9
9
|
require_relative "rubocop/graphql/inject"
|
10
10
|
require_relative "rubocop/graphql/description_method"
|
11
11
|
require_relative "rubocop/graphql/node_pattern"
|
12
|
+
require_relative "rubocop/graphql/node_uniqueness"
|
12
13
|
require_relative "rubocop/graphql/swap_range"
|
13
14
|
|
14
15
|
require_relative "rubocop/graphql/argument"
|
15
16
|
require_relative "rubocop/graphql/argument/block"
|
16
17
|
require_relative "rubocop/graphql/argument/kwargs"
|
18
|
+
require_relative "rubocop/graphql/class"
|
17
19
|
require_relative "rubocop/graphql/field"
|
18
20
|
require_relative "rubocop/graphql/field/block"
|
19
21
|
require_relative "rubocop/graphql/field/kwargs"
|
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.12.
|
4
|
+
version: 0.12.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: 2022-01-
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/rubocop/graphql/argument.rb
|
107
107
|
- lib/rubocop/graphql/argument/block.rb
|
108
108
|
- lib/rubocop/graphql/argument/kwargs.rb
|
109
|
+
- lib/rubocop/graphql/class.rb
|
109
110
|
- lib/rubocop/graphql/description_method.rb
|
110
111
|
- lib/rubocop/graphql/ext/snake_case.rb
|
111
112
|
- lib/rubocop/graphql/field.rb
|
@@ -113,6 +114,7 @@ files:
|
|
113
114
|
- lib/rubocop/graphql/field/kwargs.rb
|
114
115
|
- lib/rubocop/graphql/inject.rb
|
115
116
|
- lib/rubocop/graphql/node_pattern.rb
|
117
|
+
- lib/rubocop/graphql/node_uniqueness.rb
|
116
118
|
- lib/rubocop/graphql/schema_member.rb
|
117
119
|
- lib/rubocop/graphql/swap_range.rb
|
118
120
|
- lib/rubocop/graphql/version.rb
|