ducalis 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DOCUMENTATION.md +20 -0
- data/Gemfile.lock +1 -1
- data/config/.ducalis.yml +3 -0
- data/lib/ducalis.rb +1 -0
- data/lib/ducalis/cops/preferable_methods.rb +11 -5
- data/lib/ducalis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a37e051cff024cd88cc907c7f6588dbf45def229
|
4
|
+
data.tar.gz: e6aaaca1a78a6a7b9fe846b1f7e70f0e5dd47ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd7e58476f46b3c6198b3a089c11550300349926616bb29fdff8810a4027faaa99ea1372bc048eebd25449ba484445eda97241ae75acb6f2c6accd5391f56fb
|
7
|
+
data.tar.gz: 34c024fb32a3ed7815df722daf4067dec4befad4ffbc55e5a0d9de640c5508d9a53beb5d528e2482797119deea8d7734a38f8ce4b5f1efbb5cd9839b62695391
|
data/DOCUMENTATION.md
CHANGED
@@ -460,6 +460,26 @@ Prefer to use %<alternative>s method instead of %<original>s because of
|
|
460
460
|
```ruby
|
461
461
|
User.where(id: 7).delete
|
462
462
|
```
|
463
|
+
|
464
|
+
![](https://placehold.it/15/2cbe4e/000000?text=+) ignores calling `delete` with symbol
|
465
|
+
```ruby
|
466
|
+
params.delete(:code)
|
467
|
+
```
|
468
|
+
|
469
|
+
![](https://placehold.it/15/2cbe4e/000000?text=+) ignores calling `delete` with string
|
470
|
+
```ruby
|
471
|
+
string.delete("-")
|
472
|
+
```
|
473
|
+
|
474
|
+
![](https://placehold.it/15/2cbe4e/000000?text=+) ignores calling `delete` with multiple args
|
475
|
+
```ruby
|
476
|
+
some.delete(1, header: [])
|
477
|
+
```
|
478
|
+
|
479
|
+
![](https://placehold.it/15/2cbe4e/000000?text=+) ignores calling `delete` on files-like variables
|
480
|
+
```ruby
|
481
|
+
tempfile.delete
|
482
|
+
```
|
463
483
|
## Ducalis::PrivateInstanceAssign
|
464
484
|
|
465
485
|
Please, don't assign instance variables in controller's private methods. It's make hard to understand what variables are available in views.
|
data/Gemfile.lock
CHANGED
data/config/.ducalis.yml
CHANGED
data/lib/ducalis.rb
CHANGED
@@ -39,6 +39,7 @@ require 'ducalis/cops/module_like_class'
|
|
39
39
|
require 'ducalis/cops/params_passing'
|
40
40
|
require 'ducalis/cops/possible_tap'
|
41
41
|
require 'ducalis/cops/private_instance_assign'
|
42
|
+
require 'ducalis/cops/preferable_methods'
|
42
43
|
require 'ducalis/cops/protected_scope_cop'
|
43
44
|
require 'ducalis/cops/raise_withour_error_class'
|
44
45
|
require 'ducalis/cops/regex_cop'
|
@@ -7,16 +7,22 @@ module Ducalis
|
|
7
7
|
Prefer to use %<alternative>s method instead of %<original>s because of
|
8
8
|
%<reason>s.
|
9
9
|
).strip
|
10
|
+
ALWAYS_TRUE = ->(_who, _what, _args) { true }
|
11
|
+
DELETE_CHECK = lambda do |who, _what, args|
|
12
|
+
!%i(sym str).include?(args.first&.type) &&
|
13
|
+
args.count <= 1 && who.to_s !~ /file/
|
14
|
+
end
|
10
15
|
DESCRIPTION = {
|
11
|
-
# Method => [Alternative, Reason]
|
12
|
-
delete_all: [:destroy_all, 'it is not invoking callbacks'],
|
13
|
-
delete: [:destroy, 'it is not invoking callbacks']
|
16
|
+
# Method => [Alternative, Reason, Callable condition]
|
17
|
+
delete_all: [:destroy_all, 'it is not invoking callbacks', ALWAYS_TRUE],
|
18
|
+
delete: [:destroy, 'it is not invoking callbacks', DELETE_CHECK]
|
14
19
|
}.freeze
|
15
20
|
|
16
21
|
def on_send(node)
|
17
|
-
|
22
|
+
who, what, *args = *node
|
18
23
|
return unless DESCRIPTION.keys.include?(what)
|
19
|
-
alternative, reason = DESCRIPTION.fetch(what)
|
24
|
+
alternative, reason, condition = DESCRIPTION.fetch(what)
|
25
|
+
return unless condition.call(who, what, args)
|
20
26
|
add_offense(node, :expression, format(OFFENSE, original: what,
|
21
27
|
alternative: alternative,
|
22
28
|
reason: reason))
|
data/lib/ducalis/version.rb
CHANGED