rubocop-performance 1.10.1 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/performance/redundant_block_call.rb +7 -1
- data/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb +13 -4
- data/lib/rubocop/cop/performance/redundant_split_regexp_argument.rb +1 -1
- data/lib/rubocop/cop/performance/reverse_each.rb +18 -2
- data/lib/rubocop/performance/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 739dfb0dfbef0fa9962b144cb8cb3c600b801a86adc11877898a8eba957a2f39
|
4
|
+
data.tar.gz: 0c5f89ad71bbe81a9c9e42c418401039c9dc0f2ede40fd54c3ba1bc4955011f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07cb8c4fc7d80cac74841d9c8bdde26397c4e4273d2ef80b805388020c17cf6820c497a8ea4bfc4a39ca93f538fc2b642399e9fdb1acc401e2e0dad1bf5596d8
|
7
|
+
data.tar.gz: 74696267b3ad0b9ab49aeacfab1de661ab22140a5cea173caa82ddd206159dadc214b996812a5521d1f912c44dfa84cca822d5159c2d8b45426fe1aa55d00896
|
@@ -78,7 +78,7 @@ module RuboCop
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def calls_to_report(argname, body)
|
81
|
-
return [] if blockarg_assigned?(body, argname)
|
81
|
+
return [] if blockarg_assigned?(body, argname) || shadowed_block_argument?(body, argname)
|
82
82
|
|
83
83
|
blockarg_calls(body, argname).map do |call|
|
84
84
|
return [] if args_include_block_pass?(call)
|
@@ -87,6 +87,12 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
def shadowed_block_argument?(body, block_argument_of_method_signature)
|
91
|
+
return false unless body.block_type?
|
92
|
+
|
93
|
+
body.arguments.map(&:source).include?(block_argument_of_method_signature.to_s)
|
94
|
+
end
|
95
|
+
|
90
96
|
def args_include_block_pass?(blockcall)
|
91
97
|
_receiver, _call, *args = *blockcall
|
92
98
|
|
@@ -35,7 +35,8 @@ module RuboCop
|
|
35
35
|
IS_A_METHODS = %i[is_a? kind_of?].freeze
|
36
36
|
|
37
37
|
def on_block(node)
|
38
|
-
return unless TARGET_METHODS.include?(node.method_name)
|
38
|
+
return unless TARGET_METHODS.include?(node.method_name)
|
39
|
+
return unless one_block_argument?(node.arguments)
|
39
40
|
|
40
41
|
block_argument = node.arguments.first
|
41
42
|
block_body = node.body
|
@@ -53,14 +54,22 @@ module RuboCop
|
|
53
54
|
|
54
55
|
private
|
55
56
|
|
57
|
+
def one_block_argument?(block_arguments)
|
58
|
+
block_arguments.one? && !block_arguments.source.include?(',')
|
59
|
+
end
|
60
|
+
|
56
61
|
def use_equality_comparison_block?(block_body)
|
57
62
|
block_body.send_type? && COMPARISON_METHODS.include?(block_body.method_name)
|
58
63
|
end
|
59
64
|
|
60
65
|
def same_block_argument_and_is_a_argument?(block_body, block_argument)
|
61
|
-
|
62
|
-
|
63
|
-
|
66
|
+
if block_body.method?(:===)
|
67
|
+
block_argument.source != block_body.children[2].source
|
68
|
+
elsif IS_A_METHODS.include?(block_body.method_name)
|
69
|
+
block_argument.source == block_body.first_argument.source
|
70
|
+
else
|
71
|
+
false
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
def new_argument(block_argument, block_body)
|
@@ -26,7 +26,7 @@ module RuboCop
|
|
26
26
|
|
27
27
|
def on_send(node)
|
28
28
|
return unless (regexp_node = split_call_with_regexp?(node))
|
29
|
-
return if regexp_node.ignore_case?
|
29
|
+
return if regexp_node.ignore_case? || regexp_node.content == ' '
|
30
30
|
return unless determinist_regexp?(regexp_node)
|
31
31
|
|
32
32
|
add_offense(regexp_node) do |corrector|
|
@@ -6,12 +6,20 @@ module RuboCop
|
|
6
6
|
# This cop is used to identify usages of `reverse.each` and
|
7
7
|
# change them to use `reverse_each` instead.
|
8
8
|
#
|
9
|
+
# If the return value is used, it will not be detected because the result will be different.
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# ----
|
13
|
+
# [1, 2, 3].reverse.each {} #=> [3, 2, 1]
|
14
|
+
# [1, 2, 3].reverse_each {} #=> [1, 2, 3]
|
15
|
+
# ----
|
16
|
+
#
|
9
17
|
# @example
|
10
18
|
# # bad
|
11
|
-
#
|
19
|
+
# items.reverse.each
|
12
20
|
#
|
13
21
|
# # good
|
14
|
-
#
|
22
|
+
# items.reverse_each
|
15
23
|
class ReverseEach < Base
|
16
24
|
include RangeHelp
|
17
25
|
extend AutoCorrector
|
@@ -24,6 +32,8 @@ module RuboCop
|
|
24
32
|
MATCHER
|
25
33
|
|
26
34
|
def on_send(node)
|
35
|
+
return if use_return_value?(node)
|
36
|
+
|
27
37
|
reverse_each?(node) do
|
28
38
|
range = offense_range(node)
|
29
39
|
|
@@ -35,6 +45,12 @@ module RuboCop
|
|
35
45
|
|
36
46
|
private
|
37
47
|
|
48
|
+
def use_return_value?(node)
|
49
|
+
!!node.ancestors.detect do |ancestor|
|
50
|
+
ancestor.assignment? || ancestor.send_type? || ancestor.return_type?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
38
54
|
def offense_range(node)
|
39
55
|
range_between(node.children.first.loc.selector.begin_pos, node.loc.selector.end_pos)
|
40
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-performance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-03-
|
13
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|