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: ee80f72f854adad1ef3a54295f5b732578373d11d19eae5b7ea0386bd2fa0f25
4
- data.tar.gz: da36ad6040d986c56430965521ee1e597d3bc0919fa9c77ec1e34e5ca2cf43d6
3
+ metadata.gz: cc8de809f0aa167f08fd75ed2f7047fabc37b06b12a0c59e4647530b18fb6d99
4
+ data.tar.gz: df849a7c117eb44d8851969031cda6d5927e2f271ad41bc3689212bad6b9e2e1
5
5
  SHA512:
6
- metadata.gz: 255bba802b4023ec8be39476cc06c7614a4f7cbce11260a608f4c5c479f6e3d9b41ad6a286f8d42cb805ae65995d3bb29f46a746080dde0fa121f3a269cfaeb9
7
- data.tar.gz: 24bffb35ce7441354bb42920d3ec49a07fa005edd4847bdd81066d22beda71dbb186e5e82205c6ad181372be1963e431751466560345068d995400f237297fb8
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
- # Each of these methods (`compact`, `flatten`, `map`) will generate a
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
 
@@ -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.13.2'
7
+ STRING = '1.13.3'
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.13.2
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-01-16 00:00:00.000000000 Z
13
+ date: 2022-03-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop