rubocop-performance 1.15.0 → 1.15.1
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: 116e2f10caf814178e8afe49e7bac931cbb232dfd1ce8bb478057b7e0a0ce056
|
4
|
+
data.tar.gz: 0c9c7d2b6180607cc6988eca34ba7364a8295565ab07ddbeaa0c81027f5d3000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd9c4b591e4193d5ef640a586c71b7cb0b27dbde63022128119297ebfc9e09741f5a26ee8ef2c1cea876c4f919f48b8fbd364285149c45b89818c6e0ecf1a3c6
|
7
|
+
data.tar.gz: 8984a58f416a279e7a6f74f4917600a9ba97a90fca81160b0899a66123612736576c870668e8b5e52bb5de0aae5c34ea5874105fa58f3aef63987d5cea319198
|
@@ -79,12 +79,11 @@ module RuboCop
|
|
79
79
|
def autocorrect(corrector, node, selector_node, selector)
|
80
80
|
selector_loc = selector_node.loc.selector
|
81
81
|
|
82
|
-
return if selector == :reject
|
83
|
-
|
84
82
|
range = source_starting_at(node) { |n| n.loc.dot.begin_pos }
|
85
83
|
|
86
84
|
corrector.remove(range)
|
87
85
|
corrector.replace(selector_loc, 'count')
|
86
|
+
negate_reject(corrector, node) if selector == :reject
|
88
87
|
end
|
89
88
|
|
90
89
|
def eligible_node?(node)
|
@@ -100,6 +99,43 @@ module RuboCop
|
|
100
99
|
|
101
100
|
range_between(begin_pos, node.source_range.end_pos)
|
102
101
|
end
|
102
|
+
|
103
|
+
def negate_reject(corrector, node)
|
104
|
+
if node.receiver.send_type?
|
105
|
+
negate_block_pass_reject(corrector, node)
|
106
|
+
else
|
107
|
+
negate_block_reject(corrector, node)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def negate_block_pass_reject(corrector, node)
|
112
|
+
corrector.replace(
|
113
|
+
node.receiver.loc.expression.with(begin_pos: node.receiver.loc.begin.begin_pos),
|
114
|
+
negate_block_pass_as_inline_block(node.receiver)
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
def negate_block_reject(corrector, node)
|
119
|
+
target =
|
120
|
+
if node.receiver.body.begin_type?
|
121
|
+
node.receiver.body.children.last
|
122
|
+
else
|
123
|
+
node.receiver.body
|
124
|
+
end
|
125
|
+
corrector.replace(target, negate_expression(target))
|
126
|
+
end
|
127
|
+
|
128
|
+
def negate_expression(node)
|
129
|
+
"!(#{node.source})"
|
130
|
+
end
|
131
|
+
|
132
|
+
def negate_block_pass_as_inline_block(node)
|
133
|
+
if node.last_argument.children.first.sym_type?
|
134
|
+
" { |element| !element.#{node.last_argument.children.first.value} }"
|
135
|
+
else
|
136
|
+
" { !#{node.last_argument.children.first.source}.call }"
|
137
|
+
end
|
138
|
+
end
|
103
139
|
end
|
104
140
|
end
|
105
141
|
end
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
def remove_compact_method(corrector, map_node, compact_node, chained_method)
|
68
68
|
compact_method_range = compact_node.loc.selector
|
69
69
|
|
70
|
-
if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && chained_method
|
70
|
+
if compact_node.multiline? && chained_method&.loc.respond_to?(:selector) && use_dot?(chained_method) &&
|
71
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)
|
@@ -78,6 +78,10 @@ module RuboCop
|
|
78
78
|
corrector.remove(compact_method_range)
|
79
79
|
end
|
80
80
|
|
81
|
+
def use_dot?(node)
|
82
|
+
node.respond_to?(:dot?) && node.dot?
|
83
|
+
end
|
84
|
+
|
81
85
|
def map_method_and_compact_method_on_same_line?(map_node, compact_node)
|
82
86
|
compact_node.loc.selector.line == map_node.loc.selector.line
|
83
87
|
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.15.
|
4
|
+
version: 1.15.1
|
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-11-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|