rubocop-graphql 1.2.0 → 1.3.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: 95e3cd9f39f4d6349f89ae259d9ea98569ce58680600319f5c5e9e846b789653
4
- data.tar.gz: e1f1cf02c677f0de30913b18c60ae8dfee94e537e8dc5d70d31b291d6bb67767
3
+ metadata.gz: 9cdf5152e0106f86e952fbf5a24a38011914f34b0167a19ef0cf53dd810e4d68
4
+ data.tar.gz: 9ed0ac94bdc4f323543e1085a612dfb3d02f5e60ee55892da6894b202718865e
5
5
  SHA512:
6
- metadata.gz: 2823101dc6985bac70575d7ef73e9d600c47491759b128f1a9af47f5ac47148cbb5d3163150bfb34a97eb7dfca71c9b2498f11c0fa9ec08ee31e56d066f35f38
7
- data.tar.gz: 6f468a9a2c4e5c630a7b8d8bee2f7575efead50bf3365980f347359a3a14174b81d8dbf5ada3c48b5cc407a005fa745b1b2d02c97a07135aac8b67e295be11e2
6
+ metadata.gz: 992563e33d74e91766b4917a541ef9361795156f93eb33a95f0944e4968f87a5845681adff07178a30cd11b10c6b2e10ea002e2688b2a501cc6b9e25bb1bc103
7
+ data.tar.gz: 2cf037f19ca63a512ea00a06601cf49dcc46ed5bb59deec1ede2e45dcd74acfd875b7febf7f703b36354fa4059dd222ca5f37fb59a11572c7cc8d4ffb97389a9
data/config/default.yml CHANGED
@@ -119,6 +119,7 @@ GraphQL/NotAuthorizedNodeType:
119
119
  Description: 'Detects types that implement Node interface and not have `.authorized?` check'
120
120
  Include:
121
121
  - '**/graphql/types/**/*'
122
+ SafeBaseClasses: []
122
123
 
123
124
  GraphQL/ResolverMethodLength:
124
125
  Enabled: true
@@ -51,6 +51,7 @@ module RuboCop
51
51
 
52
52
  return if suggested_method_name.nil?
53
53
  return if RuboCop::GraphQL::Field::CONFLICT_FIELD_NAMES.include?(suggested_method_name)
54
+ return if method_kwarg_set?(field)
54
55
 
55
56
  add_offense(node, message: message(suggested_method_name)) do |corrector|
56
57
  autocorrect(corrector, node)
@@ -80,6 +81,10 @@ module RuboCop
80
81
  method_name = field.resolver_method_name
81
82
  field.schema_member.find_method_definition(method_name)
82
83
  end
84
+
85
+ def method_kwarg_set?(field)
86
+ field.kwargs.method != nil
87
+ end
83
88
  end
84
89
  end
85
90
  end
@@ -7,6 +7,9 @@ module RuboCop
7
7
  # Such types can be fetched by ID and therefore should have type level check to
8
8
  # avoid accidental information exposure.
9
9
  #
10
+ # If `.authorized?` is defined in a parent class, you can add parent to the "SafeBaseClasses"
11
+ # to avoid offenses in children.
12
+ #
10
13
  # @example
11
14
  # # good
12
15
  #
@@ -45,6 +48,11 @@ module RuboCop
45
48
  class NotAuthorizedNodeType < Base
46
49
  MSG = ".authorized? should be defined for types implementing Node interface."
47
50
 
51
+ # @!method class_name(node)
52
+ def_node_matcher :class_name, <<~PATTERN
53
+ (const nil? $_)
54
+ PATTERN
55
+
48
56
  # @!method implements_node_type?(node)
49
57
  def_node_matcher :implements_node_type?, <<~PATTERN
50
58
  `(send nil? :implements
@@ -60,8 +68,20 @@ module RuboCop
60
68
  PATTERN
61
69
 
62
70
  def on_class(node)
71
+ return if ignored_class?(parent_class(node))
72
+
63
73
  add_offense(node) if implements_node_type?(node) && !has_authorized_method?(node)
64
74
  end
75
+
76
+ private
77
+
78
+ def parent_class(node)
79
+ node.child_nodes[1]
80
+ end
81
+
82
+ def ignored_class?(node)
83
+ cop_config["SafeBaseClasses"].include?(String(class_name(node)))
84
+ end
65
85
  end
66
86
  end
67
87
  end
@@ -10,27 +10,33 @@ module RuboCop
10
10
  #
11
11
  # class UserType < BaseType
12
12
  # field :name, String, "Name of the user", null: true do
13
- # argument :filter, String, required: false, camelize: false
13
+ # argument :filter, String, required: false
14
14
  # end
15
15
  # end
16
16
  #
17
17
  # # good
18
18
  #
19
19
  # class UserType < BaseType
20
- # argument :filter, String, required: false, camelize: false
20
+ # argument :filter, String, required: false
21
+ # end
22
+ #
23
+ # # good
24
+ #
25
+ # class UserType < BaseType
26
+ # argument :email_filter, String, required: false, camelize: true
21
27
  # end
22
28
  #
23
29
  # # bad
24
30
  #
25
31
  # class UserType < BaseType
26
- # argument :filter, String, required: false
32
+ # argument :filter, String, required: false, camelize: false
27
33
  # end
28
34
  #
29
35
  # # bad
30
36
  #
31
37
  # class UserType < BaseType
32
38
  # field :name, String, "Name of the user", null: true do
33
- # argument :filter, String, required: false
39
+ # argument :filter, String, required: false, camelize: false
34
40
  # end
35
41
  # end
36
42
  #
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module GraphQL
3
- VERSION = "1.2.0".freeze
3
+ VERSION = "1.3.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.2.0
4
+ version: 1.3.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-05-06 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler