betterlint 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/config/default.yml +8 -0
- data/lib/rubocop/cop/betterment/use_global_strict_loading.rb +53 -0
- data/lib/rubocop/cop/betterment.rb +15 -14
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22aae83c05b82fd78756d3d69d45c25d71b5a63715831c947239a73a6ce5f1f
|
4
|
+
data.tar.gz: 1b80addb1d93b9823303e94c0e87b7360bd5d3456af6ab250c4f13a2e3bac625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a2bd3580e962c52fab4a4cdb9778137ca3c96506f1dde5e9d8ae69f188364b81930980b68538200aeb9e1bc433a590725370216d239a754f9c8f19e7e055bc
|
7
|
+
data.tar.gz: e685d82cf02b3065077014c89d44b1bb91aa593a087c4479d29a55aa938f3f7ccf31fa3da5486ccba8a1dbd64ff62bd23246f6e8715232fee785545db518607e
|
data/README.md
CHANGED
@@ -280,3 +280,20 @@ actions often indicates error handling (e.g. `422 Unprocessable Entity`).
|
|
280
280
|
This cop requires you to explicitly provide an HTTP status code when rendering a response in the
|
281
281
|
create, update, and destroy actions. When autocorrecting, this will automatically add
|
282
282
|
`status: :unprocessable_entity` or `status: :ok` depending on what you're rendering.
|
283
|
+
|
284
|
+
### Betterment/UseGlobalStrictLoading/ByDefaultForModels
|
285
|
+
|
286
|
+
This cop identifies models where `self.strict_loading_by_default` is assigned to explicitly, and prefers that it be removed in favor of using the global strict loading settings.
|
287
|
+
|
288
|
+
We use this to create a `.rubocop_todo.yml` file showing all the models that have been explicitly configured, so that we can "burn down" and lean more heavily on using global settings. We prefer to enable strict loading by default globally, but transioning a large Rails application to work in that state is difficult and must be broken down into smaller steps. Our workflow is to change all models to turn off strict loading, regenerate our rubocop todo file, then enable the flag globally. Then on a model-by-model basis we'll enable them one at a time, and fix all spec failures per model.
|
289
|
+
|
290
|
+
This allows us two benefits:
|
291
|
+
|
292
|
+
1. We can gradually change code used by older models to use strict loading without having to fix the world all at once.
|
293
|
+
2. All new models will strict load by default, forcing us to specify the objcts to load up-front in our controllers and other call sites.
|
294
|
+
|
295
|
+
### Betterment/UseGlobalStrictLoading/ForAssociations
|
296
|
+
|
297
|
+
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.
|
298
|
+
|
299
|
+
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.
|
data/config/default.yml
CHANGED
@@ -102,6 +102,14 @@ Betterment/UnsafeJob:
|
|
102
102
|
Betterment/UnscopedFind:
|
103
103
|
StyleGuide: '#bettermentunscopedfind'
|
104
104
|
|
105
|
+
Betterment/UseGlobalStrictLoading/ByDefaultForModels:
|
106
|
+
Enabled: true
|
107
|
+
SafeAutoCorrect: false
|
108
|
+
|
109
|
+
Betterment/UseGlobalStrictLoading/ForAssociations:
|
110
|
+
Enabled: true
|
111
|
+
SafeAutoCorrect: false
|
112
|
+
|
105
113
|
FactoryBot/AssociationStyle:
|
106
114
|
Enabled: false
|
107
115
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Betterment
|
6
|
+
module UseGlobalStrictLoading
|
7
|
+
# This cop ensures that `self.strict_loading_by_default = <any value>` is not set in ActiveRecord models.
|
8
|
+
class ByDefaultForModels < Base
|
9
|
+
extend AutoCorrector
|
10
|
+
include RangeHelp
|
11
|
+
|
12
|
+
MSG = 'Do not set `self.strict_loading_by_default` in ActiveRecord models.'
|
13
|
+
|
14
|
+
# @!method strict_loading_by_default_set?(node)
|
15
|
+
def_node_matcher :strict_loading_by_default_set?, <<~PATTERN
|
16
|
+
$(send self :strict_loading_by_default= _)
|
17
|
+
PATTERN
|
18
|
+
|
19
|
+
def on_send(node)
|
20
|
+
strict_loading_by_default_set?(node) do |method_call|
|
21
|
+
add_offense(method_call) do |corrector|
|
22
|
+
corrector.remove(method_call)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# This cop ensures that `strict_loading: <any value>` is not set in ActiveRecord associations.
|
29
|
+
class ForAssociations < Base
|
30
|
+
extend AutoCorrector
|
31
|
+
include RangeHelp
|
32
|
+
|
33
|
+
MSG = 'Do not set `:strict_loading` in ActiveRecord associations.'
|
34
|
+
|
35
|
+
ASSOCIATION_METHODS = %i(belongs_to has_and_belongs_to_many has_many has_one).freeze
|
36
|
+
|
37
|
+
# @!method association_with_strict_loading?(node)
|
38
|
+
def_node_matcher :association_with_strict_loading?, <<~PATTERN
|
39
|
+
(send nil? {#{ASSOCIATION_METHODS.map(&:inspect).join(' ')}} ... (hash <$(pair (sym :strict_loading) ...) ...>))
|
40
|
+
PATTERN
|
41
|
+
|
42
|
+
def on_send(node)
|
43
|
+
association_with_strict_loading?(node) do |pair|
|
44
|
+
add_offense(node) do |corrector|
|
45
|
+
corrector.remove(range_with_surrounding_comma(range_with_surrounding_space(range: pair.source_range, side: :left), :left))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,27 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
-
require 'rubocop/cop/betterment/
|
5
|
-
require 'rubocop/cop/betterment/
|
6
|
-
require 'rubocop/cop/betterment/utils/hardcoded_attribute'
|
4
|
+
require 'rubocop/cop/betterment/active_job_performable'
|
5
|
+
require 'rubocop/cop/betterment/allowlist_blocklist'
|
7
6
|
require 'rubocop/cop/betterment/authorization_in_controller'
|
8
7
|
require 'rubocop/cop/betterment/direct_delayed_enqueue'
|
9
8
|
require 'rubocop/cop/betterment/dynamic_params'
|
10
|
-
require 'rubocop/cop/betterment/
|
11
|
-
require 'rubocop/cop/betterment/
|
12
|
-
require 'rubocop/cop/betterment/
|
9
|
+
require 'rubocop/cop/betterment/fetch_boolean'
|
10
|
+
require 'rubocop/cop/betterment/hardcoded_id'
|
11
|
+
require 'rubocop/cop/betterment/implicit_redirect_type'
|
13
12
|
require 'rubocop/cop/betterment/internals_protection'
|
14
13
|
require 'rubocop/cop/betterment/memoization_with_arguments'
|
15
14
|
require 'rubocop/cop/betterment/non_standard_actions'
|
16
15
|
require 'rubocop/cop/betterment/non_standard_controller'
|
16
|
+
require 'rubocop/cop/betterment/redirect_status'
|
17
|
+
require 'rubocop/cop/betterment/render_status'
|
18
|
+
require 'rubocop/cop/betterment/server_error_assertion'
|
17
19
|
require 'rubocop/cop/betterment/site_prism_loaded'
|
18
20
|
require 'rubocop/cop/betterment/spec_helper_required_outside_spec_dir'
|
19
|
-
require 'rubocop/cop/betterment/
|
20
|
-
require 'rubocop/cop/betterment/
|
21
|
-
require 'rubocop/cop/betterment/
|
22
|
-
require 'rubocop/cop/betterment/
|
23
|
-
require 'rubocop/cop/betterment/
|
21
|
+
require 'rubocop/cop/betterment/timeout'
|
22
|
+
require 'rubocop/cop/betterment/unsafe_job'
|
23
|
+
require 'rubocop/cop/betterment/unscoped_find'
|
24
|
+
require 'rubocop/cop/betterment/use_global_strict_loading'
|
25
|
+
require 'rubocop/cop/betterment/utils/hardcoded_attribute'
|
26
|
+
require 'rubocop/cop/betterment/utils/method_return_table'
|
27
|
+
require 'rubocop/cop/betterment/utils/parser'
|
24
28
|
require 'rubocop/cop/betterment/vague_serialize'
|
25
|
-
require 'rubocop/cop/betterment/fetch_boolean'
|
26
|
-
require 'rubocop/cop/betterment/render_status'
|
27
|
-
require 'rubocop/cop/betterment/redirect_status'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Development
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/rubocop/cop/betterment/timeout.rb
|
126
126
|
- lib/rubocop/cop/betterment/unsafe_job.rb
|
127
127
|
- lib/rubocop/cop/betterment/unscoped_find.rb
|
128
|
+
- lib/rubocop/cop/betterment/use_global_strict_loading.rb
|
128
129
|
- lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb
|
129
130
|
- lib/rubocop/cop/betterment/utils/method_return_table.rb
|
130
131
|
- lib/rubocop/cop/betterment/utils/parser.rb
|
@@ -135,10 +136,10 @@ licenses:
|
|
135
136
|
- MIT
|
136
137
|
metadata:
|
137
138
|
homepage_uri: https://github.com/Betterment/betterlint
|
138
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
139
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
139
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.17.0
|
140
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.17.0/CHANGELOG.md
|
140
141
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
141
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
142
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.17.0
|
142
143
|
rubygems_mfa_required: 'true'
|
143
144
|
post_install_message:
|
144
145
|
rdoc_options: []
|