rubocop-performance 1.4.0 → 1.4.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: 1b4e37268b335dd810db8ddf3b71bde2de0961faff6f01762c4462e545b31b5c
4
- data.tar.gz: e12f8f66c38d0aedec5602fb812818385a1d540a272a7df3f0e5ac79117a0fe9
3
+ metadata.gz: c7ae023c81bdf2e4816ffa5bed9a98fc10bcaec5e6e37c89f51eb9fb11fa452f
4
+ data.tar.gz: 01bc8929e0c9ab2d80933c13c35dbcc713a04574ff51002ff2f7182e05045917
5
5
  SHA512:
6
- metadata.gz: 45c31b5a12937ebcae1cf78f4b9ddf21891a07f3fdeb7ff5077ae4b25338df7ef82807ece0c4663edc2b802b5441c7e35ebe5e9ae6f2472b292ea5c60ab11dc8
7
- data.tar.gz: 2640dc57af12939b4563c7bc4235a0d0668cc7a129a9ac77a3a40cc01e53c22f72d1027b0f998a93551aa4c0af7b0e0a9eaf7e8921153b88bb647e289d2b651a
6
+ metadata.gz: 05da6b08dea1f6b8f16aa077bbfaa021b9586efb6895452f6af465fa03f695740370d8eb126d467c79565c204a2d76125fd0ce6137b9e18bb3dbe47d6c9ed44d
7
+ data.tar.gz: b0c11d70c9677b6e7e8796523b602a7dfe8ed308dfe124b26a4935193eee4293f5147cdd198b2a277841ccea131dde686c0be965811659cb030b16e3a0841b68
@@ -132,7 +132,7 @@ module RuboCop
132
132
  end
133
133
 
134
134
  def max_key_value_pairs
135
- Integer(cop_config['MaxKeyValuePairs'])
135
+ Integer(cop_config['MaxKeyValuePairs']) || 2
136
136
  end
137
137
 
138
138
  # A utility class for checking the use of values within an
@@ -177,25 +177,42 @@ module RuboCop
177
177
  scope_root = scope_root(match_node)
178
178
  body = scope_root ? scope_body(scope_root) : match_node.ancestors.last
179
179
 
180
- return true if match_node.parent.if_type? &&
181
- match_node.parent.modifier_form?
180
+ range = range_to_search_for_last_matches(match_node, body, scope_root)
182
181
 
183
- match_node_pos = match_node.loc.expression.begin_pos
182
+ find_last_match(body, range, scope_root)
183
+ end
184
184
 
185
+ def range_to_search_for_last_matches(match_node, body, scope_root)
186
+ expression = if modifier_form?(match_node)
187
+ match_node.parent.if_branch.loc.expression
188
+ else
189
+ match_node.loc.expression
190
+ end
191
+
192
+ match_node_pos = expression.begin_pos
185
193
  next_match_pos = next_match_pos(body, match_node_pos, scope_root)
186
- range = match_node_pos..next_match_pos
187
194
 
188
- find_last_match(body, range, scope_root)
195
+ match_node_pos..next_match_pos
189
196
  end
190
197
 
191
198
  def next_match_pos(body, match_node_pos, scope_root)
192
199
  node = search_match_nodes(body).find do |match|
193
- match.loc.expression.begin_pos > match_node_pos &&
194
- scope_root(match) == scope_root
200
+ begin_pos = if modifier_form?(match)
201
+ match.parent.if_branch.loc.expression.begin_pos
202
+ else
203
+ match.loc.expression.begin_pos
204
+ end
205
+
206
+ begin_pos > match_node_pos && scope_root(match) == scope_root
195
207
  end
208
+
196
209
  node ? node.loc.expression.begin_pos : Float::INFINITY
197
210
  end
198
211
 
212
+ def modifier_form?(match_node)
213
+ match_node.parent.if_type? && match_node.parent.modifier_form?
214
+ end
215
+
199
216
  def find_last_match(body, range, scope_root)
200
217
  last_matches(body).find do |ref|
201
218
  ref_pos = ref.loc.expression.begin_pos
@@ -1,13 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module RuboCop
4
- # RuboCop included the performance cops directly before version 1.0.0.
5
- # We can remove them to avoid warnings about redefining constants.
6
- module Cop
7
- remove_const('Performance') if const_defined?('Performance')
8
- end
9
- end
10
-
11
3
  require_relative 'performance/caller'
12
4
  require_relative 'performance/case_when_splat'
13
5
  require_relative 'performance/casecmp'
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Performance
5
5
  module Version
6
- STRING = '1.4.0'
6
+ STRING = '1.4.1'
7
7
  end
8
8
  end
9
9
  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.4.0
4
+ version: 1.4.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: 2019-06-20 00:00:00.000000000 Z
13
+ date: 2019-07-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop