betterlint 1.15.1 → 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 +13 -0
- data/lib/rubocop/cop/betterment/non_standard_controller.rb +24 -0
- data/lib/rubocop/cop/betterment/use_global_strict_loading.rb +53 -0
- data/lib/rubocop/cop/betterment.rb +16 -14
- metadata +8 -6
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
@@ -64,6 +64,11 @@ Betterment/NonStandardActions:
|
|
64
64
|
- update
|
65
65
|
StyleGuide: '#bettermentnonstandardactions'
|
66
66
|
|
67
|
+
Betterment/NonStandardController:
|
68
|
+
Description: Detects non-standard controller names.
|
69
|
+
Include:
|
70
|
+
- config/routes.rb
|
71
|
+
|
67
72
|
Betterment/RedirectStatus:
|
68
73
|
SafeAutoCorrect: false
|
69
74
|
Description: Detect missing status codes when redirecting POST, PUT, PATCH, or DELETE responses
|
@@ -97,6 +102,14 @@ Betterment/UnsafeJob:
|
|
97
102
|
Betterment/UnscopedFind:
|
98
103
|
StyleGuide: '#bettermentunscopedfind'
|
99
104
|
|
105
|
+
Betterment/UseGlobalStrictLoading/ByDefaultForModels:
|
106
|
+
Enabled: true
|
107
|
+
SafeAutoCorrect: false
|
108
|
+
|
109
|
+
Betterment/UseGlobalStrictLoading/ForAssociations:
|
110
|
+
Enabled: true
|
111
|
+
SafeAutoCorrect: false
|
112
|
+
|
100
113
|
FactoryBot/AssociationStyle:
|
101
114
|
Enabled: false
|
102
115
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Betterment
|
6
|
+
class NonStandardController < RuboCop::Cop::Base
|
7
|
+
MSG = <<~END.gsub(/\s+/, " ")
|
8
|
+
`resources` and `resource` should not need to specify a `controller` option.
|
9
|
+
If your controller lives in a module, please use the `module` option. Otherwise,
|
10
|
+
please rename your controller to match your routes.
|
11
|
+
END
|
12
|
+
|
13
|
+
# @!method resources_with_controller(node)
|
14
|
+
def_node_matcher :resources_with_controller, <<~PATTERN
|
15
|
+
(send _ {:resources | :resource} _ (hash <$(pair (sym :controller) _) ...>))
|
16
|
+
PATTERN
|
17
|
+
|
18
|
+
def on_send(node)
|
19
|
+
resources_with_controller(node) { |option| add_offense(option) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -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,26 +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'
|
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'
|
16
19
|
require 'rubocop/cop/betterment/site_prism_loaded'
|
17
20
|
require 'rubocop/cop/betterment/spec_helper_required_outside_spec_dir'
|
18
|
-
require 'rubocop/cop/betterment/
|
19
|
-
require 'rubocop/cop/betterment/
|
20
|
-
require 'rubocop/cop/betterment/
|
21
|
-
require 'rubocop/cop/betterment/
|
22
|
-
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'
|
23
28
|
require 'rubocop/cop/betterment/vague_serialize'
|
24
|
-
require 'rubocop/cop/betterment/fetch_boolean'
|
25
|
-
require 'rubocop/cop/betterment/render_status'
|
26
|
-
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
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/rubocop/cop/betterment/internals_protection.rb
|
117
117
|
- lib/rubocop/cop/betterment/memoization_with_arguments.rb
|
118
118
|
- lib/rubocop/cop/betterment/non_standard_actions.rb
|
119
|
+
- lib/rubocop/cop/betterment/non_standard_controller.rb
|
119
120
|
- lib/rubocop/cop/betterment/redirect_status.rb
|
120
121
|
- lib/rubocop/cop/betterment/render_status.rb
|
121
122
|
- lib/rubocop/cop/betterment/server_error_assertion.rb
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- lib/rubocop/cop/betterment/timeout.rb
|
125
126
|
- lib/rubocop/cop/betterment/unsafe_job.rb
|
126
127
|
- lib/rubocop/cop/betterment/unscoped_find.rb
|
128
|
+
- lib/rubocop/cop/betterment/use_global_strict_loading.rb
|
127
129
|
- lib/rubocop/cop/betterment/utils/hardcoded_attribute.rb
|
128
130
|
- lib/rubocop/cop/betterment/utils/method_return_table.rb
|
129
131
|
- lib/rubocop/cop/betterment/utils/parser.rb
|
@@ -134,10 +136,10 @@ licenses:
|
|
134
136
|
- MIT
|
135
137
|
metadata:
|
136
138
|
homepage_uri: https://github.com/Betterment/betterlint
|
137
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
138
|
-
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
|
139
141
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
140
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
142
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.17.0
|
141
143
|
rubygems_mfa_required: 'true'
|
142
144
|
post_install_message:
|
143
145
|
rdoc_options: []
|
@@ -154,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
156
|
- !ruby/object:Gem::Version
|
155
157
|
version: '0'
|
156
158
|
requirements: []
|
157
|
-
rubygems_version: 3.5.
|
159
|
+
rubygems_version: 3.5.23
|
158
160
|
signing_key:
|
159
161
|
specification_version: 4
|
160
162
|
summary: Betterment rubocop configuration
|