rubocop-performance 1.13.3 → 1.14.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +2 -2
  3. data/lib/rubocop/cop/mixin/regexp_metacharacter.rb +2 -2
  4. data/lib/rubocop/cop/performance/ancestors_include.rb +1 -2
  5. data/lib/rubocop/cop/performance/array_semi_infinite_range_slice.rb +1 -1
  6. data/lib/rubocop/cop/performance/big_decimal_with_numeric_argument.rb +1 -1
  7. data/lib/rubocop/cop/performance/block_given_with_explicit_block.rb +1 -1
  8. data/lib/rubocop/cop/performance/caller.rb +1 -2
  9. data/lib/rubocop/cop/performance/case_when_splat.rb +2 -2
  10. data/lib/rubocop/cop/performance/casecmp.rb +10 -12
  11. data/lib/rubocop/cop/performance/chain_array_allocation.rb +4 -4
  12. data/lib/rubocop/cop/performance/collection_literal_in_loop.rb +3 -3
  13. data/lib/rubocop/cop/performance/compare_with_block.rb +1 -1
  14. data/lib/rubocop/cop/performance/concurrent_monotonic_time.rb +1 -1
  15. data/lib/rubocop/cop/performance/constant_regexp.rb +1 -1
  16. data/lib/rubocop/cop/performance/count.rb +1 -1
  17. data/lib/rubocop/cop/performance/delete_prefix.rb +3 -0
  18. data/lib/rubocop/cop/performance/delete_suffix.rb +3 -0
  19. data/lib/rubocop/cop/performance/detect.rb +1 -1
  20. data/lib/rubocop/cop/performance/double_start_end_with.rb +1 -1
  21. data/lib/rubocop/cop/performance/end_with.rb +1 -1
  22. data/lib/rubocop/cop/performance/flat_map.rb +1 -1
  23. data/lib/rubocop/cop/performance/inefficient_hash_search.rb +3 -5
  24. data/lib/rubocop/cop/performance/io_readlines.rb +1 -1
  25. data/lib/rubocop/cop/performance/map_compact.rb +1 -1
  26. data/lib/rubocop/cop/performance/method_object_as_block.rb +1 -1
  27. data/lib/rubocop/cop/performance/open_struct.rb +1 -1
  28. data/lib/rubocop/cop/performance/range_include.rb +2 -2
  29. data/lib/rubocop/cop/performance/redundant_block_call.rb +1 -1
  30. data/lib/rubocop/cop/performance/redundant_equality_comparison_block.rb +4 -1
  31. data/lib/rubocop/cop/performance/redundant_match.rb +1 -1
  32. data/lib/rubocop/cop/performance/redundant_merge.rb +1 -2
  33. data/lib/rubocop/cop/performance/redundant_sort_block.rb +1 -2
  34. data/lib/rubocop/cop/performance/redundant_split_regexp_argument.rb +1 -1
  35. data/lib/rubocop/cop/performance/redundant_string_chars.rb +1 -1
  36. data/lib/rubocop/cop/performance/regexp_match.rb +3 -0
  37. data/lib/rubocop/cop/performance/reverse_each.rb +1 -2
  38. data/lib/rubocop/cop/performance/reverse_first.rb +1 -1
  39. data/lib/rubocop/cop/performance/size.rb +1 -2
  40. data/lib/rubocop/cop/performance/sort_reverse.rb +1 -1
  41. data/lib/rubocop/cop/performance/squeeze.rb +1 -1
  42. data/lib/rubocop/cop/performance/start_with.rb +1 -1
  43. data/lib/rubocop/cop/performance/string_identifier_argument.rb +3 -3
  44. data/lib/rubocop/cop/performance/string_include.rb +2 -3
  45. data/lib/rubocop/cop/performance/string_replacement.rb +1 -2
  46. data/lib/rubocop/cop/performance/sum.rb +3 -3
  47. data/lib/rubocop/cop/performance/times_map.rb +1 -1
  48. data/lib/rubocop/cop/performance/uri_default_parser.rb +1 -2
  49. data/lib/rubocop/performance/version.rb +1 -1
  50. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc8de809f0aa167f08fd75ed2f7047fabc37b06b12a0c59e4647530b18fb6d99
4
- data.tar.gz: df849a7c117eb44d8851969031cda6d5927e2f271ad41bc3689212bad6b9e2e1
3
+ metadata.gz: 7716dc36d8facd9d8604d89d117f85db5fed60efcad66ad8354d673492800140
4
+ data.tar.gz: 59f4dd4e4df5afef36700a8951e8e91e18567ba978506d9aa02884abafc6d639
5
5
  SHA512:
6
- metadata.gz: 24c72e01dfa6cfe35b3c93e1c83d63aaa0362dff7bc4ed234b8b6f8c1a434927a945b077273ec84c95be86d70e050f28e18dad27ffc9c72350f49c7ff3477b4a
7
- data.tar.gz: 3340644f87ea108d8f7022756ff5cdf442b0d2951cd9ea351bb0a4012c2d0721dc921b1402e8b5f952899015b51c402cdbcab5e785d764f4655aa068c71be6b3
6
+ metadata.gz: 748977ac053ddab36afda43c709eee6424957a81ce18daf1048cf42399226e0d2d67f9964ba544594a03862d5650eff369a34b407d49892d72957ab3acf2ca11
7
+ data.tar.gz: 9a785cd79f0e781643720fd19e2454d6b1cac890c215d5a44762e4173d69e9f6ec6adc57fe43646dba7b3e48bf86663842f595f54db1f51c7e251af75113ecee
data/config/default.yml CHANGED
@@ -160,7 +160,7 @@ Performance/FlatMap:
160
160
  Description: >-
161
161
  Use `Enumerable#flat_map`
162
162
  instead of `Enumerable#map...Array#flatten(1)`
163
- or `Enumberable#collect..Array#flatten(1)`.
163
+ or `Enumerable#collect..Array#flatten(1)`.
164
164
  Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablemaparrayflatten-vs-enumerableflat_map-code'
165
165
  Enabled: true
166
166
  VersionAdded: '0.30'
@@ -247,7 +247,7 @@ Performance/RedundantSortBlock:
247
247
  VersionAdded: '1.7'
248
248
 
249
249
  Performance/RedundantSplitRegexpArgument:
250
- Description: 'This cop identifies places where `split` argument can be replaced from a deterministic regexp to a string.'
250
+ Description: 'Identifies places where `split` argument can be replaced from a deterministic regexp to a string.'
251
251
  Enabled: pending
252
252
  VersionAdded: '1.10'
253
253
 
@@ -54,9 +54,9 @@ module RuboCop
54
54
 
55
55
  def drop_start_metacharacter(regexp_string)
56
56
  if regexp_string.start_with?('\\A')
57
- regexp_string[2..-1] # drop `\A` anchor
57
+ regexp_string[2..] # drop `\A` anchor
58
58
  else
59
- regexp_string[1..-1] # drop `^` anchor
59
+ regexp_string[1..] # drop `^` anchor
60
60
  end
61
61
  end
62
62
 
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `ancestors.include?` and
7
- # change them to use `<=` instead.
6
+ # Identifies usages of `ancestors.include?` and change them to use `<=` instead.
8
7
  #
9
8
  # @safety
10
9
  # This cop is unsafe because it can't tell whether the receiver is a class or an object.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where slicing arrays with semi-infinite ranges
6
+ # Identifies places where slicing arrays with semi-infinite ranges
7
7
  # can be replaced by `Array#take` and `Array#drop`.
8
8
  # This cop was created due to a mistake in microbenchmark and hence is disabled by default.
9
9
  # Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where numeric argument to BigDecimal should be
6
+ # Identifies places where numeric argument to BigDecimal should be
7
7
  # converted to string. Initializing from String is faster
8
8
  # than from Numeric for BigDecimal.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies unnecessary use of a `block_given?` where explicit check
6
+ # Identifies unnecessary use of a `block_given?` where explicit check
7
7
  # of block argument would suffice.
