rubocop-graphql 0.16.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54f884b232227042a66670cda20f99b749f559dfc1429c1803c4545c0335885c
4
- data.tar.gz: 4ae6307ab827039a5dacff35d4075e123c2288752542923ea3ca2c7122658242
3
+ metadata.gz: fb4e28828d5aa07e959ad98fd9da04872c4832d1c8b1d168d440d1ad7c80762c
4
+ data.tar.gz: eaf5932cba816bfb478fac0cec298bb0e3db98b506b4f7112851503712e77068
5
5
  SHA512:
6
- metadata.gz: 0c00f215519826a44d044a1cf6f87aa6402c179213a7c8650632a73cf45871ee4daf31f0b9c1a6d203448b0e3259687085612521242f314287f683ca51cc5137
7
- data.tar.gz: df7fc7edf61e5a66adb94ab131da35625ef4106cdef87cdd3859e1d63604fadda1725b8f0284f80e47bf2f2300395876b91a7637aea746ce83dc191a107961a8
6
+ metadata.gz: cf88847a0b7a49cd1274b30fcff4e4e5ecb47b16f11a7d5e3fddcbcd7985a8d43bb8911080064a23e8d444daab330327f8908355a2ad75b2a94b14f2f4a4b2c8
7
+ data.tar.gz: a10cf2b637bc06a65338af84928c53ced64c78e634470a7fe988e4bf7a7037cfcd3035895914b99056fa11abc272c328d9be40da6ee608f33c900490dea0504d
data/config/default.yml CHANGED
@@ -73,6 +73,8 @@ GraphQL/ExtractInputType:
73
73
  VersionAdded: '0.80'
74
74
  Description: 'Suggests using input type instead of many arguments'
75
75
  MaxArguments: 2
76
+ Include:
77
+ - 'graphql/mutations/**/*.rb'
76
78
 
77
79
  GraphQL/ExtractType:
78
80
  Enabled: true
@@ -99,6 +101,7 @@ GraphQL/ObjectDescription:
99
101
  Exclude:
100
102
  - '**/*_schema.rb'
101
103
  - '**/base_*.rb'
104
+ - '**/graphql/query_context.rb'
102
105
 
103
106
  GraphQL/OrderedArguments:
104
107
  Enabled: true
@@ -113,3 +116,15 @@ GraphQL/OrderedFields:
113
116
  GraphQL/UnusedArgument:
114
117
  Enabled: true
115
118
  Description: 'Arguments should either be listed explicitly or **rest should be in the resolve signature'
119
+
120
+ GraphQL/UnnecessaryFieldAlias:
121
+ Enabled: true
122
+ Description: 'Field aliases should be different than their field names'
123
+
124
+ GraphQL/UnnecessaryArgumentCamelize:
125
+ Enabled: true
126
+ Description: "Camelize isn't necessary if the argument name doesn't contain underscores"
127
+
128
+ GraphQL/UnnecessaryFieldCamelize:
129
+ Enabled: true
130
+ Description: "Camelize isn't necessary if the field name doesn't contain underscores"
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module GraphQL
6
+ # This cop checks if each argument has an unnecessary camelize.
7
+ #
8
+ # @example
9
+ # # good
10
+ #
11
+ # class UserType < BaseType
12
+ # field :name, String, "Name of the user", null: true do
13
+ # argument :filter, String, required: false, camelize: false
14
+ # end
15
+ # end
16
+ #
17
+ # # good
18
+ #
19
+ # class UserType < BaseType
20
+ # argument :filter, String, required: false, camelize: false
21
+ # end
22
+ #
23
+ # # bad
24
+ #
25
+ # class UserType < BaseType
26
+ # argument :filter, String, required: false, camelize: false
27
+ # end
28
+ #
29
+ # # bad
30
+ #
31
+ # class UserType < BaseType
32
+ # field :name, String, "Name of the user", null: true do
33
+ # argument :filter, String, required: false, camelize: true
34
+ # end
35
+ # end
36
+ #
37
+ class UnnecessaryArgumentCamelize < Base
38
+ include RuboCop::GraphQL::NodePattern
39
+
40
+ MSG = "Unnecessary argument camelize"
41
+
42
+ def on_send(node)
43
+ return unless argument?(node)
44
+
45
+ argument = RuboCop::GraphQL::Argument.new(node)
46
+
47
+ if argument.name.to_s.split("_").length < 2 && !argument.kwargs.camelize.nil?
48
+ add_offense(node)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module GraphQL
6
+ # This cop checks if a field has an unnecessary alias.
7
+ #
8
+ # @example
9
+ # # good
10
+ #
11
+ # class UserType < BaseType
12
+ # field :name, String, "Name of the user", null: true, alias: :real_name
13
+ # end
14
+ #
15
+ # # bad
16
+ #
17
+ # class UserType < BaseType
18
+ # field :name, "Name of the user" String, null: true, alias: :name
19
+ # end
20
+ #
21
+ class UnnecessaryFieldAlias < Base
22
+ include RuboCop::GraphQL::NodePattern
23
+
24
+ MSG = "Unnecessary field alias"
25
+
26
+ def on_send(node)
27
+ return unless field_definition?(node)
28
+
29
+ field = RuboCop::GraphQL::Field.new(node)
30
+
31
+ add_offense(node) if field.name == field.kwargs.alias
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module GraphQL
6
+ # This cop checks if each field has an unnecessary camelize.
7
+ #
8
+ # @example
9
+ # # good
10
+ #
11
+ # class UserType < BaseType
12
+ # field :name, String, "Name of the user", null: true
13
+ # end
14
+ #
15
+ # # bad
16
+ #
17
+ # class UserType < BaseType
18
+ # field :name, "Name of the user", String, null: true, camelize: true
19
+ # end
20
+ #
21
+ class UnnecessaryFieldCamelize < Base
22
+ include RuboCop::GraphQL::NodePattern
23
+
24
+ MSG = "Unnecessary field camelize"
25
+
26
+ def on_send(node)
27
+ return unless field_definition?(node)
28
+
29
+ field = RuboCop::GraphQL::Field.new(node)
30
+
31
+ add_offense(node) if field.name.to_s.split("_").length < 2 && !field.kwargs.camelize.nil?
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -18,3 +18,6 @@ require_relative "graphql/object_description"
18
18
  require_relative "graphql/ordered_arguments"
19
19
  require_relative "graphql/ordered_fields"
20
20
  require_relative "graphql/unused_argument"
21
+ require_relative "graphql/unnecessary_argument_camelize"
22
+ require_relative "graphql/unnecessary_field_alias"
23
+ require_relative "graphql/unnecessary_field_camelize"
@@ -31,6 +31,11 @@ module RuboCop
31
31
  (pair (sym :as) ...)
32
32
  PATTERN
33
33
 
34
+ # @!method camelize_kwarg?(node)
35
+ def_node_matcher :camelize_kwarg?, <<~PATTERN
36
+ (pair (sym :camelize) ...)
37
+ PATTERN
38
+
34
39
  def initialize(argument_node)
35
40
  @nodes = argument_kwargs(argument_node) || []
36
41
  end
@@ -39,6 +44,10 @@ module RuboCop
39
44
  @nodes.find { |kwarg| description_kwarg?(kwarg) }
40
45
  end
41
46
 
47
+ def camelize
48
+ @nodes.find { |kwarg| camelize_kwarg?(kwarg) }
49
+ end
50
+
42
51
  def loads
43
52
  @nodes.find { |kwarg| loads_kwarg?(kwarg) }
44
53
  end
@@ -26,6 +26,11 @@ module RuboCop
26
26
  (pair (sym :method) ...)
27
27
  PATTERN
28
28
 
29
+ # @!method alias_kwarg(node)
30
+ def_node_matcher :alias_kwarg, <<~PATTERN
31
+ (pair (sym :alias) (sym $ _))
32
+ PATTERN
33
+
29
34
  # @!method hash_key_kwarg?(node)
30
35
  def_node_matcher :hash_key_kwarg?, <<~PATTERN
31
36
  (pair (sym :hash_key) ...)
@@ -41,6 +46,11 @@ module RuboCop
41
46
  (pair (sym :resolver_method) (sym $...))
42
47
  PATTERN
43
48
 
49
+ # @!method camelize_kwarg?(node)
50
+ def_node_matcher :camelize_kwarg?, <<~PATTERN
51
+ (pair (sym :camelize) ...)
52
+ PATTERN
53
+
44
54
  def initialize(field_node)
45
55
  @nodes = field_kwargs(field_node) || []
46
56
  end
@@ -53,6 +63,14 @@ module RuboCop
53
63
  @nodes.find { |kwarg| method_kwarg?(kwarg) }
54
64
  end
55
65
 
66
+ def alias
67
+ @alias ||= @nodes.map { |kwarg| alias_kwarg(kwarg) }.compact.first
68
+ end
69
+
70
+ def camelize
71
+ @nodes.find { |kwarg| camelize_kwarg?(kwarg) }
72
+ end
73
+
56
74
  def hash_key
57
75
  @nodes.find { |kwarg| hash_key_kwarg?(kwarg) }
58
76
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "0.16.0".freeze
3
+ VERSION = "0.18.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: 0.16.0
4
+ version: 0.18.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: 2022-10-24 00:00:00.000000000 Z
11
+ date: 2022-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,9 @@ files:
101
101
  - lib/rubocop/cop/graphql/ordered_arguments.rb
102
102
  - lib/rubocop/cop/graphql/ordered_fields.rb
103
103
  - lib/rubocop/cop/graphql/resolver_method_length.rb
104
+ - lib/rubocop/cop/graphql/unnecessary_argument_camelize.rb
105
+ - lib/rubocop/cop/graphql/unnecessary_field_alias.rb
106
+ - lib/rubocop/cop/graphql/unnecessary_field_camelize.rb
104
107
  - lib/rubocop/cop/graphql/unused_argument.rb
105
108
  - lib/rubocop/cop/graphql_cops.rb
106
109
  - lib/rubocop/graphql.rb