rubocop-graphql 0.10.3 → 0.11.0
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/config/default.yml +12 -0
- data/lib/rubocop/cop/graphql/argument_uniqueness.rb +87 -0
- data/lib/rubocop/cop/graphql/field_uniqueness.rb +71 -0
- data/lib/rubocop/cop/graphql/ordered_arguments.rb +1 -1
- data/lib/rubocop/cop/graphql/ordered_fields.rb +1 -1
- data/lib/rubocop/cop/graphql_cops.rb +2 -0
- data/lib/rubocop/graphql/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 695dc31bd7713d4a04c067297952afc95397caae7d713828414cf6f1d4296c75
|
4
|
+
data.tar.gz: e8aa0cb10f10e83c42750ccb8531d282cb3825b18c8cc00882cbc85396a80f8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aaa9969636a336c4fe09d12cb4513882612b1b901475abccc63c234985fc2c30d08bcc00d88e433460d7622fa50a03b6cb63ce6172ca24448fc1684d173062b
|
7
|
+
data.tar.gz: ac9b024d31903265137d1309838238de83a89bd5899ffb0740009ffb366f0c8a91d2c593f0e2e20eda4bff306ac7e1af9fd942600e25893b9ed5b022e774745e
|
data/config/default.yml
CHANGED
@@ -12,6 +12,11 @@ GraphQL/ArgumentName:
|
|
12
12
|
VersionAdded: '0.80'
|
13
13
|
Description: 'This cop checks whether argument names are snake_case'
|
14
14
|
|
15
|
+
GraphQL/ArgumentUniqueness:
|
16
|
+
Enabled: true
|
17
|
+
VersionAdded: '0.80'
|
18
|
+
Description: 'This cop enforces arguments to be defined once per block'
|
19
|
+
|
15
20
|
GraphQL/ResolverMethodLength:
|
16
21
|
Enabled: true
|
17
22
|
VersionAdded: '0.80'
|
@@ -50,6 +55,11 @@ GraphQL/FieldName:
|
|
50
55
|
Description: 'This cop checks whether field names are snake_case'
|
51
56
|
SafeAutoCorrect: false
|
52
57
|
|
58
|
+
GraphQL/FieldUniqueness:
|
59
|
+
Enabled: true
|
60
|
+
VersionAdded: '0.80'
|
61
|
+
Description: 'This cop enforces fields to be defined once'
|
62
|
+
|
53
63
|
GraphQL/ExtractInputType:
|
54
64
|
Enabled: true
|
55
65
|
VersionAdded: '0.80'
|
@@ -90,3 +100,5 @@ GraphQL/OrderedFields:
|
|
90
100
|
Enabled: true
|
91
101
|
VersionAdded: '0.80'
|
92
102
|
Description: 'Fields should be alphabetically sorted within groups'
|
103
|
+
|
104
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module GraphQL
|
6
|
+
# This cop detects duplicate argument definitions
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # good
|
10
|
+
#
|
11
|
+
# class BanUser < BaseMutation
|
12
|
+
# argument :user_id, ID, required: true
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # bad
|
16
|
+
#
|
17
|
+
# class BanUser < BaseMutation
|
18
|
+
# argument :user_id, ID, required: true
|
19
|
+
# argument :user_id, ID, required: true
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
class ArgumentUniqueness < Base
|
23
|
+
MSG = "Argument names should only be defined once per block. "\
|
24
|
+
"Argument `%<current>s` is duplicated%<field_name>s."
|
25
|
+
|
26
|
+
def on_class(node)
|
27
|
+
global_argument_names = Set.new
|
28
|
+
argument_names_by_field = {}
|
29
|
+
|
30
|
+
argument_declarations(node).each do |current|
|
31
|
+
current_field_name = field_name(current)
|
32
|
+
current_argument_name = argument_name(current)
|
33
|
+
|
34
|
+
if current_field_name
|
35
|
+
argument_names_by_field[current_field_name] ||= Set.new
|
36
|
+
argument_names = argument_names_by_field[current_field_name]
|
37
|
+
else
|
38
|
+
argument_names = global_argument_names
|
39
|
+
end
|
40
|
+
|
41
|
+
unless argument_names.include?(current_argument_name)
|
42
|
+
argument_names.add(current_argument_name)
|
43
|
+
next
|
44
|
+
end
|
45
|
+
|
46
|
+
register_offense(current)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def register_offense(current)
|
53
|
+
current_field_name = field_name(current)
|
54
|
+
field_name_message = " in field `#{current_field_name}`" if current_field_name
|
55
|
+
|
56
|
+
message = format(
|
57
|
+
self.class::MSG,
|
58
|
+
current: argument_name(current),
|
59
|
+
field_name: field_name_message
|
60
|
+
)
|
61
|
+
|
62
|
+
add_offense(current, message: message)
|
63
|
+
end
|
64
|
+
|
65
|
+
def argument_name(node)
|
66
|
+
node.first_argument.value.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
# Find parent field block, if available
|
70
|
+
def field_name(node)
|
71
|
+
return if node.nil?
|
72
|
+
|
73
|
+
is_field_block = node.block_type? &&
|
74
|
+
node.respond_to?(:method_name) &&
|
75
|
+
node.method_name == :field
|
76
|
+
return node.send_node.first_argument.value.to_s if is_field_block
|
77
|
+
|
78
|
+
field_name(node.parent)
|
79
|
+
end
|
80
|
+
|
81
|
+
def_node_search :argument_declarations, <<~PATTERN
|
82
|
+
(send nil? :argument (:sym _) ...)
|
83
|
+
PATTERN
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module GraphQL
|
6
|
+
# This cop detects duplicate field definitions within
|
7
|
+
# the same type
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# # good
|
11
|
+
#
|
12
|
+
# class UserType < BaseType
|
13
|
+
# field :name, String, null: true
|
14
|
+
# field :phone, String, null: true do
|
15
|
+
# argument :something, String, required: false
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
#
|
21
|
+
# class UserType < BaseType
|
22
|
+
# field :name, String, null: true
|
23
|
+
# field :phone, String, null: true
|
24
|
+
# field :phone, String, null: true do
|
25
|
+
# argument :something, String, required: false
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
class FieldUniqueness < Base
|
30
|
+
MSG = "Field names should only be defined once per type. "\
|
31
|
+
"Field `%<current>s` is duplicated."
|
32
|
+
|
33
|
+
def on_class(node)
|
34
|
+
field_names = Set.new
|
35
|
+
|
36
|
+
field_declarations(node).each do |current|
|
37
|
+
current_field_name = field_name(current)
|
38
|
+
|
39
|
+
unless field_names.include?(current_field_name)
|
40
|
+
field_names.add(current_field_name)
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
register_offense(current)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def register_offense(current)
|
51
|
+
message = format(
|
52
|
+
self.class::MSG,
|
53
|
+
current: field_name(current)
|
54
|
+
)
|
55
|
+
|
56
|
+
add_offense(current, message: message)
|
57
|
+
end
|
58
|
+
|
59
|
+
def field_name(node)
|
60
|
+
node.first_argument.value.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def_node_search :field_declarations, <<~PATTERN
|
64
|
+
{
|
65
|
+
(send nil? :field (:sym _) ...)
|
66
|
+
}
|
67
|
+
PATTERN
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
59
59
|
def on_class(node)
|
60
60
|
argument_declarations(node).each_cons(2) do |previous, current|
|
61
61
|
next unless consecutive_lines(previous, current)
|
62
|
-
next if argument_name(current)
|
62
|
+
next if argument_name(current) >= argument_name(previous)
|
63
63
|
|
64
64
|
register_offense(previous, current)
|
65
65
|
end
|
@@ -42,7 +42,7 @@ module RuboCop
|
|
42
42
|
def on_class(node)
|
43
43
|
field_declarations(node).each_cons(2) do |previous, current|
|
44
44
|
next unless consecutive_lines(previous, current)
|
45
|
-
next if field_name(current)
|
45
|
+
next if field_name(current) >= field_name(previous)
|
46
46
|
|
47
47
|
register_offense(previous, current)
|
48
48
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "graphql/argument_description"
|
4
4
|
require_relative "graphql/argument_name"
|
5
|
+
require_relative "graphql/argument_uniqueness"
|
5
6
|
require_relative "graphql/extract_input_type"
|
6
7
|
require_relative "graphql/extract_type"
|
7
8
|
require_relative "graphql/field_definitions"
|
@@ -9,6 +10,7 @@ require_relative "graphql/field_description"
|
|
9
10
|
require_relative "graphql/field_hash_key"
|
10
11
|
require_relative "graphql/field_method"
|
11
12
|
require_relative "graphql/field_name"
|
13
|
+
require_relative "graphql/field_uniqueness"
|
12
14
|
require_relative "graphql/legacy_dsl"
|
13
15
|
require_relative "graphql/resolver_method_length"
|
14
16
|
require_relative "graphql/object_description"
|
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
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Tsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/rubocop-graphql.rb
|
87
87
|
- lib/rubocop/cop/graphql/argument_description.rb
|
88
88
|
- lib/rubocop/cop/graphql/argument_name.rb
|
89
|
+
- lib/rubocop/cop/graphql/argument_uniqueness.rb
|
89
90
|
- lib/rubocop/cop/graphql/extract_input_type.rb
|
90
91
|
- lib/rubocop/cop/graphql/extract_type.rb
|
91
92
|
- lib/rubocop/cop/graphql/field_definitions.rb
|
@@ -93,6 +94,7 @@ files:
|
|
93
94
|
- lib/rubocop/cop/graphql/field_hash_key.rb
|
94
95
|
- lib/rubocop/cop/graphql/field_method.rb
|
95
96
|
- lib/rubocop/cop/graphql/field_name.rb
|
97
|
+
- lib/rubocop/cop/graphql/field_uniqueness.rb
|
96
98
|
- lib/rubocop/cop/graphql/legacy_dsl.rb
|
97
99
|
- lib/rubocop/cop/graphql/object_description.rb
|
98
100
|
- lib/rubocop/cop/graphql/ordered_arguments.rb
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
137
|
- !ruby/object:Gem::Version
|
136
138
|
version: '0'
|
137
139
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.2.31
|
139
141
|
signing_key:
|
140
142
|
specification_version: 4
|
141
143
|
summary: Automatic performance checking tool for Ruby code.
|