8
8
  #
9
9
  # @example
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `caller[n]`
7
- # can be replaced by `caller(n..n).first`.
6
+ # Identifies places where `caller[n]` can be replaced by `caller(n..n).first`.
8
7
  #
9
8
  # @example
10
9
  # # bad
@@ -18,7 +18,7 @@ module RuboCop
18
18
  # that is inside of the splat expansion.
19
19
  #
20
20
  # @safety
21
- # This cop is not unsafe auto-correction because it is not a guaranteed
21
+ # This cop is not unsafe autocorrection because it is not a guaranteed
22
22
  # performance improvement. If the data being processed by the `case` condition is
23
23
  # normalized in a manner that favors hitting a condition in the splat expansion,
24
24
  # it is possible that moving the splat condition to the end will use more memory,
@@ -168,7 +168,7 @@ module RuboCop
168
168
 
169
169
  def needs_reorder?(when_node)
170
170
  following_branches =
171
- when_node.parent.when_branches[(when_node.branch_index + 1)..-1]
171
+ when_node.parent.when_branches[(when_node.branch_index + 1)..]
172
172
 
173
173
  following_branches.any? do |when_branch|
174
174
  when_branch.conditions.any? do |condition|
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where a case-insensitive string comparison
6
+ # Identifies places where a case-insensitive string comparison
7
7
  # can better be implemented using `casecmp`.
8
8
  #
9
9
  # @safety
@@ -54,11 +54,11 @@ module RuboCop
54
54
  return unless (parts = take_method_apart(node))
55
55
 
56
56
  _receiver, method, arg, variable = parts
57
- good_method = build_good_method(arg, variable)
57
+ good_method = build_good_method(method, arg, variable)
58
58
 
59
59
  message = format(MSG, good: good_method, bad: node.source)
60
60
  add_offense(node, message: message) do |corrector|
61
- correction(corrector, node, method, arg, variable)
61
+ autocorrect(corrector, node, good_method)
62
62
  end
63
63
  end
64
64
 
@@ -81,22 +81,20 @@ module RuboCop
81
81
  [receiver, method, arg, variable]
82
82
  end
83
83
 
84
- def correction(corrector, node, method, arg, variable)
85
- corrector.insert_before(node.loc.expression, '!') if method == :!=
86
-
87
- replacement = build_good_method(arg, variable)
88
-
89
- corrector.replace(node.loc.expression, replacement)
84
+ def autocorrect(corrector, node, replacement)
85
+ corrector.replace(node, replacement)
90
86
  end
91
87
 
92
- def build_good_method(arg, variable)
88
+ def build_good_method(method, arg, variable)
89
+ bang = method == :!= ? '!' : ''
90
+
93
91
  # We want resulting call to be parenthesized
94
92
  # if arg already includes one or more sets of parens, don't add more
95
93
  # or if method call already used parens, again, don't add more
96
94
  if arg.send_type? || !parentheses?(arg)
97
- "#{variable.source}.casecmp(#{arg.source}).zero?"
95
+ "#{bang}#{variable.source}.casecmp(#{arg.source}).zero?"
98
96
  else
99
- "#{variable.source}.casecmp#{arg.source}.zero?"
97
+ "#{bang}#{variable.source}.casecmp#{arg.source}.zero?"
100
98
  end
101
99
  end
102
100
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `array.compact.flatten.map { |x| x.downcase }`.
6
+ # Identifies usages of `array.compact.flatten.map { |x| x.downcase }`.
7
7
  # Each of these methods (`compact`, `flatten`, `map`) will generate a new intermediate array
8
8
  # that is promptly thrown away. Instead it is faster to mutate when we know it's safe.
9
9
  #
@@ -47,13 +47,13 @@ module RuboCop
47
47
 
48
48
  RETURNS_NEW_ARRAY = (ALWAYS_RETURNS_NEW_ARRAY + RETURNS_NEW_ARRAY_WHEN_NO_BLOCK).freeze
49
49
 
