rubocop-graphql 1.0.1 → 1.1.0

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: a7531302386361a75baf74bcb65e70041bf5b414fb55151c1bcb6eb9e40bbb92
4
- data.tar.gz: 43943f69aacfebc7ea8060af236796c499b671ac8825853a77961105bc57afe5
3
+ metadata.gz: 93b15c7311147740481d59f94cab5e62ca4317ada9ec0e21254ec785b5dfd683
4
+ data.tar.gz: 9157944e4d8a28635389fe2b1472c48361001a5674fb1c81ebd0dec4447b44d0
5
5
  SHA512:
6
- metadata.gz: e67d5bba4243ca1e4122af69449871465e9e8124574d0a379e2125f4e0b13ce05a6d48f0c44f129ad8fbcc3fb4af692bb5e366ce4fa9d1b8c125d276d1f17e53
7
- data.tar.gz: c6020f17e1828c0fe135e7ca398c36b8ed322ff9daf86d3616ade152b8391e213565a6b1a5c1b185a436c0f2b9d68c805135c39973f18e0fbb0e58d4ccab3895
6
+ metadata.gz: 9cd372736e4f994645dfaf72289ce5933a9e739f5ef179096326574b5da79d6c872ee01097232666d2549d8bd5f9c762dc3af0de6b66ce905a2a3d37814a3c9c
7
+ data.tar.gz: 181fd6b02b1bb4e20fc64f60e39ceb94073ce178be18b6d1bc6177e4d62cf933e2f6bd5ef4e23b4b8aa163a22ccd641ca4727647054f24bcce2882e390bfddd5
@@ -3,32 +3,48 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GraphQL
6
- # This cop checks if a field has an unnecessary alias.
6
+ # This cop prevents defining an unnecessary alias, method, or resolver_method.
7
7
  #
8
8
  # @example
9
9
  # # good
10
10
  #
11
- # class UserType < BaseType
12
- # field :name, String, "Name of the user", null: true, alias: :real_name
13
- # end
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
- # class UserType < BaseType
18
- # field :name, "Name of the user" String, null: true, alias: :name
19
- # end
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 field alias"
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
- add_offense(node) if field.name == field.kwargs.alias
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
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "1.0.1".freeze
3
+ VERSION = "1.1.0".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: 1.0.1
4
+ version: 1.1.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-03-13 00:00:00.000000000 Z
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler