betterlint 1.20.0 → 1.22.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: a8373ada8389173714d5f6086fd98f64e056340b8ddbd6c3b7e9cb78a3143b1f
4
- data.tar.gz: bf710724c7163b0ef355cecfaad17bcf6af70c58fa50cdb81fd7d691d1e6e269
3
+ metadata.gz: abed62a3254c489777ae4372142ff0bf2a4c8201003619e5c10f0754a07f9eb8
4
+ data.tar.gz: 618bb3269cb0c584e94bd3fef3f6776b5e325e9bf63d5cfdc8737c3c3d5f33a2
5
5
  SHA512:
6
- metadata.gz: 991c3a041583443b9e53e0c3baa7ace7354b76a5a07e322d85e82f73bea4a01b7252f203ccbbac1e6947675eb20940777cc4f6df72132ba40f64aab265fbbbf3
7
- data.tar.gz: c52af40049be9780cbd719df55e3747902f5c51d7e0136340140aaecc1bab53b8a17f5ecc9f84843dc43e066a9a7df90b02ce751d46c8784d2b0f77baba6e47f
6
+ metadata.gz: 641573afe2d923b6c4a063c6ed7051792484750e8542171f9f39c499886101ef6cb1aee01790de96f2c5c16de514e063a3ede731b37b68c7afce23a13b8cd9cb
7
+ data.tar.gz: bf51c01eb160f348615a8a0ee57c3f5954e22b18547b41b93f4c54a2c6dcf6bd3b544c761c56a162e6514c49e85b285c379a0270faf234f5739ae9b905dbf1d5
data/README.md CHANGED
@@ -318,3 +318,15 @@ This allows us two benefits:
318
318
  This cop identifies associations where `:strict_loading` is set explicitly, and prefers that it be removed in favor of using the global strict loading settings.
319
319
 
320
320
  This is related to the [Betterment/UseGlobalStrictLoading/ByDefaultForModels](#bettermentuseglobalstrictloadingbydefaultformodels) cop, but allows for more granular enablement and disablement of associations within a model. The intention is similar, in that we are using this cop to help "burn down" code to strict load, but it allows us to focus on the per-association level. Some models may have quite a lot of usage, so enabling it for a model might cause thousands of failures in the specs. In those cases we will disable all the associations, and then work through them one at a time until all code that uses the model strict loads.
321
+
322
+ ### Betterment/VagueSerialize
323
+
324
+ This cop identifies calls to `serialize` that do not specify a coder either by using the positional argument or
325
+ the `coder` keyword argument.
326
+
327
+ **NOTE:** Using a positional argument is deprecated for Rails 7.1+. That means that...
328
+
329
+ - If you are on Rails 7.2
330
+ - And you've opted into 7.1 defaults (namely, `config.active_record.default_column_serializer = nil`)
331
+
332
+ ...you can safely disable this cop, since failing to pass a deserializer will raise an exception.
data/config/default.yml CHANGED
@@ -124,6 +124,13 @@ Betterment/UseGlobalStrictLoading/ForAssociations:
124
124
  FactoryBot/AssociationStyle:
125
125
  Enabled: false
126
126
 
127
+ Betterment/NotUsingRswag:
128
+ Enabled: false
129
+ SafeAutoCorrect: false
130
+ Description: Detect API specs missing OpenAPI documentation using rswag
131
+ Include:
132
+ - spec/requests/**/*_spec.rb
133
+
127
134
  FactoryBot/ConsistentParenthesesStyle:
128
135
  Enabled: false
129
136
 
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Betterment
6
+ class NotUsingRswag < Base
7
+ MSG = 'Request specs must use rswag to test and document their API endpoints. See: https://github.com/rswag/rswag'
8
+
9
+ def on_block(node)
10
+ # Only run from root Rspec.describe block
11
+ return unless rspec_describe?(node)
12
+
13
+ # If the block descendants contain rswag structure, it's valid
14
+ return if contains_rswag_structure?(node)
15
+
16
+ # Otherwise, add offense
17
+ add_offense(node)
18
+ end
19
+
20
+ private
21
+
22
+ def contains_rswag_structure?(node)
23
+ has_path_block?(node) &&
24
+ has_http_method_block?(node) &&
25
+ has_response_block?(node)
26
+ end
27
+
28
+ # @!method rspec_describe?(node)
29
+ def_node_matcher :rspec_describe?, <<~PATTERN
30
+ (block
31
+ (send
32
+ (const nil? :RSpec) :describe ...)
33
+ ...)
34
+ PATTERN
35
+
36
+ # @!method has_path_block?(node)
37
+ def_node_matcher :has_path_block?, <<~PATTERN
38
+ `(block
39
+ (send nil? :path (str _))
40
+ ...)
41
+ PATTERN
42
+
43
+ # @!method has_http_method_block?(node)
44
+ def_node_matcher :has_http_method_block?, <<~PATTERN
45
+ `(block
46
+ (send nil? {:get :post :put :patch :delete} (str _))
47
+ ...)
48
+ PATTERN
49
+
50
+ # @!method has_response_block?(node)
51
+ def_node_matcher :has_response_block?, <<~PATTERN
52
+ `(block
53
+ (send nil? :response (str _) (str _))
54
+ ...)
55
+ PATTERN
56
+ end
57
+ end
58
+ end
59
+ end
@@ -12,10 +12,16 @@ module RuboCop
12
12
  (send nil? :serialize ...)
13
13
  PATTERN
14
14
 
15
- def on_send(node)
16
- return unless serialize? node
15
+ # @!method kwargs_with_coder?(node)
16
+ def_node_matcher :kwargs_with_coder?, '(hash <(pair (sym :coder) const) ...>)'
17
+
18
+ # @!method valid_serialize?(node)
19
+ def_node_matcher :valid_serialize?, <<-PATTERN
20
+ (send nil? :serialize _ { const !#kwargs_with_coder?? | #kwargs_with_coder? })
21
+ PATTERN
17
22
 
18
- add_offense(node) if node.arguments.length < 2 || !node.arguments[1].const_type?
23
+ def on_send(node)
24
+ add_offense(node) if serialize?(node) && !valid_serialize?(node)
19
25
  end
20
26
  alias on_csend on_send
21
27
  end
@@ -14,6 +14,7 @@ require 'rubocop/cop/betterment/internals_protection'
14
14
  require 'rubocop/cop/betterment/memoization_with_arguments'
15
15
  require 'rubocop/cop/betterment/non_standard_actions'
16
16
  require 'rubocop/cop/betterment/non_standard_controller'
17
+ require 'rubocop/cop/betterment/not_using_rswag'
17
18
  require 'rubocop/cop/betterment/redirect_status'
18
19
  require 'rubocop/cop/betterment/render_status'
19
20
  require 'rubocop/cop/betterment/server_error_assertion'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.0
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Development
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rubocop
@@ -117,6 +117,7 @@ files:
117
117
  - lib/rubocop/cop/betterment/memoization_with_arguments.rb
118
118
  - lib/rubocop/cop/betterment/non_standard_actions.rb
119
119
  - lib/rubocop/cop/betterment/non_standard_controller.rb
120
+ - lib/rubocop/cop/betterment/not_using_rswag.rb
120
121
  - lib/rubocop/cop/betterment/redirect_status.rb
121
122
  - lib/rubocop/cop/betterment/render_status.rb
122
123
  - lib/rubocop/cop/betterment/server_error_assertion.rb
@@ -136,10 +137,10 @@ licenses:
136
137
  - MIT
137
138
  metadata:
138
139
  homepage_uri: https://github.com/Betterment/betterlint
139
- source_code_uri: https://github.com/Betterment/betterlint/tree/v1.20.0
140
- changelog_uri: https://github.com/Betterment/betterlint/blob/v1.20.0/CHANGELOG.md
140
+ source_code_uri: https://github.com/Betterment/betterlint/tree/v1.22.0
141
+ changelog_uri: https://github.com/Betterment/betterlint/blob/v1.22.0/CHANGELOG.md
141
142
  bug_tracker_uri: https://github.com/Betterment/betterlint/issues
142
- documentation_uri: https://www.rubydoc.info/gems/betterlint/1.20.0
143
+ documentation_uri: https://www.rubydoc.info/gems/betterlint/1.22.0
143
144
  rubygems_mfa_required: 'true'
144
145
  rdoc_options: []
145
146
  require_paths:
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  - !ruby/object:Gem::Version
156
157
  version: '0'
157
158
  requirements: []
158
- rubygems_version: 3.6.6
159
+ rubygems_version: 3.6.8
159
160
  specification_version: 4
160
161
  summary: Betterment rubocop configuration
161
162
  test_files: []