betterlint 1.30.0 → 1.32.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 +34 -0
- data/config/default.yml +12 -0
- data/lib/betterlint/version.rb +1 -1
- data/lib/rubocop/cop/betterment/no_not_implemented_error.rb +18 -0
- data/lib/rubocop/cop/betterment/no_send.rb +25 -0
- data/lib/rubocop/cop/betterment.rb +2 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 255b819071945ceaf2a26dd9897a310a52a04bb79c67a06b87195257938e5812
|
|
4
|
+
data.tar.gz: d1b308edd9873869d15a079934dd04ac9cf0d883909cea13eacec04b582eecbd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a253ddffc5c77897adf1d17dc59e684b702dfdc6329adb7f5acaf8b75d2b4e6d70cf6775e1728113f88bca797dc1e73003f1eace2acb5dbdff9a9b5d55baf388
|
|
7
|
+
data.tar.gz: 7b26e11e5d09c6b5a5d823c02225a81c15c196630781e220b968e0f11ad23930622702e2d731b28b5b0f7758c305463bde614813c81cb274cfb2179200b86521
|
data/README.md
CHANGED
|
@@ -470,3 +470,37 @@ end
|
|
|
470
470
|
```
|
|
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
|
+
|
|
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
|
+
|
|
487
|
+
### Betterment/NoSend
|
|
488
|
+
|
|
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.
|
|
490
|
+
|
|
491
|
+
#### BAD:
|
|
492
|
+
|
|
493
|
+
```ruby
|
|
494
|
+
record.public_send(:name)
|
|
495
|
+
record.send(attribute_name)
|
|
496
|
+
job.send(:plaid_item)
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
#### GOOD:
|
|
500
|
+
|
|
501
|
+
```ruby
|
|
502
|
+
record.name
|
|
503
|
+
record.attributes.fetch(attribute_name)
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
This cop ignores files in `spec/`, and calls to `send` with no arguments, which are usually a different method named `send`.
|
data/config/default.yml
CHANGED
|
@@ -70,6 +70,18 @@ Betterment/NoDownMigrations:
|
|
|
70
70
|
Include:
|
|
71
71
|
- db/migrate/**/*.rb
|
|
72
72
|
|
|
73
|
+
Betterment/NoNotImplementedError:
|
|
74
|
+
Description: Disallows direct references to Ruby's NotImplementedError in application code.
|
|
75
|
+
Enabled: false
|
|
76
|
+
StyleGuide: '#bettermentnonotimplementederror'
|
|
77
|
+
|
|
78
|
+
Betterment/NoSend:
|
|
79
|
+
Description: Detects dynamic method calls through send, public_send and __send__.
|
|
80
|
+
StyleGuide: '#bettermentnosend'
|
|
81
|
+
Enabled: true
|
|
82
|
+
Exclude:
|
|
83
|
+
- spec/**/*
|
|
84
|
+
|
|
73
85
|
Betterment/NonNamespacedClass:
|
|
74
86
|
Description: Detects classes that are not namespaced under a module or constant
|
|
75
87
|
StyleGuide: '#bettermentnonamespacedclass'
|
data/lib/betterlint/version.rb
CHANGED
|
@@ -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
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Betterment
|
|
6
|
+
class NoSend < Base
|
|
7
|
+
MSG = <<~TEXT
|
|
8
|
+
Call the method directly instead of using `%<method>s`; dynamic dispatch is invisible to Sorbet and code search.
|
|
9
|
+
|
|
10
|
+
See here for more information on this cop:
|
|
11
|
+
https://github.com/Betterment/betterlint/blob/main/README.md#bettermentnosend
|
|
12
|
+
TEXT
|
|
13
|
+
|
|
14
|
+
RESTRICT_ON_SEND = %i(send public_send __send__).freeze
|
|
15
|
+
|
|
16
|
+
def on_send(node)
|
|
17
|
+
return unless node.arguments?
|
|
18
|
+
|
|
19
|
+
add_offense(node.loc.selector, message: format(MSG, method: node.method_name))
|
|
20
|
+
end
|
|
21
|
+
alias on_csend on_send
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -13,6 +13,8 @@ require 'rubocop/cop/betterment/implicit_redirect_type'
|
|
|
13
13
|
require 'rubocop/cop/betterment/internals_protection'
|
|
14
14
|
require 'rubocop/cop/betterment/memoization_with_arguments'
|
|
15
15
|
require 'rubocop/cop/betterment/no_down_migrations'
|
|
16
|
+
require 'rubocop/cop/betterment/no_not_implemented_error'
|
|
17
|
+
require 'rubocop/cop/betterment/no_send'
|
|
16
18
|
require 'rubocop/cop/betterment/non_namespaced_class'
|
|
17
19
|
require 'rubocop/cop/betterment/non_standard_actions'
|
|
18
20
|
require 'rubocop/cop/betterment/non_standard_controller'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: betterlint
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.32.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Development
|
|
@@ -180,6 +180,8 @@ files:
|
|
|
180
180
|
- lib/rubocop/cop/betterment/internals_protection.rb
|
|
181
181
|
- lib/rubocop/cop/betterment/memoization_with_arguments.rb
|
|
182
182
|
- lib/rubocop/cop/betterment/no_down_migrations.rb
|
|
183
|
+
- lib/rubocop/cop/betterment/no_not_implemented_error.rb
|
|
184
|
+
- lib/rubocop/cop/betterment/no_send.rb
|
|
183
185
|
- lib/rubocop/cop/betterment/non_namespaced_class.rb
|
|
184
186
|
- lib/rubocop/cop/betterment/non_standard_actions.rb
|
|
185
187
|
- lib/rubocop/cop/betterment/non_standard_controller.rb
|
|
@@ -204,10 +206,10 @@ licenses:
|
|
|
204
206
|
- MIT
|
|
205
207
|
metadata:
|
|
206
208
|
homepage_uri: https://github.com/Betterment/betterlint
|
|
207
|
-
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.
|
|
208
|
-
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.
|
|
209
|
+
source_code_uri: https://github.com/Betterment/betterlint/tree/v1.32.0
|
|
210
|
+
changelog_uri: https://github.com/Betterment/betterlint/blob/v1.32.0/CHANGELOG.md
|
|
209
211
|
bug_tracker_uri: https://github.com/Betterment/betterlint/issues
|
|
210
|
-
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.
|
|
212
|
+
documentation_uri: https://www.rubydoc.info/gems/betterlint/1.32.0
|
|
211
213
|
rubygems_mfa_required: 'true'
|
|
212
214
|
default_lint_roller_plugin: Betterlint::Plugin
|
|
213
215
|
rdoc_options: []
|