betterlint 1.31.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: df6ab37fcacbca2232240ecc261718b03ce8cae9d9ec6860d01b1fe5aafa15de
4
- data.tar.gz: 3c1aace8b60b77b649f621b5923f3defddb33d18922aff23211225cea7461af5
3
+ metadata.gz: cb783d5bf833bd5560b05f745bf105b7c1292856b7339879e13e0bdae50ef815
4
+ data.tar.gz: e68389653c5f622ddae9c717a232864741287f4bbc5bc2f434417f149d35be52
5
5
  SHA512:
6
- metadata.gz: 0405efeb7e9268e65ab0440399f375e482338b7008a9ffa4690cbdc0640d8f0d1e5ea5382ddf2f203f54beb517f76387386f104b0f2a20519615e9c34f3bd6fd
7
- data.tar.gz: 668fba99358e61376714517009c13e3e335e74c5576541941293c56018a851dca599edb0333160d99c27a31b192ec730149dac7cdf53045dbbac2cc24f643fba
6
+ metadata.gz: 3e9768cd5a18d704506627e16c396cf824c20b2a8c03112450004c841161936ba68c4f01163af52c252a6a4ad387fe414937635223d35e8316ae8fb1e8cc492d
7
+ data.tar.gz: d0107fca6468fa69a7719ebb3cc52e085e30003e733a4a4c2001756844886f4d5addc3bed778e625954a3e2d81cce14a6a95eb593aef63d715889554bd40873b
data/README.md CHANGED
@@ -471,6 +471,19 @@ end
471
471
 
472
472
  This cop is disabled by default, because it reports many offenses in applications with older specs. To use it, enable it in your `.rubocop.yml`. By default it examines all files in `spec/`, except for the `features`, `requests`, `routing`, `system`, and `views` directories, where integration style tests that don't test one class and method are common. Examples in shared example groups are also ignored.
473
473
 
474
+ ### Betterment/NoNotImplementedError
475
+
476
+ Ruby's [`NotImplementedError`](https://docs.ruby-lang.org/en/3.4/NotImplementedError.html) signals a feature unavailable on the current platform. It inherits from `ScriptError`, so a bare `rescue` won't catch it.
477
+ This cop flags direct references to the exception in application code, including in `raise`, `rescue`, and inheritance. It does not autocorrect, because the replacement depends on what failed.
478
+ If you need to handle a genuine platform limitation, scope the rescue to the platform call and disable the cop on that line.
479
+
480
+ The cop is disabled by default. To enable it:
481
+
482
+ ```yaml
483
+ Betterment/NoNotImplementedError:
484
+ Enabled: true
485
+ ```
486
+
474
487
  ### Betterment/NoSend
475
488
 
476
489
  This cop flags calls to `send`, `public_send`, and `__send__`. Dynamic dispatch hides the call from Sorbet and code search, and `send` also reaches private methods. Call the method directly instead.
@@ -491,3 +504,27 @@ record.attributes.fetch(attribute_name)
491
504
  ```
492
505
 
493
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
@@ -70,6 +75,11 @@ Betterment/NoDownMigrations:
70
75
  Include:
71
76
  - db/migrate/**/*.rb
72
77
 
78
+ Betterment/NoNotImplementedError:
79
+ Description: Disallows direct references to Ruby's NotImplementedError in application code.
80
+ Enabled: false
81
+ StyleGuide: '#bettermentnonotimplementederror'
82
+
73
83
  Betterment/NoSend:
74
84
  Description: Detects dynamic method calls through send, public_send and __send__.
75
85
  StyleGuide: '#bettermentnosend'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Betterlint
4
- VERSION = '1.31.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
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Betterment
6
+ class NoNotImplementedError < Base
7
+ MSG = 'Ruby reserves `NotImplementedError` for platform limitations. Use an abstract method or a specific application error.'
8
+
9
+ # @!method not_implemented_error?(node)
10
+ def_node_matcher :not_implemented_error?, '(const {nil? (cbase) (const {nil? (cbase)} :Object)} :NotImplementedError)'
11
+
12
+ def on_const(node)
13
+ add_offense(node) if not_implemented_error?(node)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,11 +8,13 @@ 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'
14
15
  require 'rubocop/cop/betterment/memoization_with_arguments'
15
16
  require 'rubocop/cop/betterment/no_down_migrations'
17
+ require 'rubocop/cop/betterment/no_not_implemented_error'
16
18
  require 'rubocop/cop/betterment/no_send'
17
19
  require 'rubocop/cop/betterment/non_namespaced_class'
18
20
  require 'rubocop/cop/betterment/non_standard_actions'
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.31.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,11 +176,13 @@ 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
181
183
  - lib/rubocop/cop/betterment/memoization_with_arguments.rb
182
184
  - lib/rubocop/cop/betterment/no_down_migrations.rb
185
+ - lib/rubocop/cop/betterment/no_not_implemented_error.rb
183
186
  - lib/rubocop/cop/betterment/no_send.rb
184
187
  - lib/rubocop/cop/betterment/non_namespaced_class.rb
185
188
  - lib/rubocop/cop/betterment/non_standard_actions.rb
@@ -205,12 +208,13 @@ licenses:
205
208
  - MIT
206
209
  metadata:
207
210
  homepage_uri: https://github.com/Betterment/betterlint
208
- source_code_uri: https://github.com/Betterment/betterlint/tree/v1.31.0
209
- changelog_uri: https://github.com/Betterment/betterlint/blob/v1.31.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
210
213
  bug_tracker_uri: https://github.com/Betterment/betterlint/issues
211
- documentation_uri: https://www.rubydoc.info/gems/betterlint/1.31.0
214
+ documentation_uri: https://www.rubydoc.info/gems/betterlint/1.33.0
212
215
  rubygems_mfa_required: 'true'
213
216
  default_lint_roller_plugin: Betterlint::Plugin
217
+ post_install_message:
214
218
  rdoc_options: []
215
219
  require_paths:
216
220
  - lib
@@ -225,7 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
229
  - !ruby/object:Gem::Version
226
230
  version: '0'
227
231
  requirements: []
228
- rubygems_version: 4.0.24
232
+ rubygems_version: 3.5.22
233
+ signing_key:
229
234
  specification_version: 4
230
235
  summary: Betterment rubocop configuration
231
236
  test_files: []