rubocop-graphql 1.0.1 → 1.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bcabdbafaf927896c569183254a11c60352414d91978553dcc12449cc45b46c
|
4
|
+
data.tar.gz: b9edc6b4444b21ecde01fceffbb027489aa59241886ba1f6e09f1488ae73a0f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02fbc1b2402f0661737a188a5aa107376210ba30ca52d1461da8e5ba7312ef2c548d3485ea2630194422e4379368f4efd595b0ac2c6affdc4432939344c7f956
|
7
|
+
data.tar.gz: 6472b601c9ba130fe97eac98d556a4f9113884e95290c8c751d321c123d1ff54ac31396d7fc53885001c55a62a3e66941547a4dd5f761af5e72a7a1b46f74a2c
|
@@ -3,32 +3,48 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module GraphQL
|
6
|
-
# This cop
|
6
|
+
# This cop prevents defining an unnecessary alias, method, or resolver_method.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# # good
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
11
|
+
# field :name, String, "Name of the user", null: true, alias: :real_name
|
12
|
+
# field :name, String, "Name of the user", null: true, method: :real_name
|
13
|
+
# field :name, String, "Name of the user", null: true, resolver_method: :real_name
|
14
|
+
# field :name, String, "Name of the user", null: true, hash_key: :real_name
|
14
15
|
#
|
15
16
|
# # bad
|
16
17
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
18
|
+
# field :name, "Name of the user" String, null: true, alias: :name
|
19
|
+
# field :name, String, "Name of the user", null: true, method: :name
|
20
|
+
# field :name, String, "Name of the user", null: true, resolver_method: :name
|
21
|
+
# field :name, String, "Name of the user", null: true, hash_key: :name
|
20
22
|
#
|
21
23
|
class UnnecessaryFieldAlias < Base
|
22
24
|
include RuboCop::GraphQL::NodePattern
|
23
25
|
|
24
|
-
MSG = "Unnecessary
|
26
|
+
MSG = "Unnecessary :%<kwarg>s configured"
|
25
27
|
|
26
28
|
def on_send(node)
|
27
29
|
return unless field_definition?(node)
|
28
30
|
|
29
31
|
field = RuboCop::GraphQL::Field.new(node)
|
30
32
|
|
31
|
-
|
33
|
+
if (unnecessary_kwarg = validate_kwargs(field))
|
34
|
+
message = format(self.class::MSG, kwarg: unnecessary_kwarg)
|
35
|
+
add_offense(node, message: message)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def validate_kwargs(field) # rubocop:disable Metrics/CyclomaticComplexity
|
42
|
+
case field.name
|
43
|
+
when field.kwargs.alias then "alias"
|
44
|
+
when field.kwargs.method&.value&.value then "method"
|
45
|
+
when field.kwargs.resolver_method_name then "resolver_method"
|
46
|
+
when field.kwargs.hash_key&.value&.value then "hash_key"
|
47
|
+
end
|
32
48
|
end
|
33
49
|
end
|
34
50
|
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: 1.
|
4
|
+
version: 1.1.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: 2023-03-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|