50
- MSG = 'Use unchained `%<method>s` and `%<second_method>s!` '\
51
- '(followed by `return array` if required) instead of chaining '\
50
+ MSG = 'Use unchained `%<method>s` and `%<second_method>s!` ' \
51
+ '(followed by `return array` if required) instead of chaining ' \
52
52
  '`%<method>s...%<second_method>s`.'
53
53
 
54
54
  def_node_matcher :chain_array_allocation?, <<~PATTERN
55
55
  (send {
56
- (send _ $%RETURN_NEW_ARRAY_WHEN_ARGS {int lvar ivar cvar gvar})
56
+ (send _ $%RETURN_NEW_ARRAY_WHEN_ARGS {int lvar ivar cvar gvar send})
57
57
  (block (send _ $%ALWAYS_RETURNS_NEW_ARRAY) ...)
58
58
  (send _ $%RETURNS_NEW_ARRAY ...)
59
59
  } $%HAS_MUTATION_ALTERNATIVE ...)
@@ -5,8 +5,8 @@ require 'set'
5
5
  module RuboCop
6
6
  module Cop
7
7
  module Performance
8
- # This cop identifies places where Array and Hash literals are used
9
- # within loops. It is better to extract them into a local variable or constant
8
+ # Identifies places where Array and Hash literals are used within loops.
9
+ # It is better to extract them into a local variable or constant
10
10
  # to avoid unnecessary allocations on each iteration.
11
11
  #
12
12
  # You can set the minimum number of elements to consider
@@ -32,7 +32,7 @@ module RuboCop
32
32
  # end
33
33
  #
34
34
  class CollectionLiteralInLoop < Base
35
- MSG = 'Avoid immutable %<literal_class>s literals in loops. '\
35
+ MSG = 'Avoid immutable %<literal_class>s literals in loops. ' \
36
36
  'It is better to extract it into a local variable or a constant.'
37
37
 
38
38
  POST_CONDITION_LOOP_TYPES = %i[while_post until_post].freeze
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `sort { |a, b| a.foo <=> b.foo }`
6
+ # Identifies places where `sort { |a, b| a.foo <=> b.foo }`
7
7
  # can be replaced by `sort_by(&:foo)`.
8
8
  # This cop also checks `max` and `min` methods.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `Concurrent.monotonic_time`
6
+ # Identifies places where `Concurrent.monotonic_time`
7
7
  # can be replaced by `Process.clock_gettime(Process::CLOCK_MONOTONIC)`.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop finds regular expressions with dynamic components that are all constants.
6
+ # Finds regular expressions with dynamic components that are all constants.
7
7
  #
8
8
  # Ruby allocates a new Regexp object every time it executes a code containing such
9
9
  # a regular expression. It is more efficient to extract it into a constant,
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `count` on an `Enumerable` that
6
+ # Identifies usages of `count` on an `Enumerable` that
7
7
  # follow calls to `select`, `find_all`, `filter` or `reject`. Querying logic can instead be
8
8
  # passed to the `count` call.
9
9
  #
@@ -49,6 +49,9 @@ module RuboCop
49
49
  class DeletePrefix < Base
50
50
  include RegexpMetacharacter
51
51
  extend AutoCorrector
52
+ extend TargetRubyVersion
53
+
54
+ minimum_target_ruby_version 2.5
52
55
 
53
56
  MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
54
57
  RESTRICT_ON_SEND = %i[gsub gsub! sub sub!].freeze
@@ -49,6 +49,9 @@ module RuboCop
49
49
  class DeleteSuffix < Base
50
50
  include RegexpMetacharacter
51
51
  extend AutoCorrector
52
+ extend TargetRubyVersion
53
+
54
+ minimum_target_ruby_version 2.5
52
55
 
53
56
  MSG = 'Use `%<prefer>s` instead of `%<current>s`.'
54
57
  RESTRICT_ON_SEND = %i[gsub gsub! sub sub!].freeze
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `first`, `last`, `[0]` or `[-1]`
6
+ # Identifies usages of `first`, `last`, `[0]` or `[-1]`
7
7
  # chained to `select`, `find_all` or `filter` and change them to use
8
8
  # `detect` instead.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for double `#start_with?` or `#end_with?` calls
6
+ # Checks for double `#start_with?` or `#end_with?` calls
7
7
  # separated by `||`. In some cases such calls can be replaced
8
8
  # with an single `#start_with?`/`#end_with?` call.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies unnecessary use of a regex where `String#end_with?` would suffice.
6
+ # Identifies unnecessary use of a regex where `String#end_with?` would suffice.
7
7
  #
8
8
  # This cop has `SafeMultiline` configuration option that `true` by default because
9
9
  # `end$` is unsafe as it will behave incompatible with `end_with?`
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `map { ... }.flatten` and
6
+ # Identifies usages of `map { ... }.flatten` and
7
7
  # change them to use `flat_map { ... }` instead.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for inefficient searching of keys and values within
6
+ # Checks for inefficient searching of keys and values within
7
7
  # hashes.
8
8
  #
9
9
  # `Hash#keys.include?` is less efficient than `Hash#key?` because
@@ -58,8 +58,7 @@ module RuboCop
58
58
  # `key?`/`value?` method.
59
59
  corrector.replace(
60
60
  node.loc.expression,
61
- "#{autocorrect_hash_expression(node)}."\
62
- "#{autocorrect_method(node)}(#{autocorrect_argument(node)})"
61
+ "#{autocorrect_hash_expression(node)}.#{autocorrect_method(node)}(#{autocorrect_argument(node)})"
63
62
  )
64
63
  end
65
64
  end
@@ -68,8 +67,7 @@ module RuboCop
68
67
  private
69
68
 
70
69
  def message(node)
71
- "Use `##{autocorrect_method(node)}` instead of "\
72
- "`##{current_method(node)}.include?`."
70
+ "Use `##{autocorrect_method(node)}` instead of `##{current_method(node)}.include?`."
73
71
  end
74
72
 
75
73
  def autocorrect_method(node)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where inefficient `readlines` method
6
+ # Identifies places where inefficient `readlines` method
7
7
  # can be replaced by `each_line` to avoid fully loading file content into memory.
8
8
  #
9
9
  # @example
@@ -83,7 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def invoke_method_after_map_compact_on_same_line?(compact_node, chained_method)
86
- compact_node.loc.selector.line == chained_method.loc.selector.line
86
+ compact_node.loc.selector.line == chained_method.loc.last_line
87
87
  end
88
88
 
89
89
  def compact_method_with_final_newline_range(compact_method_range)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where methods are converted to blocks, with the
6
+ # Identifies places where methods are converted to blocks, with the
7
7
  # use of `&method`, and passed as arguments to method calls.
8
8
  # It is faster to replace those with explicit blocks, calling those methods inside.
9
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for `OpenStruct.new` calls.
6
+ # Checks for `OpenStruct.new` calls.
7
7
  # Instantiation of an `OpenStruct` invalidates
8
8
  # Ruby global method cache as it causes dynamic method
9
9
  # definition during program runtime.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies uses of `Range#include?` and `Range#member?`, which iterates over each
6
+ # Identifies uses of `Range#include?` and `Range#member?`, which iterates over each
7
7
  # item in a `Range` to see if a specified item is there. In contrast,
8
8
  # `Range#cover?` simply compares the target item with the beginning and
9
9
  # end points of the `Range`. In a great majority of cases, this is what
@@ -11,7 +11,7 @@ module RuboCop
11
11
  #
12
12
  # @safety
13
13
  # This cop is unsafe because `Range#include?` (or `Range#member?`) and `Range#cover?`
14
- # are not equivalent behaviour.
14
+ # are not equivalent behavior.
15
15
  #
16
16
  # @example
17
17
  # # bad
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies the use of a `&block` parameter and `block.call`
6
+ # Identifies the use of a `&block` parameter and `block.call`
7
7
  # where `yield` would do just as well.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
6
+ # Checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
7
7
  # and `Enumerable#none?` are compared with `===` or similar methods in block.
8
8
  #
