rubocop-graphql 1.1.1 → 1.2.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 +2 -0
- data/lib/rubocop/cop/graphql/field_hash_key.rb +1 -1
- data/lib/rubocop/cop/graphql/field_method.rb +1 -1
- data/lib/rubocop/cop/graphql/ordered_arguments.rb +2 -1
- data/lib/rubocop/cop/graphql/ordered_fields.rb +2 -1
- data/lib/rubocop/cop/graphql/unnecessary_field_alias.rb +8 -1
- data/lib/rubocop/graphql/compare_order.rb +51 -0
- data/lib/rubocop/graphql/ext/snake_case.rb +1 -1
- data/lib/rubocop/graphql/version.rb +1 -1
- data/lib/rubocop-graphql.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e3cd9f39f4d6349f89ae259d9ea98569ce58680600319f5c5e9e846b789653
|
4
|
+
data.tar.gz: e1f1cf02c677f0de30913b18c60ae8dfee94e537e8dc5d70d31b291d6bb67767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2823101dc6985bac70575d7ef73e9d600c47491759b128f1a9af47f5ac47148cbb5d3163150bfb34a97eb7dfca71c9b2498f11c0fa9ec08ee31e56d066f35f38
|
7
|
+
data.tar.gz: 6f468a9a2c4e5c630a7b8d8bee2f7575efead50bf3365980f347359a3a14174b81d8dbf5ada3c48b5cc407a005fa745b1b2d02c97a07135aac8b67e295be11e2
|
data/config/default.yml
CHANGED
@@ -141,12 +141,14 @@ GraphQL/OrderedArguments:
|
|
141
141
|
Enabled: true
|
142
142
|
VersionAdded: '0.7.0'
|
143
143
|
Description: 'Arguments should be alphabetically sorted within groups'
|
144
|
+
Order: null
|
144
145
|
|
145
146
|
GraphQL/OrderedFields:
|
146
147
|
Enabled: true
|
147
148
|
VersionAdded: '0.5.0'
|
148
149
|
Description: 'Fields should be alphabetically sorted within groups'
|
149
150
|
Groups: true
|
151
|
+
Order: null
|
150
152
|
|
151
153
|
GraphQL/UnusedArgument:
|
152
154
|
Enabled: true
|
@@ -74,7 +74,7 @@ module RuboCop
|
|
74
74
|
suggested_hash_key_name = hash_key_to_use(method_definition)
|
75
75
|
|
76
76
|
corrector.insert_after(
|
77
|
-
node
|
77
|
+
node, ", hash_key: #{suggested_hash_key_name.inspect}"
|
78
78
|
)
|
79
79
|
|
80
80
|
range = range_with_surrounding_space(
|
@@ -68,7 +68,7 @@ module RuboCop
|
|
68
68
|
method_definition = suggest_method_name_for(field)
|
69
69
|
suggested_method_name = method_to_use(method_definition)
|
70
70
|
|
71
|
-
corrector.insert_after(node
|
71
|
+
corrector.insert_after(node, ", method: :#{suggested_method_name}")
|
72
72
|
|
73
73
|
range = range_with_surrounding_space(
|
74
74
|
range: method_definition.source_range, side: :left
|
@@ -52,6 +52,7 @@ module RuboCop
|
|
52
52
|
extend AutoCorrector
|
53
53
|
|
54
54
|
include RuboCop::GraphQL::SwapRange
|
55
|
+
include RuboCop::GraphQL::CompareOrder
|
55
56
|
|
56
57
|
MSG = "Arguments should be sorted in an alphabetical order within their section. " \
|
57
58
|
"Field `%<current>s` should appear before `%<previous>s`."
|
@@ -71,7 +72,7 @@ module RuboCop
|
|
71
72
|
|
72
73
|
argument_declarations.each_cons(2) do |previous, current|
|
73
74
|
next unless consecutive_lines(previous, current)
|
74
|
-
next if argument_name(
|
75
|
+
next if correct_order?(argument_name(previous), argument_name(current))
|
75
76
|
|
76
77
|
register_offense(previous, current)
|
77
78
|
end
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
extend AutoCorrector
|
35
35
|
|
36
36
|
include RuboCop::GraphQL::SwapRange
|
37
|
+
include RuboCop::GraphQL::CompareOrder
|
37
38
|
|
38
39
|
MSG = "Fields should be sorted in an alphabetical order within their "\
|
39
40
|
"section. "\
|
@@ -51,7 +52,7 @@ module RuboCop
|
|
51
52
|
def on_class(node)
|
52
53
|
field_declarations(node).each_cons(2) do |previous, current|
|
53
54
|
next unless consecutive_fields(previous, current)
|
54
|
-
next if field_name(
|
55
|
+
next if correct_order?(field_name(previous), field_name(current))
|
55
56
|
|
56
57
|
register_offense(previous, current)
|
57
58
|
end
|
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
# field :name, String, "Name of the user", null: true, hash_key: :name
|
22
22
|
#
|
23
23
|
class UnnecessaryFieldAlias < Base
|
24
|
+
extend AutoCorrector
|
24
25
|
include RuboCop::GraphQL::NodePattern
|
25
26
|
|
26
27
|
MSG = "Unnecessary :%<kwarg>s configured"
|
@@ -32,7 +33,13 @@ module RuboCop
|
|
32
33
|
|
33
34
|
if (unnecessary_kwarg = validate_kwargs(field))
|
34
35
|
message = format(self.class::MSG, kwarg: unnecessary_kwarg)
|
35
|
-
add_offense(node, message: message)
|
36
|
+
add_offense(node, message: message) do |corrector|
|
37
|
+
kwarg_node = node.arguments.last.pairs.find do |pair|
|
38
|
+
pair.key.value == unnecessary_kwarg.to_sym
|
39
|
+
end
|
40
|
+
corrector.remove_preceding(kwarg_node, 2)
|
41
|
+
corrector.remove(kwarg_node)
|
42
|
+
end
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module GraphQL
|
5
|
+
module CompareOrder
|
6
|
+
def correct_order?(previous, current)
|
7
|
+
# If Order config is provided, we should use it to determine the order
|
8
|
+
# Else, we should use alphabetical order
|
9
|
+
# e.g. "Order" => [
|
10
|
+
# "id",
|
11
|
+
# "/^id_.*$/",
|
12
|
+
# "/^.*_id$/",
|
13
|
+
# "everything-else",
|
14
|
+
# "/^(created|updated)_at$/"
|
15
|
+
# ]
|
16
|
+
if (order = cop_config["Order"])
|
17
|
+
# For each of previous and current, we should find the first matching order,
|
18
|
+
# checking 'everything-else' last
|
19
|
+
# If the order is the same, we should use alphabetical order
|
20
|
+
# If the order is different, we should use the order
|
21
|
+
previous_order = order_index(previous, order)
|
22
|
+
current_order = order_index(current, order)
|
23
|
+
|
24
|
+
if previous_order == current_order
|
25
|
+
previous <= current
|
26
|
+
else
|
27
|
+
previous_order < current_order
|
28
|
+
end
|
29
|
+
else
|
30
|
+
previous <= current
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def order_index(field, order)
|
35
|
+
everything_else_index = order.length
|
36
|
+
|
37
|
+
order.each_with_index do |order_item, index|
|
38
|
+
if order_item == "everything-else"
|
39
|
+
everything_else_index = index
|
40
|
+
elsif order_item.start_with?("/") && order_item.end_with?("/") # is regex-like?
|
41
|
+
return index if field.match?(order_item[1..-2])
|
42
|
+
elsif field == order_item
|
43
|
+
return index
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
everything_else_index
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/rubocop-graphql.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative "rubocop/graphql/ext/snake_case"
|
|
7
7
|
require_relative "rubocop/graphql"
|
8
8
|
require_relative "rubocop/graphql/version"
|
9
9
|
require_relative "rubocop/graphql/inject"
|
10
|
+
require_relative "rubocop/graphql/compare_order"
|
10
11
|
require_relative "rubocop/graphql/description_method"
|
11
12
|
require_relative "rubocop/graphql/heredoc"
|
12
13
|
require_relative "rubocop/graphql/node_pattern"
|
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: 1.
|
4
|
+
version: 1.2.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: 2023-
|
11
|
+
date: 2023-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/rubocop/graphql/argument/block.rb
|
116
116
|
- lib/rubocop/graphql/argument/kwargs.rb
|
117
117
|
- lib/rubocop/graphql/class.rb
|
118
|
+
- lib/rubocop/graphql/compare_order.rb
|
118
119
|
- lib/rubocop/graphql/description_method.rb
|
119
120
|
- lib/rubocop/graphql/ext/snake_case.rb
|
120
121
|
- lib/rubocop/graphql/field.rb
|
@@ -143,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
144
|
requirements:
|
144
145
|
- - ">="
|
145
146
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
147
|
+
version: '3.0'
|
147
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
149
|
requirements:
|
149
150
|
- - ">="
|