betterlint 1.32.0 → 1.33.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: 255b819071945ceaf2a26dd9897a310a52a04bb79c67a06b87195257938e5812
4
- data.tar.gz: d1b308edd9873869d15a079934dd04ac9cf0d883909cea13eacec04b582eecbd
3
+ metadata.gz: cb783d5bf833bd5560b05f745bf105b7c1292856b7339879e13e0bdae50ef815
4
+ data.tar.gz: e68389653c5f622ddae9c717a232864741287f4bbc5bc2f434417f149d35be52
5
5
  SHA512:
6
- metadata.gz: a253ddffc5c77897adf1d17dc59e684b702dfdc6329adb7f5acaf8b75d2b4e6d70cf6775e1728113f88bca797dc1e73003f1eace2acb5dbdff9a9b5d55baf388
7
- data.tar.gz: 7b26e11e5d09c6b5a5d823c02225a81c15c196630781e220b968e0f11ad23930622702e2d731b28b5b0f7758c305463bde614813c81cb274cfb2179200b86521
6
+ metadata.gz: 3e9768cd5a18d704506627e16c396cf824c20b2a8c03112450004c841161936ba68c4f01163af52c252a6a4ad387fe414937635223d35e8316ae8fb1e8cc492d
7
+ data.tar.gz: d0107fca6468fa69a7719ebb3cc52e085e30003e733a4a4c2001756844886f4d5addc3bed778e625954a3e2d81cce14a6a95eb593aef63d715889554bd40873b
data/README.md CHANGED
@@ -504,3 +504,27 @@ record.attributes.fetch(attribute_name)
504
504
  ```
505
505
 
506
506
  This cop ignores files in `spec/`, and calls to `send` with no arguments, which are usually a different method named `send`.
507
+
508
+ ### Betterment/GraphqlResolverFieldType
509
+
510
+ This cop requires type information (the type and `null:`) to be declared on the resolver, not on a field that uses it. When a field sets `resolver:`, `mutation:`, or `subscription:`, graphql-ruby uses the field's own type and nullability over the ones declared in the resolver class, so declaring them on the field silently replaces the resolver's.
511
+
512
+ ```ruby
513
+ # BAD - the field's type overrides the resolver's
514
+ field :full_name, String, resolver: Resolvers::FullName
515
+ field :full_name, type: String, resolver: Resolvers::FullName
516
+ field :full_name, resolver: Resolvers::FullName, null: false
517
+
518
+ # GOOD
519
+ field :full_name, resolver: Resolvers::FullName
520
+
521
+ module Resolvers
522
+ class FullName < BaseResolver
523
+ type String, null: false
524
+ end
525
+ end
526
+ ```
527
+
528
+ To fix an offense, move the type and `null:` to the resolver rather than deleting them from the field. A resolver is nullable unless it declares `null false`, so deleting `null: false` from the field changes the schema. This is also why the cop has no autocorrect.
529
+
530
+ This cop is disabled by default, so that applications can enable it and add existing offenses to their `.rubocop_todo.yml` at the same time.
data/config/default.yml CHANGED
@@ -51,6 +51,11 @@ Betterment/EnvironmentConfiguration:
51
51
  - app/**/*.rb
52
52
  - lib/**/*.rb
53
53
 
54
+ Betterment/GraphqlResolverFieldType:
55
+ Description: Requires type information to live on the resolver, not on a field that uses it.
56
+ Enabled: false
57
+ StyleGuide: '#bettermentgraphqlresolverfieldtype'
58
+
54
59
  Betterment/HardcodedID:
55
60
  AutoCorrect: false
56
61
  Description: Detects hardcoded IDs in specs
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterlint
4
- VERSION = '1.32.0'
4
+ VERSION = '1.33.0'
5
5
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Betterment
6
+ class GraphqlResolverFieldType < Base
7
+ MSG = 'Declare the type and `null:` on the resolver class, not on a field that uses it.'
8
+ RESTRICT_ON_SEND = %i(field).freeze
9
+ RESOLVER_OPTIONS = %i(resolver mutation subscription).freeze
10
+ TYPE_OPTIONS = %i(type null).freeze
11
+
12
+ def on_send(node)
13
+ return unless field_with_resolver?(node)
14
+
15
+ type_argument = positional_type(node)
16
+ add_offense(type_argument) if type_argument
17
+
18
+ type_options(node).each { |option| add_offense(option) }
19
+ end
20
+ alias on_csend on_send
21
+
22
+ private
23
+
24
+ def field_with_resolver?(node)
25
+ node.receiver.nil? && any_option?(node, *RESOLVER_OPTIONS)
26
+ end
27
+
28
+ def positional_type(node)
29
+ argument = node.arguments[1]
30
+ return if argument.nil? || argument.hash_type?
31
+ return if description?(node, argument)
32
+
33
+ argument
34
+ end
35
+
36
+ # With `resolver:` or `mutation:` (not `subscription:`), graphql-ruby reads `field :x, "Some text", ...` as a description
37
+ def description?(node, argument)
38
+ argument.type?(:str, :dstr) &&
39
+ node.arguments.size == 3 &&
40
+ any_option?(node, :resolver, :mutation)
41
+ end
42
+
43
+ def type_options(node)
44
+ option_pairs(node).select { |pair| TYPE_OPTIONS.include?(pair.key.value) }
45
+ end
46
+
47
+ def any_option?(node, *names)
48
+ option_pairs(node).any? { |pair| names.include?(pair.key.value) }
49
+ end
50
+
51
+ def option_pairs(node)
52
+ options = node.last_argument
53
+ return [] unless options&.hash_type?
54
+
55
+ options.pairs.select { |pair| pair.key.sym_type? }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -8,6 +8,7 @@ require 'rubocop/cop/betterment/direct_delayed_enqueue'
8
8
  require 'rubocop/cop/betterment/dynamic_params'
9
9
  require 'rubocop/cop/betterment/environment_configuration'
10
10
  require 'rubocop/cop/betterment/fetch_boolean'
11
+ require 'rubocop/cop/betterment/graphql_resolver_field_type'
11
12
  require 'rubocop/cop/betterment/hardcoded_id'
12
13
  require 'rubocop/cop/betterment/implicit_redirect_type'
13
14
  require 'rubocop/cop/betterment/internals_protection'
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.0
4
+ version: 1.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Development
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-12-03 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: lint_roller
@@ -175,6 +176,7 @@ files:
175
176
  - lib/rubocop/cop/betterment/dynamic_params.rb
176
177
  - lib/rubocop/cop/betterment/environment_configuration.rb
177
178
  - lib/rubocop/cop/betterment/fetch_boolean.rb
179
+ - lib/rubocop/cop/betterment/graphql_resolver_field_type.rb
178
180
  - lib/rubocop/cop/betterment/hardcoded_id.rb
179
181
  - lib/rubocop/cop/betterment/implicit_redirect_type.rb
180
182
  - lib/rubocop/cop/betterment/internals_protection.rb
@@ -206,12 +208,13 @@ licenses:
206
208
  - MIT
207
209
  metadata:
208
210
  homepage_uri: https://github.com/Betterment/betterlint
209
- source_code_uri: https://github.com/Betterment/betterlint/tree/v1.32.0
210
- changelog_uri: https://github.com/Betterment/betterlint/blob/v1.32.0/CHANGELOG.md
211
+ source_code_uri: https://github.com/Betterment/betterlint/tree/v1.33.0
212
+ changelog_uri: https://github.com/Betterment/betterlint/blob/v1.33.0/CHANGELOG.md
211
213
  bug_tracker_uri: https://github.com/Betterment/betterlint/issues
212
- documentation_uri: https://www.rubydoc.info/gems/betterlint/1.32.0
214
+ documentation_uri: https://www.rubydoc.info/gems/betterlint/1.33.0
213
215
  rubygems_mfa_required: 'true'
214
216
  default_lint_roller_plugin: Betterlint::Plugin
217
+ post_install_message:
215
218
  rdoc_options: []
216
219
  require_paths:
217
220
  - lib
@@ -226,7 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
229
  - !ruby/object:Gem::Version
227
230
  version: '0'
228
231
  requirements: []
229
- rubygems_version: 4.0.21
232
+ rubygems_version: 3.5.22
233
+ signing_key:
230
234
  specification_version: 4
231
235
  summary: Betterment rubocop configuration
232
236
  test_files: []