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: adb06524c4619412cdce77d2330bc1bfb949a23d6075f5e1b104e8e87bad27e6
4
- data.tar.gz: 5908667c00fd6e7e6c133bff94cdad711ce4ea69b85efac2e0b484dc15b75390
3
+ metadata.gz: 116e2f10caf814178e8afe49e7bac931cbb232dfd1ce8bb478057b7e0a0ce056
4
+ data.tar.gz: 0c9c7d2b6180607cc6988eca34ba7364a8295565ab07ddbeaa0c81027f5d3000
5
5
  SHA512:
6
- metadata.gz: 59b793af217d90b8fea3ffe50634e77ca5970f7729d6b931d83025015385c016c4469a354c85f624b4ef4f52e66559ae38ff9714fd0025106ddf25766e54c3a8
7
- data.tar.gz: 295ed43e20bc9d07de773420eb9d44329c000e444d47a6b379d503eb1cf42f6ebfa174c105cb5e80a4deebf5d1aca037475a71dc8569a3528a9932c6d25da1c7
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.dot? &&
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
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Performance
5
5
  # This module holds the RuboCop Performance version information.
6
6
  module Version
7
- STRING = '1.15.0'
7
+ STRING = '1.15.1'
8
8
 
9
9
  def self.document_version
10
10
  STRING.match('\d+\.\d+').to_s
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.0
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-09-10 00:00:00.000000000 Z
13
+ date: 2022-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop