rubocop-performance 1.13.2 → 1.13.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc8de809f0aa167f08fd75ed2f7047fabc37b06b12a0c59e4647530b18fb6d99
|
4
|
+
data.tar.gz: df849a7c117eb44d8851969031cda6d5927e2f271ad41bc3689212bad6b9e2e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24c72e01dfa6cfe35b3c93e1c83d63aaa0362dff7bc4ed234b8b6f8c1a434927a945b077273ec84c95be86d70e050f28e18dad27ffc9c72350f49c7ff3477b4a
|
7
|
+
data.tar.gz: 3340644f87ea108d8f7022756ff5cdf442b0d2951cd9ea351bb0a4012c2d0721dc921b1402e8b5f952899015b51c402cdbcab5e785d764f4655aa068c71be6b3
|
@@ -3,18 +3,16 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Performance
|
6
|
-
# This cop is used to identify usages of
|
6
|
+
# This cop is used to identify usages of `array.compact.flatten.map { |x| x.downcase }`.
|
7
|
+
# Each of these methods (`compact`, `flatten`, `map`) will generate a new intermediate array
|
8
|
+
# that is promptly thrown away. Instead it is faster to mutate when we know it's safe.
|
9
|
+
#
|
7
10
|
# @example
|
8
11
|
# # bad
|
9
12
|
# array = ["a", "b", "c"]
|
10
13
|
# array.compact.flatten.map { |x| x.downcase }
|
11
14
|
#
|
12
|
-
#
|
13
|
-
# new intermediate array that is promptly thrown away. Instead it is
|
14
|
-
# faster to mutate when we know it's safe.
|
15
|
-
#
|
16
|
-
# @example
|
17
|
-
# # good.
|
15
|
+
# # good
|
18
16
|
# array = ["a", "b", "c"]
|
19
17
|
# array.compact!
|
20
18
|
# array.flatten!
|
@@ -58,17 +58,17 @@ module RuboCop
|
|
58
58
|
|
59
59
|
add_offense(range) do |corrector|
|
60
60
|
corrector.replace(map_node.loc.selector, 'filter_map')
|
61
|
-
remove_compact_method(corrector, node, node.parent)
|
61
|
+
remove_compact_method(corrector, map_node, node, node.parent)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
66
66
|
|
67
|
-
def remove_compact_method(corrector, compact_node, chained_method)
|
67
|
+
def remove_compact_method(corrector, map_node, compact_node, chained_method)
|
68
68
|
compact_method_range = compact_node.loc.selector
|
69
69
|
|
70
70
|
if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && chained_method.dot? &&
|
71
|
-
!map_method_and_compact_method_on_same_line?(compact_node) &&
|
71
|
+
!map_method_and_compact_method_on_same_line?(map_node, compact_node) &&
|
72
72
|
!invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
|
73
73
|
compact_method_range = compact_method_with_final_newline_range(compact_method_range)
|
74
74
|
else
|
@@ -78,11 +78,7 @@ module RuboCop
|
|
78
78
|
corrector.remove(compact_method_range)
|
79
79
|
end
|
80
80
|
|
81
|
-
def map_method_and_compact_method_on_same_line?(compact_node)
|
82
|
-
return false unless compact_node.children.first.respond_to?(:send_node)
|
83
|
-
|
84
|
-
map_node = compact_node.children.first.send_node
|
85
|
-
|
81
|
+
def map_method_and_compact_method_on_same_line?(map_node, compact_node)
|
86
82
|
compact_node.loc.selector.line == map_node.loc.selector.line
|
87
83
|
end
|
88
84
|
|
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.13.
|
4
|
+
version: 1.13.3
|
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: 2022-
|
13
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|