9
9
  # By default, `Object#===` behaves the same as `Object#==`, but this
@@ -25,6 +25,9 @@ module RuboCop
25
25
  #
26
26
  class RedundantEqualityComparisonBlock < Base
27
27
  extend AutoCorrector
28
+ extend TargetRubyVersion
29
+
30
+ minimum_target_ruby_version 2.5
28
31
 
29
32
  MSG = 'Use `%<prefer>s` instead of block.'
30
33
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies the use of `Regexp#match` or `String#match`, which
6
+ # Identifies the use of `Regexp#match` or `String#match`, which
7
7
  # returns `#<MatchData>`/`nil`. The return value of `=~` is an integral
8
8
  # index/`nil` and is more performant.
9
9
  #
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `Hash#merge!` can be replaced by
7
- # `Hash#[]=`.
6
+ # Identifies places where `Hash#merge!` can be replaced by `Hash#[]=`.
8
7
  # You can set the maximum number of key-value pairs to consider
9
8
  # an offense with `MaxKeyValuePairs`.
10
9
  #
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `sort { |a, b| a <=> b }`
7
- # can be replaced with `sort`.
6
+ # Identifies places where `sort { |a, b| a <=> b }` can be replaced with `sort`.
8
7
  #
9
8
  # @example
10
9
  # # bad
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `split` argument can be replaced from
6
+ # Identifies places where `split` argument can be replaced from
7
7
  # a deterministic regexp to a string.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for redundant `String#chars`.
6
+ # Checks for redundant `String#chars`.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -74,6 +74,9 @@ module RuboCop
74
74
  # end
75
75
  class RegexpMatch < Base
76
76
  extend AutoCorrector
77
+ extend TargetRubyVersion
78
+
79
+ minimum_target_ruby_version 2.4
77
80
 
78
81
  # Constants are included in this list because it is unlikely that
79
82
  # someone will store `nil` as a constant and then use it for comparison
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `reverse.each` and
7
- # change them to use `reverse_each` instead.
6
+ # Identifies usages of `reverse.each` and change them to use `reverse_each` instead.
8
7
  #
9
8
  # If the return value is used, it will not be detected because the result will be different.
10
9
  #
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `reverse.first(n)` and `reverse.first`
6
+ # Identifies places where `reverse.first(n)` and `reverse.first`
7
7
  # can be replaced by `last(n).reverse` and `last`.
8
8
  #
9
9
  # @example
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop is used to identify usages of `count` on an
7
- # `Array` and `Hash` and change them to `size`.
6
+ # Identifies usages of `count` on an `Array` and `Hash` and change them to `size`.
8
7
  #
9
8
  # @example
10
9
  # # bad
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `sort { |a, b| b <=> a }`
6
+ # Identifies places where `sort { |a, b| b <=> a }`
7
7
  # can be replaced by a faster `sort.reverse`.
8
8
  #
9
9
  # @example
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `gsub(/a+/, 'a')` and `gsub!(/a+/, 'a')`
6
+ # Identifies places where `gsub(/a+/, 'a')` and `gsub!(/a+/, 'a')`
7
7
  # can be replaced by `squeeze('a')` and `squeeze!('a')`.
8
8
  #
9
9
  # The `squeeze('a')` method is faster than `gsub(/a+/, 'a')`.
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies unnecessary use of a regex where `String#start_with?` would suffice.
6
+ # Identifies unnecessary use of a regex where `String#start_with?` would suffice.
7
7
  #
8
8
  # This cop has `SafeMultiline` configuration option that `true` by default because
9
9
  # `^start` is unsafe as it will behave incompatible with `start_with?`
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where string identifier argument can be replaced
6
+ # Identifies places where string identifier argument can be replaced
7
7
  # by symbol identifier argument.
8
8
  # It prevents the redundancy of the internal string-to-symbol conversion.
9
9
  #
@@ -38,7 +38,7 @@ module RuboCop
38
38
  remove_class_variable remove_method undef_method class_variable_get class_variable_set
39
39
  deprecate_constant module_function private private_constant protected public public_constant
