betterlint 1.23.0 → 1.24.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 +4 -4
- data/README.md +40 -2
- data/STYLEGUIDE.md +33 -0
- data/config/default.yml +4 -0
- data/lib/rubocop/cop/betterment/simple_delegator.rb +26 -0
- data/lib/rubocop/cop/betterment.rb +1 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dedcf1bca77813b532e0523d2c85776697e0a0602faaa7a6939f77d0c1af5d9c
|
4
|
+
data.tar.gz: 68097f9df8adb9f37db3ecafa2fbec26d1445418bc080f8d879a845557b25f4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '07922a227dc628c4c3fd9389dee5ffbacb56db56cc4e15160db8849a69a21e8102e1b46c9f80bbe1062073e6886832b4ef1978ed4506aa7912edfc9a6948d9e8'
|
7
|
+
data.tar.gz: 38d4bfc4ea265f2242cbb45b67f9d872dfb4ea7c168b3f729ce121a7f848f2c9b1c7ca2b3df89a2b65969eb9b5994f3f012ab575b3899b9b8e1c2d060a7c76fd
|
data/README.md
CHANGED
@@ -142,13 +142,18 @@ If there isn't a better place to assign your environment variable, Rails provide
|
|
142
142
|
for [custom configuration](https://guides.rubyonrails.org/configuring.html#custom-configuration):
|
143
143
|
|
144
144
|
```ruby
|
145
|
-
config.x.whatever = ENV.fetch('WHATEVER')
|
145
|
+
config.x.some_namespace.whatever = ENV.fetch('WHATEVER')
|
146
146
|
```
|
147
147
|
|
148
148
|
Here's how you'd reference this configuration parameter at runtime:
|
149
149
|
|
150
150
|
```ruby
|
151
|
-
Rails.configuration.x.whatever
|
151
|
+
Rails.configuration.x.some_namespace.whatever
|
152
|
+
```
|
153
|
+
|
154
|
+
Or to raise an error when the value is not present
|
155
|
+
```ruby
|
156
|
+
Rails.configuration.x.some_namespace.whatever! # will raise "KeyError: :whatever is blank" when value is not set or set to nil
|
152
157
|
```
|
153
158
|
|
154
159
|
### Betterment/InternalsProtection
|
@@ -302,6 +307,39 @@ This cop requires you to explicitly provide an HTTP status code when rendering a
|
|
302
307
|
create, update, and destroy actions. When autocorrecting, this will automatically add
|
303
308
|
`status: :unprocessable_entity` or `status: :ok` depending on what you're rendering.
|
304
309
|
|
310
|
+
### Betterment/SimpleDelegator
|
311
|
+
|
312
|
+
This cop requires you to use Rails's `delegate` class method instead of `SimpleDelegator` in order to explicitly specify
|
313
|
+
the set of delegated methods.
|
314
|
+
|
315
|
+
#### BAD:
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
class GearPresenter < SimpleDelegator
|
319
|
+
def ratio_string
|
320
|
+
ratio.to_s
|
321
|
+
end
|
322
|
+
end
|
323
|
+
```
|
324
|
+
|
325
|
+
#### GOOD:
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
class GearPresenter
|
329
|
+
attr_reader :gear
|
330
|
+
|
331
|
+
delegate :ratio, to: :gear
|
332
|
+
|
333
|
+
def initialize(gear)
|
334
|
+
@gear = gear
|
335
|
+
end
|
336
|
+
|
337
|
+
def ratio_string
|
338
|
+
ratio.to_s
|
339
|
+
end
|
340
|
+
end
|
341
|
+
```
|
342
|
+
|
305
343
|
### Betterment/UseGlobalStrictLoading/ByDefaultForModels
|
306
344
|
|
307
345
|
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.
|
data/STYLEGUIDE.md
CHANGED
@@ -109,3 +109,36 @@ expect(response).to have_http_status 422
|
|
109
109
|
expect(response).to have_http_status :internal_server_error
|
110
110
|
expect(response).to have_http_status 500
|
111
111
|
```
|
112
|
+
|
113
|
+
## Betterment/SimpleDelegator
|
114
|
+
|
115
|
+
This cop requires you to use Rail's `delegate` class method instead of `SimpleDelegator` in order to explicitly specify
|
116
|
+
the set of delegating methods.
|
117
|
+
|
118
|
+
### BAD:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class GearPresenter < SimpleDelegator
|
122
|
+
def ratio_string
|
123
|
+
ratio.to_s
|
124
|
+
end
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
### GOOD:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
class GearDelegator
|
132
|
+
attr_reader :gear
|
133
|
+
|
134
|
+
delegate :ratio, to: :gear
|
135
|
+
|
136
|
+
def initialize(gear)
|
137
|
+
@gear = gear
|
138
|
+
end
|
139
|
+
|
140
|
+
def ratio_string
|
141
|
+
ratio.to_s
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
data/config/default.yml
CHANGED
@@ -95,6 +95,10 @@ Betterment/ServerErrorAssertion:
|
|
95
95
|
Include:
|
96
96
|
- spec/requests/**/*_spec.rb
|
97
97
|
|
98
|
+
Betterment/SimpleDelegator:
|
99
|
+
StyleGuide: '#bettermentsimpledelegator'
|
100
|
+
AutoCorrect: false
|
101
|
+
|
98
102
|
Betterment/SitePrismLoaded:
|
99
103
|
Include:
|
100
104
|
- spec/features/**/*_spec.rb
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Betterment
|
6
|
+
class SimpleDelegator < Base
|
7
|
+
MSG = <<~MSG
|
8
|
+
In order to specify a set of explicitly available methods,
|
9
|
+
use the `delegate` class method instead of `SimpleDelegator`.
|
10
|
+
|
11
|
+
See here for more information on this error:
|
12
|
+
https://github.com/Betterment/betterlint/#bettermentsimpledelegator
|
13
|
+
MSG
|
14
|
+
|
15
|
+
# @!method class_with_simple_delegator?(node)
|
16
|
+
def_node_matcher :class_with_simple_delegator?, <<~PATTERN
|
17
|
+
(class _ (const nil? :SimpleDelegator) _)
|
18
|
+
PATTERN
|
19
|
+
|
20
|
+
def on_class(node)
|
21
|
+
add_offense(node) if class_with_simple_delegator?(node)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -18,6 +18,7 @@ require 'rubocop/cop/betterment/not_using_rswag'
|
|
18
18
|
require 'rubocop/cop/betterment/redirect_status'
|
19
19
|
require 'rubocop/cop/betterment/render_status'
|
20
20
|
require 'rubocop/cop/betterment/server_error_assertion'
|
21
|
+
require 'rubocop/cop/betterment/simple_delegator'
|
21
22
|
require 'rubocop/cop/betterment/site_prism_loaded'
|
22
23
|
require 'rubocop/cop/betterment/spec_helper_required_outside_spec_dir'
|
23
24
|
require 'rubocop/cop/betterment/timeout'
|
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.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Development
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rubocop
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/rubocop/cop/betterment/redirect_status.rb
|
122
122
|
- lib/rubocop/cop/betterment/render_status.rb
|
123
123
|
- lib/rubocop/cop/betterment/server_error_assertion.rb
|
124
|
+
- lib/rubocop/cop/betterment/simple_delegator.rb
|
124
125
|
- lib/rubocop/cop/betterment/site_prism_loaded.rb
|
125
126
|
- lib/rubocop/cop/betterment/spec_helper_required_outside_spec_dir.rb
|
126
127
|
- lib/rubocop/cop/betterment/timeout.rb
|
@@ -137,10 +138,10 @@ licenses:
|
|
137
138
|
- MIT
|
138
139
|
metadata:
|
139
140
|
homepage_uri: https://github.com/Betterment/betterlint
|
140
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
141
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
141
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.24.0
|
142
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.24.0/CHANGELOG.md
|
142
143
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
143
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
144
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.24.0
|
144
145
|
rubygems_mfa_required: 'true'
|
145
146
|
rdoc_options: []
|
146
147
|
require_paths:
|
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
157
|
- !ruby/object:Gem::Version
|
157
158
|
version: '0'
|
158
159
|
requirements: []
|
159
|
-
rubygems_version: 3.6.
|
160
|
+
rubygems_version: 3.6.8
|
160
161
|
specification_version: 4
|
161
162
|
summary: Betterment rubocop configuration
|
162
163
|
test_files: []
|