ducalis 0.5.4 → 0.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 328e7b375b3c04b775fa5857eccbc0ea72fde606
4
- data.tar.gz: 9e36648c4778ba101e3af5811a8356359383b7a4
3
+ metadata.gz: a37e051cff024cd88cc907c7f6588dbf45def229
4
+ data.tar.gz: e6aaaca1a78a6a7b9fe846b1f7e70f0e5dd47ec4
5
5
  SHA512:
6
- metadata.gz: 89622fd354b5feabd9390c12107a5e651e4dfbd1a3659efdebd578a930b33ebf4a40313723d00fde39b9558954f440413365701e59d891f2502b6bf0ddd10041
7
- data.tar.gz: 1387adbbc6154a6b2eca280a3cea8d030b0f90fbf3a6bcc53e0604227df29d08607ba8b167d420f78099028d3ed1c2d6c8e130161464da237cfa9ff965fce4e0
6
+ metadata.gz: 9cd7e58476f46b3c6198b3a089c11550300349926616bb29fdff8810a4027faaa99ea1372bc048eebd25449ba484445eda97241ae75acb6f2c6accd5391f56fb
7
+ data.tar.gz: 34c024fb32a3ed7815df722daf4067dec4befad4ffbc55e5a0d9de640c5508d9a53beb5d528e2482797119deea8d7734a38f8ce4b5f1efbb5cd9839b62695391
@@ -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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ducalis (0.5.4)
4
+ ducalis (0.5.5)
5
5
  git (~> 1.3, >= 1.3.0)
6
6
  policial (= 0.0.4)
7
7
  regexp-examples (~> 1.3, >= 1.3.2)
@@ -5,6 +5,9 @@ AllCops:
5
5
  - 'node_modules/**/*'
6
6
  - 'vendor/bundle/**/*'
7
7
 
8
+ Ducalis/PreferableMethods:
9
+ Enabled: true
10
+
8
11
  Ducalis/CaseMapping:
9
12
  Enabled: true
10
13
 
@@ -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
- _who, what, *_args = *node
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))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ducalis
4
- VERSION = '0.5.4'
4
+ VERSION = '0.5.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ducalis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignat Zakrevsky