40
40
  remove_const ruby2_keywords
41
- define_singleton_method instance_variable_defined instance_variable_get instance_variable_set
41
+ define_singleton_method instance_variable_defined? instance_variable_get instance_variable_set
42
42
  method public_method public_send remove_instance_variable respond_to? send singleton_method
43
43
  __send__
44
44
  ].freeze
@@ -46,7 +46,7 @@ module RuboCop
46
46
  def on_send(node)
47
47
  return unless (first_argument = node.first_argument)
48
48
  return unless first_argument.str_type?
49
- return if first_argument.value.include?(' ')
49
+ return if first_argument.value.include?(' ') || first_argument.value.include?('::')
50
50
 
51
51
  replacement = first_argument.value.to_sym.inspect
52
52
 
@@ -3,11 +3,10 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies unnecessary use of a regex where
7
- # `String#include?` would suffice.
6
+ # Identifies unnecessary use of a regex where `String#include?` would suffice.
8
7
  #
9
8
  # @safety
10
- # This cop's offenses are not safe to auto-correct if a receiver is nil.
9
+ # This cop's offenses are not safe to autocorrect if a receiver is nil.
11
10
  #
12
11
  # @example
13
12
  # # bad
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `gsub` can be replaced by
7
- # `tr` or `delete`.
6
+ # Identifies places where `gsub` can be replaced by `tr` or `delete`.
8
7
  #
9
8
  # @example
10
9
  # # bad
@@ -3,11 +3,11 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where custom code finding the sum of elements
6
+ # Identifies places where custom code finding the sum of elements
7
7
  # in some Enumerable object can be replaced by `Enumerable#sum` method.
8
8
  #
9
9
  # @safety
10
- # Auto-corrections are unproblematic wherever an initial value is provided explicitly:
10
+ # Autocorrections are unproblematic wherever an initial value is provided explicitly:
11
11
  #
12
12
  # [source,ruby]
13
13
  # ----
@@ -43,7 +43,7 @@ module RuboCop
43
43
  #
44
44
  # @example OnlySumOrWithInitialValue: false (default)
45
45
  # # bad
46
- # [1, 2, 3].inject(:+) # Auto-corrections for cases without initial value are unsafe
46
+ # [1, 2, 3].inject(:+) # Autocorrections for cases without initial value are unsafe
47
47
  # [1, 2, 3].inject(&:+) # and will only be performed when using the `-A` option.
48
48
  # [1, 2, 3].reduce { |acc, elem| acc + elem } # They can be prohibited completely using `SafeAutoCorrect: true`.
49
49
  # [1, 2, 3].reduce(10, :+)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop checks for .times.map calls.
6
+ # Checks for .times.map calls.
7
7
  # In most cases such calls can be replaced
8
8
  # with an explicit array creation.
9
9
  #
@@ -3,8 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Performance
6
- # This cop identifies places where `URI::Parser.new`
7
- # can be replaced by `URI::DEFAULT_PARSER`.
6
+ # Identifies places where `URI::Parser.new` can be replaced by `URI::DEFAULT_PARSER`.
8
7
  #
9
8
  # @example
10
9
  # # bad
@@ -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.3'
7
+ STRING = '1.14.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.3
4
+ version: 1.14.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-03-05 00:00:00.000000000 Z
13
+ date: 2022-07-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -123,7 +123,7 @@ metadata:
123
123
  homepage_uri: https://docs.rubocop.org/rubocop-performance/
124
124
  changelog_uri: https://github.com/rubocop/rubocop-performance/blob/master/CHANGELOG.md
125
125
  source_code_uri: https://github.com/rubocop/rubocop-performance/
126
- documentation_uri: https://docs.rubocop.org/rubocop-performance/1.13/
126
+ documentation_uri: https://docs.rubocop.org/rubocop-performance/1.14/
127
127
  bug_tracker_uri: https://github.com/rubocop/rubocop-performance/issues
128
128
  rubygems_mfa_required: 'true'
129
129
  post_install_message:
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 2.5.0
137
+ version: 2.6.0
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="